aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-01-15 11:53:01 +0100
committerlonkaars <l.leblansch@gmail.com>2021-01-15 11:53:01 +0100
commitfd4c608f2cf61a3bc655cda49a1e2d0884f2a8fa (patch)
tree65c384c9605fa901422250c7f6a6122e7054049c /api
parentdec3b25e9cf3e2880d3553238cef39bd0c192636 (diff)
private token login
Diffstat (limited to 'api')
-rw-r--r--api/auth/login_token.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/api/auth/login_token.py b/api/auth/login_token.py
index 324e721..1004543 100644
--- a/api/auth/login_token.py
+++ b/api/auth/login_token.py
@@ -2,6 +2,11 @@ from flask import Blueprint, request
from main import cursor
from auth.token import validate_token, hash_token
+def token_login(token):
+ hashed = hash_token({ "token": token, "expirationDate": 0 })
+ user_id = cursor.execute("select user_id from users where valid_tokens like ?", [f"%{hashed['token']}%"]).fetchone()
+ return None if not user_id else user_id
+
token = Blueprint('token', __name__)
@token.route('/token', methods = ['POST'])
@@ -11,9 +16,4 @@ def index():
auth_token = data.get("token") or ""
if not auth_token: return "", 400
- hashed = hash_token({ "token": auth_token, "expirationDate": 0 })
- user_id = cursor.execute("select user_id from users where valid_tokens like ?", [f"%{hashed['token']}%"]).fetchone()
-
- if not user_id: return "", 401
-
- return "", 200 if validate_token(user_id[0], auth_token) else 401
+ return "", 200 if token_login(auth_token) else 401