Initial commit
This commit is contained in:
commit
8b18f2439c
13 changed files with 960 additions and 0 deletions
17
db/users_manip.py
Normal file
17
db/users_manip.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from fastapi import HTTPException
|
||||
from tortoise.exceptions import IntegrityError
|
||||
from db.models.user import User
|
||||
from passlib.context import CryptContext
|
||||
|
||||
from schemas.user_schemas import UserCreateInfo, UserInfo
|
||||
|
||||
pass_context = CryptContext(schemes=["bcrypt"])
|
||||
|
||||
|
||||
async def register_user(user: UserCreateInfo) -> UserInfo:
|
||||
user.password = pass_context.hash(user.password)
|
||||
try:
|
||||
db_user = await User.create(**user.dict(exclude_unset=True))
|
||||
except IntegrityError:
|
||||
raise HTTPException(status_code=401, detail="User already exists")
|
||||
return await UserInfo.from_tortoise_orm(db_user)
|
Loading…
Add table
Add a link
Reference in a new issue