Add authorization

This commit is contained in:
2024-05-14 20:55:35 +04:00
parent 0565efdd15
commit 090897a11f
15 changed files with 255 additions and 24 deletions

26
database/crud/users.py Normal file
View File

@@ -0,0 +1,26 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from .. import models as mdl
from .. import schemas as sch
from ..database import add_transaction
async def get_user(db: AsyncSession, username: str):
return (await db.execute(select(mdl.User).where(mdl.User.name == username))).scalar()
async def add_user(db: AsyncSession,
user_data: sch.UserCreate, hash_of_password: str):
user_data_db = \
{k: v for k, v in user_data.model_dump().items()
if k != "password"}
user = mdl.User(**user_data_db,
hash_of_password=hash_of_password)
return await add_transaction(db, user)
async def check_email(db: AsyncSession, email: str):
users = (await db.execute(select(mdl.User)
.where(mdl.User.email == email))).scalars().all()
return True if len(users) == 0 else False