From 5d3d9f57a49295b1a4f4890b34e3e2fc4c774657 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sun, 8 Dec 2024 21:06:14 -0500 Subject: [PATCH] verify sign up --- services/web/project/__init__.py | 40 +++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/services/web/project/__init__.py b/services/web/project/__init__.py index 03a6bad..b5ff4ef 100644 --- a/services/web/project/__init__.py +++ b/services/web/project/__init__.py @@ -87,17 +87,39 @@ def start_login(): data["username"], data["password"] ) + if member: + try: + # token should expire after 24 hrs + user["token"] = jwt.encode( + {"member": member, 'exp' : datetime.datetime.utcnow() + datetime.timedelta(minutes=30)}, + app.config["SECRET_KEY"], + algorithm="HS256" + ) + return { + "message": "Successfully fetched auth token", + "data": user + } + except Exception as e: + return { + "error": "Something went wrong", + "message": str(e) + }, 500 + return { + "message": "Error fetching auth token!, invalid email or password", + "data": None, + "error": "Unauthorized" + }, 404 - GLOBAL_AVG = """SELECT * FROM members WHERE id = 1;""" - with connection: - with connection.cursor() as cursor: - cursor.execute(GLOBAL_AVG) - account = cursor.fetchone() - #return jsonify(hello="ameye world") - token = jwt.encode({'user': 'account', 'exp' : datetime.datetime.utcnow() + datetime.timedelta(minutes=30)},app.config['SECRET_KEY'] ) - # return {"account": account} - return {"token": token} +# GLOBAL_AVG = """SELECT * FROM members WHERE id = 1;""" +# with connection: +# with connection.cursor() as cursor: +# cursor.execute(GLOBAL_AVG) +# account = cursor.fetchone() +# #return jsonify(hello="ameye world") +# token = jwt.encode({'user': 'account', 'exp' : datetime.datetime.utcnow() + datetime.timedelta(minutes=30)},app.config['SECRET_KEY'] ) +# # return {"account": account} +# return {"token": token} except Exception as e: return {