Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send email confirmation mail on login for mandatory EmailVerification setting #573

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rest_auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from rest_framework import serializers, exceptions
from rest_framework.exceptions import ValidationError

from allauth.account.utils import send_email_confirmation

from .models import TokenModel
from .utils import import_callable

Expand Down Expand Up @@ -64,6 +66,7 @@ def validate(self, attrs):
email = attrs.get('email')
password = attrs.get('password')


user = None

if 'allauth' in settings.INSTALLED_APPS:
Expand Down Expand Up @@ -107,6 +110,12 @@ def validate(self, attrs):
if app_settings.EMAIL_VERIFICATION == app_settings.EmailVerificationMethod.MANDATORY:
email_address = user.emailaddress_set.get(email=user.email)
if not email_address.verified:
# send email confirmation mail for mandatory verification settings
request = self.context.get("request")
# above `request` is DRF's Request class wrapper on Django's HttpRequest
django_http_request = getattr(request, "_request", None)
if django_http_request:
send_email_confirmation(django_http_request, user)
raise serializers.ValidationError(_('E-mail is not verified.'))

attrs['user'] = user
Expand Down