Skip to content

Commit 1786703

Browse files
authored
Add error message when email already exists (#272)
* Add error message when email already exists * Run black
1 parent ffba4b1 commit 1786703

3 files changed

Lines changed: 104 additions & 82 deletions

File tree

website/members/forms.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from PIL import Image
2+
from django.core.exceptions import ValidationError
23
from django.conf import settings
34
from django.contrib.auth.forms import SetPasswordForm
45
from django.contrib.auth.models import User
@@ -47,6 +48,19 @@ def clean_password(self):
4748
validate_password(self.data["password"], self.instance)
4849
return self.data["password"]
4950

51+
def clean_email(self):
52+
email = self.cleaned_data["email"]
53+
54+
try:
55+
User._default_manager.get(email=email)
56+
except User.DoesNotExist:
57+
return email
58+
raise ValidationError(
59+
_(
60+
"Email already registered. If you are having trouble logging in, you can reset your password."
61+
)
62+
)
63+
5064
def save(self, commit=True, *args, **kwargs):
5165
member = super().save(commit=False)
5266
user = User.objects.create_user(
209 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)