Created
February 5, 2020 05:58
-
-
Save b3h3rkz/51a7a4e465310da9a193e2cb7a933093 to your computer and use it in GitHub Desktop.
Django email confirmation resend
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
from rest_framework import generics | |
from allauth.account.utils import send_email_confirmation | |
from rest_framework.views import APIView | |
from rest_framework import status | |
from rest_framework.response import Response | |
from rest_framework.permissions import AllowAny | |
# request a new confirmation email | |
class EmailConfirmation(APIView): | |
permission_classes = [AllowAny] | |
def post(self, request): | |
user = User.objects.get(email=request.data['email'] # the email sent from the client | |
# check if user exists or not, if user doesn't exist, send the response back to the user to let them know that no account with this email exists | |
# if user exists, resend the email using this | |
send_email_confirmation(request, request.user) | |
return Response({'message': 'Email confirmation sent'}, status=status.HTTP_201_CREATED) | |
URLS.PY | |
from users.views import EmailConfirmation | |
urlpatterns = [ | |
... | |
path('resend_confirmation_email/', EmailConfirmation.as_view(), name='resend-email-confirmation') | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment