mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-22 09:06:40 +03:00
veirfy email view and test
This commit is contained in:
parent
de1fb3d81f
commit
08fcca9b48
|
@ -5,8 +5,7 @@ from .views import Register, VerifyEmail
|
|||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', Register.as_view(), name='rest_register'),
|
||||
url(r'^verify-email/(?P<activation_key>\w+)/$', VerifyEmail.as_view(),
|
||||
name='verify_email'),
|
||||
url(r'^verify-email/$', VerifyEmail.as_view(), name='verify_email'),
|
||||
|
||||
url(r'^account-email-verification-sent/$', TemplateView.as_view(),
|
||||
name='account_email_verification_sent'),
|
||||
|
|
|
@ -3,7 +3,7 @@ from rest_framework.response import Response
|
|||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework import status
|
||||
|
||||
from allauth.account.views import SignupView
|
||||
from allauth.account.views import SignupView, ConfirmEmailView
|
||||
from allauth.account.utils import complete_signup
|
||||
from allauth.account import app_settings
|
||||
|
||||
|
@ -40,5 +40,12 @@ class Register(APIView, SignupView):
|
|||
return Response(self.form.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class VerifyEmail(APIView):
|
||||
pass
|
||||
class VerifyEmail(APIView, ConfirmEmailView):
|
||||
|
||||
permission_classes = (AllowAny,)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.kwargs['key'] = self.request.DATA.get('key', '')
|
||||
confirmation = self.get_object()
|
||||
confirmation.confirm(self.request)
|
||||
return Response({'message': 'ok'}, status=status.HTTP_200_OK)
|
||||
|
|
|
@ -153,6 +153,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
|||
self.register_url = reverse('rest_register')
|
||||
self.password_reset_url = reverse('rest_password_reset')
|
||||
self.user_url = reverse('rest_user_details')
|
||||
self.veirfy_email_url = reverse('verify_email')
|
||||
|
||||
setattr(settings, 'REST_PROFILE_MODULE', self.PROFILE_MODEL)
|
||||
self.user_profile_model = None
|
||||
|
@ -323,9 +324,11 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
|||
mail_count = len(mail.outbox)
|
||||
|
||||
# test empty payload
|
||||
self.post(self.register_url, data={}, status_code=400)
|
||||
self.post(self.register_url, data={},
|
||||
status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
self.post(self.register_url, data=self.REGISTRATION_DATA_WITH_EMAIL, status_code=201)
|
||||
self.post(self.register_url, data=self.REGISTRATION_DATA_WITH_EMAIL,
|
||||
status_code=status.HTTP_201_BAD_REQUEST)
|
||||
self.assertEqual(User.objects.all().count(), user_count + 1)
|
||||
self.assertEqual(len(mail.outbox), mail_count + 1)
|
||||
new_user = get_user_model().objects.latest('id')
|
||||
|
@ -336,4 +339,14 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
|||
"username": self.USERNAME,
|
||||
"password": self.PASS
|
||||
}
|
||||
self.post(self.login_url, data=payload, status=status.HTTP_400_BAD_REQUEST)
|
||||
self.post(self.login_url, data=payload,
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# veirfy email
|
||||
email_confirmation = new_user.emailaddress_set.get(email=self.EMAIL)\
|
||||
.emailconfirmation_set.last()
|
||||
self.post(self.veirfy_email_url, data={"key": email_confirmation.key},
|
||||
status_code=status.HTTP_200_OK)
|
||||
|
||||
# try to login again
|
||||
self.post(self.login_url, data=payload, status_code=status.HTTP_200_OK)
|
||||
|
|
Loading…
Reference in New Issue
Block a user