async def login(user_login: UserInLogin = Body( ..., embed=True, alias="user")) -> UserInResponse: user = await User.get_or_none(email=user_login.email) if not user.check_password(user_login.password): raise HTTP_400_BAD_REQUEST_Exception(strings.INCORRECT_LOGIN_INPUT) return UserInResponse.from_user(user)
async def register(user_create: UserInCreate = Body( ..., embed=True, alias="user")) -> UserInResponse: if await User.exists(username=user_create.username): raise HTTP_400_BAD_REQUEST_Exception(strings.USERNAME_TAKEN) if await User.exists(email=user_create.email): raise HTTP_400_BAD_REQUEST_Exception(strings.EMAIL_TAKEN) user = await create_user_and_set_password(user_create) await Profile.create(user=user, username=user.username) return UserInResponse.from_user(user)
async def update_current_user( user_update: UserInUpdate = Body(..., embed=True, alias="user"), current_user: User = Depends(get_current_user_authorizer()), ) -> UserInResponse: if user_update.username and user_update.username != current_user.username: if await check_username_is_taken(user_update.username): raise HTTP_400_BAD_REQUEST_Exception(strings.USERNAME_TAKEN) if user_update.email and user_update.email != current_user.email: if await check_email_is_taken(user_update.email): raise HTTP_400_BAD_REQUEST_Exception(strings.EMAIL_TAKEN) user = update_user(current_user, user_update) return UserInResponse.from_user(user)
async def retrieve_current_user(user: UserBase = Depends( get_current_user_authorizer())) -> UserInResponse: return UserInResponse.from_user(user)