Handle email taken during registration

This commit is contained in:
Peter Vacho 2025-01-03 17:12:10 +01:00
parent d36db8c04f
commit 3351499e73
Signed by: school
GPG key ID: 8CFC3837052871B4

View file

@ -99,6 +99,10 @@ async def register(reg_data: Annotated[RegisterData, Body()]) -> UserData:
if user is not None:
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Username already taken")
user = await User.find_one(User.email == reg_data.email)
if user is not None:
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Email already taken")
user = await reg_data.create_user()
return UserData.from_user(user)