generateur_v3/backend/api/dbo/auth/crud.py
2022-09-16 21:50:55 +02:00

31 lines
985 B
Python

from services.password import get_password_hash
from database.auth.models import User
async def create_user_db(username, password):
#id_code = generate_unique_code(UserModel)
return await User.create(username=username, hashed_password=password)
async def get_user_from_username_db(username):
return await User.get_or_none(username=username)
async def get_user_from_clientId_db(clientId):
return await User.get_or_none(clientId=clientId)
async def update_user_db(username: str, **kwargs):
user = await get_user_from_username_db(username)
await user.update_from_dict({**kwargs}).save()
return user
async def delete_user_db(username: str):
user = await get_user_from_username_db(username)
await user.delete()
async def update_password_db(username: str, password: str):
user = await get_user_from_username_db(username)
await user.update_from_dict({'hashed_password': get_password_hash(password)}).save(update_fields=["hashed_password"])
return user