Update app.py
Browse files
app.py
CHANGED
|
@@ -1857,32 +1857,36 @@ def show_registrations_period():
|
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
-
|
| 1861 |
-
|
| 1862 |
-
|
| 1863 |
-
|
| 1864 |
email = request.args.get('email')
|
| 1865 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1866 |
if not email:
|
| 1867 |
return jsonify({"error": "Email parameter is required"}), 400
|
| 1868 |
-
|
| 1869 |
# Подключаемся к базе данных
|
| 1870 |
conn = sqlite3.connect('data_gc.db')
|
| 1871 |
cursor = conn.cursor()
|
| 1872 |
-
|
| 1873 |
# Проверяем, существует ли запись с таким email
|
| 1874 |
cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
|
| 1875 |
user = cursor.fetchone()
|
| 1876 |
-
|
| 1877 |
if not user:
|
| 1878 |
conn.close()
|
| 1879 |
return jsonify({"error": "User with this email not found"}), 404
|
| 1880 |
-
|
| 1881 |
# Удаляем запись из базы данных
|
| 1882 |
cursor.execute("DELETE FROM contacts WHERE email = ?", (email,))
|
| 1883 |
conn.commit()
|
| 1884 |
conn.close()
|
| 1885 |
-
|
| 1886 |
return jsonify({"status": "success", "message": f"User with email {email} has been deleted"}), 200
|
| 1887 |
|
| 1888 |
|
|
|
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
+
@app.route('/delete_user', methods=['GET'])
|
| 1861 |
+
def delete_user():
|
| 1862 |
+
# Получаем параметры из запроса
|
| 1863 |
+
api_sys = request.args.get('api_sys')
|
| 1864 |
email = request.args.get('email')
|
| 1865 |
+
|
| 1866 |
+
# Проверка API-ключа
|
| 1867 |
+
if api_sys != os.getenv('api_key_sys'):
|
| 1868 |
+
return jsonify({"error": "Unauthorized access"}), 403
|
| 1869 |
+
|
| 1870 |
if not email:
|
| 1871 |
return jsonify({"error": "Email parameter is required"}), 400
|
| 1872 |
+
|
| 1873 |
# Подключаемся к базе данных
|
| 1874 |
conn = sqlite3.connect('data_gc.db')
|
| 1875 |
cursor = conn.cursor()
|
| 1876 |
+
|
| 1877 |
# Проверяем, существует ли запись с таким email
|
| 1878 |
cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
|
| 1879 |
user = cursor.fetchone()
|
| 1880 |
+
|
| 1881 |
if not user:
|
| 1882 |
conn.close()
|
| 1883 |
return jsonify({"error": "User with this email not found"}), 404
|
| 1884 |
+
|
| 1885 |
# Удаляем запись из базы данных
|
| 1886 |
cursor.execute("DELETE FROM contacts WHERE email = ?", (email,))
|
| 1887 |
conn.commit()
|
| 1888 |
conn.close()
|
| 1889 |
+
|
| 1890 |
return jsonify({"status": "success", "message": f"User with email {email} has been deleted"}), 200
|
| 1891 |
|
| 1892 |
|