mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-25 06:24:19 +00:00
🔧 Increase token expiration date to 30 days, and send it in the login response
This commit is contained in:
parent
2b488d9028
commit
a481a4e087
1 changed files with 8 additions and 2 deletions
|
@ -3,6 +3,7 @@ from ...database import *
|
||||||
from ...gestione import *
|
from ...gestione import *
|
||||||
from flask_jwt_extended import create_access_token
|
from flask_jwt_extended import create_access_token
|
||||||
from flask_cors import cross_origin
|
from flask_cors import cross_origin
|
||||||
|
from datetime import timedelta, datetime
|
||||||
|
|
||||||
|
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
|
@ -18,7 +19,12 @@ def page_login():
|
||||||
email = request.json.get("email", None)
|
email = request.json.get("email", None)
|
||||||
password = request.json.get("password", None)
|
password = request.json.get("password", None)
|
||||||
if authenticate(email, password):
|
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)
|
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
|
return json_error("Bad username or password."), 401
|
||||||
|
|
Loading…
Reference in a new issue