mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-29 20:33:44 +03:00
Resend Verification Email Endpoint
This commit is contained in:
parent
998b2b1fbc
commit
e156ee97d0
|
@ -215,3 +215,6 @@ class RegisterSerializer(serializers.Serializer):
|
|||
|
||||
class VerifyEmailSerializer(serializers.Serializer):
|
||||
key = serializers.CharField()
|
||||
|
||||
class ResendEmailVerificationSerializer(serializers.Serializer):
|
||||
email = serializers.EmailField()
|
|
@ -1,10 +1,15 @@
|
|||
from django.views.generic import TemplateView
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import RegisterView, VerifyEmailView
|
||||
from .views import (
|
||||
RegisterView,
|
||||
VerifyEmailView,
|
||||
ResendEmailVerification
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', RegisterView.as_view(), name='rest_register'),
|
||||
url(r'^resend-verification-email/$', ResendEmailVerification.as_view(), name='rest_resend_verification_email'),
|
||||
url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'),
|
||||
|
||||
# This url is used by django-allauth and empty TemplateView is
|
||||
|
|
|
@ -14,6 +14,7 @@ from rest_framework import status
|
|||
from allauth.account.adapter import get_adapter
|
||||
from allauth.account.views import ConfirmEmailView
|
||||
from allauth.account.utils import complete_signup
|
||||
from allauth.account.models import EmailAddress
|
||||
from allauth.account import app_settings as allauth_settings
|
||||
from allauth.socialaccount import signals
|
||||
from allauth.socialaccount.adapter import get_adapter as get_social_adapter
|
||||
|
@ -24,6 +25,7 @@ from rest_auth.app_settings import (TokenSerializer,
|
|||
create_token)
|
||||
from rest_auth.models import TokenModel
|
||||
from rest_auth.registration.serializers import (VerifyEmailSerializer,
|
||||
ResendEmailVerificationSerializer,
|
||||
SocialLoginSerializer,
|
||||
SocialAccountSerializer,
|
||||
SocialConnectSerializer)
|
||||
|
@ -98,6 +100,24 @@ class VerifyEmailView(APIView, ConfirmEmailView):
|
|||
return Response({'detail': _('ok')}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ResendEmailVerification(GenericAPIView):
|
||||
serializer_class = ResendEmailVerificationSerializer
|
||||
permission_classes = (AllowAny,)
|
||||
allowed_methods = ('POST', 'OPTIONS', 'HEAD')
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
email = serializer.data['email']
|
||||
|
||||
try:
|
||||
email_address = EmailAddress.objects.get(email__exact=email, verified=False)
|
||||
email_address.send_confirmation(self.request, True)
|
||||
except EmailAddress.DoesNotExist:
|
||||
pass
|
||||
|
||||
return Response({'detail': _('Verification e-mail sent.')})
|
||||
|
||||
class SocialLoginView(LoginView):
|
||||
"""
|
||||
class used for social authentications
|
||||
|
|
Loading…
Reference in New Issue
Block a user