-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "open_registration" setting option to control whether registratio…
…n is enabled.
- Loading branch information
Showing
3 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.urls import path, re_path, include | ||
from django.views.generic import TemplateView | ||
from dj_rest_auth.registration.views import VerifyEmailView, ResendEmailVerificationView | ||
from .views import RegistrationView | ||
|
||
urlpatterns = [ | ||
path('', include('dj_rest_auth.urls')), | ||
path('registration/', RegistrationView.as_view(), name='rest_register'), | ||
path('verify-email/', VerifyEmailView.as_view(), name='rest_verify_email'), | ||
path('resend-email/', ResendEmailVerificationView.as_view(), name="rest_resend_email"), | ||
|
||
# This url is used by django-allauth and empty TemplateView is | ||
# defined just to allow reverse() call inside app, for example when email | ||
# with verification link is being sent, then it's required to render email | ||
# content. | ||
|
||
# account_confirm_email - You should override this view to handle it in | ||
# your API client somehow and then, send post to /verify-email/ endpoint | ||
# with proper key. | ||
# If you don't want to use API on that step, then just use ConfirmEmailView | ||
# view from: | ||
# django-allauth https://github.com/pennersr/django-allauth/blob/master/allauth/account/views.py | ||
re_path( | ||
r'^account-confirm-email/(?P<key>[-:\w]+)/$', TemplateView.as_view(), | ||
name='account_confirm_email', | ||
), | ||
path( | ||
'account-email-verification-sent/', TemplateView.as_view(), | ||
name='account_email_verification_sent', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
from django.shortcuts import render | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from dj_rest_auth.registration.views import RegisterView | ||
from chat.models import Setting | ||
|
||
# Create your views here. | ||
from dj_rest_auth.views import LoginView | ||
|
||
class RegistrationView(RegisterView): | ||
def create(self, request, *args, **kwargs): | ||
try: | ||
open_registration = Setting.objects.get(name='open_registration').value == 'True' | ||
except Setting.DoesNotExist: | ||
open_registration = True | ||
|
||
if open_registration: | ||
return super().create(request, *args, **kwargs) | ||
else: | ||
return Response({'detail': 'Registration is not yet open.'}, status=status.HTTP_403_FORBIDDEN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters