register user, sign in and sign out working

This commit is contained in:
knst-kotov
2021-06-29 13:26:46 +03:00
parent 2dac73b412
commit c9b3d3a833
14 changed files with 81 additions and 30 deletions

View File

@@ -56,9 +56,8 @@ class JWTAuthenticate(AuthenticationBackend):
if JWT_AUTH_HEADER not in request.headers:
return AuthCredentials(scopes=[]), AuthUser(user_id=None)
auth = request.headers[JWT_AUTH_HEADER]
token = request.headers[JWT_AUTH_HEADER]
try:
scheme, token = auth.split()
payload = await _Authenticate.verify(token)
except Exception as exc:
return AuthCredentials(scopes=[], error_message=str(exc)), AuthUser(user_id=None)

View File

@@ -3,7 +3,7 @@ from datetime import datetime, timedelta
from auth.token import Token
from redis import redis
from settings import JWT_LIFE_SPAN
from validations import User
from auth.validations import User
class Authorize:
@@ -30,7 +30,7 @@ class Authorize:
except: # noqa
pass
else:
await redis.execute("DEL", f"{payload.id}-{token}")
await redis.execute("DEL", f"{payload.user_id}-{token}")
return True
@staticmethod

View File

@@ -2,7 +2,7 @@ from auth.password import Password
from exceptions import InvalidPassword, ObjectNotExist
from orm import User as OrmUser
from orm.base import global_session
from validations import User
from auth.validations import User
class Identity:

View File

@@ -3,7 +3,7 @@ from datetime import datetime
import jwt
from settings import JWT_ALGORITHM, JWT_SECRET_KEY
from validations import PayLoad, User
from auth.validations import PayLoad, User
class Token:

View File

@@ -20,9 +20,10 @@ class PayLoad(BaseModel):
class CreateUser(BaseModel):
email: Text
username: Text
# age: Optional[int]
# phone: Optional[Text]
password: Optional[Text]
# TODO: update validations
# TODO: update validations