Update: Session JWT added (not working now)
This commit is contained in:
parent
1771c63b36
commit
6dee0956dd
5 changed files with 60 additions and 41 deletions
|
|
@ -1,7 +1,3 @@
|
|||
from datetime import datetime, timedelta
|
||||
from flask import current_app as app
|
||||
import jwt
|
||||
|
||||
from . import db
|
||||
|
||||
|
||||
|
|
@ -35,32 +31,3 @@ class Users(db.Model):
|
|||
'email': self.email,
|
||||
'is_admin': self.is_admin
|
||||
}
|
||||
|
||||
def auth_token(self):
|
||||
try:
|
||||
time = datetime.now()
|
||||
payload = {
|
||||
'exp': time + timedelta(days=0, seconds=5),
|
||||
'iat': time,
|
||||
'user': self.json()
|
||||
}
|
||||
return jwt.encode(
|
||||
payload,
|
||||
app.config.get('SECRET_KEY'),
|
||||
algorithm='HS256'
|
||||
)
|
||||
except Exception as e:
|
||||
return e
|
||||
|
||||
@staticmethod
|
||||
def decode_auth_token(auth_token):
|
||||
try:
|
||||
payload = jwt.decode(
|
||||
auth_token,
|
||||
app.config.get('SECRET_KEY')
|
||||
)
|
||||
return payload['user']
|
||||
except jwt.ExpiredSignatureError:
|
||||
return 'Signature expired . Please log in again.'
|
||||
except jwt.InvalidTokenError:
|
||||
return 'Invalid token. Please log in again.'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue