Skip to content

Commit

Permalink
Add response field email_verification_required to the registration in…
Browse files Browse the repository at this point in the history
…terface
  • Loading branch information
WongSaang committed Mar 20, 2023
1 parent 3a57e8b commit 9df500d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 21 additions & 3 deletions account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework import status
from dj_rest_auth.registration.views import RegisterView
from chat.models import Setting
from allauth.account import app_settings as allauth_account_settings


class RegistrationView(RegisterView):
Expand All @@ -11,7 +12,24 @@ def create(self, request, *args, **kwargs):
except Setting.DoesNotExist:
open_registration = True

if open_registration:
return super().create(request, *args, **kwargs)
if open_registration is False:
return Response({'detail': 'Registration is not yet open.'}, status=status.HTTP_403_FORBIDDEN)

serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
data = self.get_response_data(user)

data['email_verification_required'] = allauth_account_settings.EMAIL_VERIFICATION

if data:
response = Response(
data,
status=status.HTTP_201_CREATED,
headers=headers,
)
else:
return Response({'detail': 'Registration is not yet open.'}, status=status.HTTP_403_FORBIDDEN)
response = Response(status=status.HTTP_204_NO_CONTENT, headers=headers)

return response
1 change: 1 addition & 0 deletions chatgpt_ui_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@

# Allauth settings
ACCOUNT_ADAPTER = 'account.allauth.AccountAdapter'
ACCOUNT_EMAIL_VERIFICATION = os.getenv('ACCOUNT_EMAIL_VERIFICATION', 'optional')

# Email settings
EMAIL_BACKEND = os.getenv('EMAIL_BACKEND', 'django.core.mail.backends.smtp.EmailBackend')
Expand Down

0 comments on commit 9df500d

Please sign in to comment.