Skip to content

Instantly share code, notes, and snippets.

@b3h3rkz
Created February 5, 2020 05:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b3h3rkz/51a7a4e465310da9a193e2cb7a933093 to your computer and use it in GitHub Desktop.
Save b3h3rkz/51a7a4e465310da9a193e2cb7a933093 to your computer and use it in GitHub Desktop.
Django email confirmation resend
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