Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add existing email response (hydroserver2/hydroserver#44) #149

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions accounts/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ def get_user(request: HttpRequest):

@user_router.post(
'/user',
response=UserAuthResponse,
response={
409: str,
200: UserAuthResponse
},
by_alias=True
)
def create_user(_: HttpRequest, data: UserPostBody):

user = user_model.objects.filter(username=data.email, is_verified=True).first()

if user:
return None
return 409, 'Email already linked to an existing account.'

user = user_model.objects.create_user(
email=data.email,
Expand All @@ -62,7 +65,7 @@ def create_user(_: HttpRequest, data: UserPostBody):

user.email = user.unverified_email

return {
return 200, {
'access': str(getattr(jwt, 'access_token', '')),
'refresh': str(jwt),
'user': build_user_response(user)
Expand Down