fixing auth for token
This commit is contained in:
parent
b3d77ba212
commit
e1f8f89a9b
|
@ -3,12 +3,17 @@ from teal.auth import TokenAuth
|
||||||
from teal.db import ResourceNotFound
|
from teal.db import ResourceNotFound
|
||||||
from werkzeug.exceptions import Unauthorized
|
from werkzeug.exceptions import Unauthorized
|
||||||
|
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User, Session
|
||||||
|
|
||||||
|
|
||||||
class Auth(TokenAuth):
|
class Auth(TokenAuth):
|
||||||
def authenticate(self, token: str, *args, **kw) -> User:
|
def authenticate(self, token: str, *args, **kw) -> User:
|
||||||
try:
|
try:
|
||||||
return User.query.filter_by(token=token).one()
|
user = User.query.filter_by(token=token).first()
|
||||||
|
if user:
|
||||||
|
return user
|
||||||
|
|
||||||
|
ses = Session.query.filter_by(token=token).one()
|
||||||
|
return ses.user
|
||||||
except (ResourceNotFound, DataError):
|
except (ResourceNotFound, DataError):
|
||||||
raise Unauthorized('Provide a suitable token.')
|
raise Unauthorized('Provide a suitable token.')
|
||||||
|
|
Reference in New Issue