mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2025-02-17 02:10:42 +03:00
Resend Account Verification Email
- View, URL, Serializer rename - Test Implementation
This commit is contained in:
parent
e156ee97d0
commit
c16ea36fc5
|
@ -216,5 +216,5 @@ class RegisterSerializer(serializers.Serializer):
|
||||||
class VerifyEmailSerializer(serializers.Serializer):
|
class VerifyEmailSerializer(serializers.Serializer):
|
||||||
key = serializers.CharField()
|
key = serializers.CharField()
|
||||||
|
|
||||||
class ResendEmailVerificationSerializer(serializers.Serializer):
|
class ResendVerificationEmailSerializer(serializers.Serializer):
|
||||||
email = serializers.EmailField()
|
email = serializers.EmailField()
|
|
@ -4,14 +4,13 @@ from django.conf.urls import url
|
||||||
from .views import (
|
from .views import (
|
||||||
RegisterView,
|
RegisterView,
|
||||||
VerifyEmailView,
|
VerifyEmailView,
|
||||||
ResendEmailVerification
|
ResendVerificationEmail
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', RegisterView.as_view(), name='rest_register'),
|
url(r'^$', RegisterView.as_view(), name='rest_register'),
|
||||||
url(r'^resend-verification-email/$', ResendEmailVerification.as_view(), name='rest_resend_verification_email'),
|
url(r'^resend-verification-email/$', ResendVerificationEmail.as_view(), name='rest_resend_verification_email'),
|
||||||
url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'),
|
url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'),
|
||||||
|
|
||||||
# This url is used by django-allauth and empty TemplateView is
|
# This url is used by django-allauth and empty TemplateView is
|
||||||
# defined just to allow reverse() call inside app, for example when email
|
# 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
|
# with verification link is being sent, then it's required to render email
|
||||||
|
|
|
@ -25,7 +25,7 @@ from rest_auth.app_settings import (TokenSerializer,
|
||||||
create_token)
|
create_token)
|
||||||
from rest_auth.models import TokenModel
|
from rest_auth.models import TokenModel
|
||||||
from rest_auth.registration.serializers import (VerifyEmailSerializer,
|
from rest_auth.registration.serializers import (VerifyEmailSerializer,
|
||||||
ResendEmailVerificationSerializer,
|
ResendVerificationEmailSerializer,
|
||||||
SocialLoginSerializer,
|
SocialLoginSerializer,
|
||||||
SocialAccountSerializer,
|
SocialAccountSerializer,
|
||||||
SocialConnectSerializer)
|
SocialConnectSerializer)
|
||||||
|
@ -100,8 +100,8 @@ class VerifyEmailView(APIView, ConfirmEmailView):
|
||||||
return Response({'detail': _('ok')}, status=status.HTTP_200_OK)
|
return Response({'detail': _('ok')}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class ResendEmailVerification(GenericAPIView):
|
class ResendVerificationEmail(GenericAPIView):
|
||||||
serializer_class = ResendEmailVerificationSerializer
|
serializer_class = ResendVerificationEmailSerializer
|
||||||
permission_classes = (AllowAny,)
|
permission_classes = (AllowAny,)
|
||||||
allowed_methods = ('POST', 'OPTIONS', 'HEAD')
|
allowed_methods = ('POST', 'OPTIONS', 'HEAD')
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ from rest_framework.test import APIRequestFactory
|
||||||
from rest_auth.registration.views import RegisterView
|
from rest_auth.registration.views import RegisterView
|
||||||
from rest_auth.registration.app_settings import register_permission_classes
|
from rest_auth.registration.app_settings import register_permission_classes
|
||||||
|
|
||||||
|
from allauth.account.models import EmailAddress
|
||||||
|
|
||||||
from .mixins import TestsMixin, CustomPermissionClass
|
from .mixins import TestsMixin, CustomPermissionClass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -516,3 +518,66 @@ class APIBasicTests(TestsMixin, TestCase):
|
||||||
|
|
||||||
self.post(self.login_url, data=payload, status_code=status.HTTP_200_OK)
|
self.post(self.login_url, data=payload, status_code=status.HTTP_200_OK)
|
||||||
self.get(self.logout_url, status_code=status.HTTP_405_METHOD_NOT_ALLOWED)
|
self.get(self.logout_url, status_code=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||||
|
|
||||||
|
@override_settings(ACCOUNT_EMAIL_VERIFICATION='mandatory')
|
||||||
|
def test_resend_account_verification_email(self):
|
||||||
|
result = self.post(
|
||||||
|
self.register_url,
|
||||||
|
data=self.REGISTRATION_DATA_WITH_EMAIL,
|
||||||
|
status_code=status.HTTP_201_CREATED
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(EmailAddress.objects.count(), 1)
|
||||||
|
self.assertEqual(EmailAddress.objects.first().email, self.EMAIL)
|
||||||
|
self.assertEqual(EmailAddress.objects.first().verified, False)
|
||||||
|
|
||||||
|
self.post(
|
||||||
|
reverse('rest_resend_verification_email'),
|
||||||
|
data={
|
||||||
|
'email': self.EMAIL
|
||||||
|
},
|
||||||
|
status_code=status.HTTP_200_OK
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(mail.outbox), 2)
|
||||||
|
|
||||||
|
@override_settings(ACCOUNT_EMAIL_VERIFICATION='mandatory')
|
||||||
|
def test_resend_not_registered_account_verification_email(self):
|
||||||
|
self.assertEqual(EmailAddress.objects.count(), 0)
|
||||||
|
|
||||||
|
self.post(
|
||||||
|
reverse('rest_resend_verification_email'),
|
||||||
|
data={
|
||||||
|
'email': self.EMAIL
|
||||||
|
},
|
||||||
|
status_code=status.HTTP_200_OK
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(mail.outbox), 0)
|
||||||
|
|
||||||
|
@override_settings(ACCOUNT_EMAIL_VERIFICATION='mandatory')
|
||||||
|
def test_resend_already_verified_account_verification_email(self):
|
||||||
|
result = self.post(
|
||||||
|
self.register_url,
|
||||||
|
data=self.REGISTRATION_DATA_WITH_EMAIL,
|
||||||
|
status_code=status.HTTP_201_CREATED
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(EmailAddress.objects.count(), 1)
|
||||||
|
self.assertEqual(EmailAddress.objects.first().email, self.EMAIL)
|
||||||
|
self.assertEqual(EmailAddress.objects.first().verified, False)
|
||||||
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
|
||||||
|
email_address = EmailAddress.objects.first()
|
||||||
|
email_address.verified = True
|
||||||
|
email_address.save()
|
||||||
|
|
||||||
|
self.post(
|
||||||
|
reverse('rest_resend_verification_email'),
|
||||||
|
data={
|
||||||
|
'email': self.EMAIL
|
||||||
|
},
|
||||||
|
status_code=status.HTTP_200_OK
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user