aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2023-11-06 10:47:56 -0800
committerPinapelz <yukais@pinapelz.com>2023-11-06 10:47:56 -0800
commitd89e202a31557e3cbdebc91b7d5eeff70c902b14 (patch)
tree0acb415632822af73f450e63505b388281b7a203 /api
parent11c326513c46d4550df6957f5f64ae9ce9fe4714 (diff)
added endpoint for clearing sessions table
- To be used with cron job
Diffstat (limited to 'api')
-rw-r--r--api/app.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/api/app.py b/api/app.py
index 7d5728c..be747e7 100644
--- a/api/app.py
+++ b/api/app.py
@@ -4,7 +4,6 @@ import psycopg2
from psycopg2 import Error
import os
import secrets
-import string
app = Flask(__name__)
CORS(app)
@@ -28,6 +27,12 @@ class PostgresHandler:
self._connection.commit()
cursor.close()
+ def clear_table(self, name: str):
+ cursor = self._connection.cursor()
+ cursor.execute(f"DELETE FROM {name}")
+ self._connection.commit()
+ cursor.close()
+
def check_row_exists(self, table_name: str, column_name: str, value: str):
cursor = self._connection.cursor()
query = f"SELECT 1 FROM {table_name} WHERE {column_name} = %s"
@@ -202,7 +207,20 @@ def verify_answers():
return jsonify({"success": True})
else:
return jsonify({"success": False})
-
+
+@app.route("/api/clear_sessions")
+def clear_sessions():
+ auth = request.headers.get("Authorization")
+ stored_auth = os.environ.get("AUTHORIZATION")
+ if auth != stored_auth:
+ return jsonify({"error": "Unauthorized"}), 401
+ server = create_database_connection()
+ if server.check_health() is False:
+ return jsonify({"error": "Cannot connect to verification database"}), 500
+ server.clear_table("sessions")
+ server.close_connection()
+ return jsonify({"success": True})
+
if __name__ == "__main__":
app.run(debug=True)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage