wip: redis, sqlalchemy, structured, etc

This commit is contained in:
2021-06-28 12:08:09 +03:00
parent 133e1cd490
commit 9f01572557
37 changed files with 1297 additions and 62 deletions

17
auth/identity.py Normal file
View File

@@ -0,0 +1,17 @@
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
class Identity:
@staticmethod
def identity(user_id: int, password: str) -> User:
user = global_session.query(OrmUser).filter_by(id=user_id).first()
if not user:
raise ObjectNotExist("User does not exist")
user = User(**user.dict())
if not Password.verify(password, user.password):
raise InvalidPassword("Wrong user password")
return user