diff --git a/account/views.py b/account/views.py index aed08ab..85d79ec 100644 --- a/account/views.py +++ b/account/views.py @@ -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): @@ -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) \ No newline at end of file + response = Response(status=status.HTTP_204_NO_CONTENT, headers=headers) + + return response diff --git a/chatgpt_ui_server/settings.py b/chatgpt_ui_server/settings.py index c1030fb..4d0d758 100644 --- a/chatgpt_ui_server/settings.py +++ b/chatgpt_ui_server/settings.py @@ -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')