DmitrMakeev commited on
Commit
9f15519
·
verified ·
1 Parent(s): 11a7664

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -1
app.py CHANGED
@@ -702,6 +702,18 @@ def add_user_home():
702
  def user():
703
  global current_curator_index
704
 
 
 
 
 
 
 
 
 
 
 
 
 
705
  veref_on_off = request.args.get('ver', '0')
706
  curator_on_off = request.args.get('cur', '0')
707
  db_name = request.args.get('db', 'data_gc.db') # Получаем имя базы данных из запроса
@@ -733,11 +745,12 @@ def user():
733
 
734
  try:
735
  add_or_update_contact(user_data, db_name)
736
- return jsonify({'status': 'success', 'message': f'User added {user_data.get("curator", "not assigned")}'})
737
  except Exception as e:
738
  logging.error(f"Error adding user: {e}")
739
  return jsonify({'status': 'error', 'message': str(e)}), 500
740
 
 
741
  @app.route('/add_user_mess', methods=['GET'])
742
  def add_user_mess():
743
  global current_curator_index
@@ -1849,10 +1862,50 @@ def registrations_period():
1849
  # Маршрут для отображения страницы с графиком за период
1850
  @app.route('/show_registrations_period', methods=['GET'])
1851
  def show_registrations_period():
 
 
 
 
1852
  return render_template('registrations_period.html')
1853
 
1854
 
1855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1856
 
1857
 
1858
 
 
702
  def user():
703
  global current_curator_index
704
 
705
+ # Получаем параметры API-ключа и email из запроса
706
+ api_sys = request.args.get('api_sys')
707
+ email = request.args.get('email')
708
+
709
+ # Проверка API-ключа
710
+ if api_sys != os.getenv('api_key_sys'):
711
+ return jsonify({"error": "Unauthorized access"}), 403
712
+
713
+ # Проверка email
714
+ if not email:
715
+ return jsonify({'error': 'Email is required'}), 400
716
+
717
  veref_on_off = request.args.get('ver', '0')
718
  curator_on_off = request.args.get('cur', '0')
719
  db_name = request.args.get('db', 'data_gc.db') # Получаем имя базы данных из запроса
 
745
 
746
  try:
747
  add_or_update_contact(user_data, db_name)
748
+ return jsonify({'status': 'success', 'message': f'User added {user_data.get("curator", "not assigned")}'}), 200
749
  except Exception as e:
750
  logging.error(f"Error adding user: {e}")
751
  return jsonify({'status': 'error', 'message': str(e)}), 500
752
 
753
+
754
  @app.route('/add_user_mess', methods=['GET'])
755
  def add_user_mess():
756
  global current_curator_index
 
1862
  # Маршрут для отображения страницы с графиком за период
1863
  @app.route('/show_registrations_period', methods=['GET'])
1864
  def show_registrations_period():
1865
+ api_sys_control = request.args.get('api_sys')
1866
+ if api_sys_control != api_key_sys:
1867
+ return "EUR 22", 200
1868
+
1869
  return render_template('registrations_period.html')
1870
 
1871
 
1872
 
1873
+ @app.route('/delete_user', methods=['GET'])
1874
+ def delete_user():
1875
+ # Получаем параметры из запроса
1876
+ api_sys = request.args.get('api_sys')
1877
+ email = request.args.get('email')
1878
+
1879
+ # Проверка API-ключа
1880
+ if api_sys != os.getenv('api_key_sys'):
1881
+ return jsonify({"error": "Unauthorized access"}), 403
1882
+
1883
+ if not email:
1884
+ return jsonify({"error": "Email parameter is required"}), 400
1885
+
1886
+ # Подключаемся к базе данных
1887
+ conn = sqlite3.connect('data_gc.db')
1888
+ cursor = conn.cursor()
1889
+
1890
+ # Проверяем, существует ли запись с таким email
1891
+ cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
1892
+ user = cursor.fetchone()
1893
+
1894
+ if not user:
1895
+ conn.close()
1896
+ return jsonify({"error": "User with this email not found"}), 404
1897
+
1898
+ # Удаляем запись из базы данных
1899
+ cursor.execute("DELETE FROM contacts WHERE email = ?", (email,))
1900
+ conn.commit()
1901
+ conn.close()
1902
+
1903
+ return jsonify({"status": "success", "message": f"User with email {email} has been deleted"}), 200
1904
+
1905
+
1906
+
1907
+
1908
+
1909
 
1910
 
1911