Skip to content

Commit

Permalink
Capital letters emails fix
Browse files Browse the repository at this point in the history
  • Loading branch information
asennoussi committed Aug 30, 2023
1 parent a49a60f commit 96ed43a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion accounts/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EmailBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
UserModel = get_user_model()
try:
user = UserModel.objects.get(email=username)
user = UserModel.objects.get(email__iexact=username)
except UserModel.DoesNotExist:
return None
else:
Expand Down
6 changes: 6 additions & 0 deletions accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class Meta:
]
# We need the user object, so it's an additional parameter

def clean_email(self):
email = self.cleaned_data.get('email').lower()
if CustomUser.objects.filter(email__iexact=email).exists():
raise forms.ValidationError("Email address already exists.")
return email

def send_activation_email(self, request, user):
current_site = get_current_site(request)
subject = 'Activate Your Account'
Expand Down
1 change: 1 addition & 0 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def get_form_kwargs(self):
return kwargs

def form_valid(self, form):
form.instance.email = form.instance.email.lower()
to_return = super().form_valid(form)
user = form.save()
user.is_verified = False # Turns the user email verification to False
Expand Down

0 comments on commit 96ed43a

Please sign in to comment.