From a481a4e0870bfb5124c744e364f1886e24057325 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi <256895@studenti.unimore.it> Date: Thu, 29 Apr 2021 03:53:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Increase=20token=20expiration=20?= =?UTF-8?q?date=20to=2030=20days,=20and=20send=20it=20in=20the=20login=20r?= =?UTF-8?q?esponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/backend/nest_backend/routes/users/login.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code/backend/nest_backend/routes/users/login.py b/code/backend/nest_backend/routes/users/login.py index d8e6638..e26c227 100644 --- a/code/backend/nest_backend/routes/users/login.py +++ b/code/backend/nest_backend/routes/users/login.py @@ -3,6 +3,7 @@ from ...database import * from ...gestione import * from flask_jwt_extended import create_access_token from flask_cors import cross_origin +from datetime import timedelta, datetime @cross_origin() @@ -18,7 +19,12 @@ def page_login(): email = request.json.get("email", None) password = request.json.get("password", None) if authenticate(email, password): - access_token = create_access_token(identity=email) + # Find today's date + now = datetime.now() + # Add 30 days to it; that's your token expiration date + delta = timedelta(days=30) + expiration = now + delta + access_token = create_access_token(identity=email, expires_delta=delta) user = find_user(email) - return json_success({"access_token": access_token, 'user': user.to_json()}), 201 + return json_success({"access_token": access_token, 'user': user.to_json(), "expiration": expiration}), 201 return json_error("Bad username or password."), 401