Skip to content

Commit

Permalink
Preventing users from using an existing email
Browse files Browse the repository at this point in the history
  • Loading branch information
yahyaaly151989 committed Sep 23, 2023
1 parent a6540ef commit 78c8f5a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Binary file modified Module04/bookmarks/account/__pycache__/forms.cpython-311.pyc
Binary file not shown.
14 changes: 14 additions & 0 deletions Module04/bookmarks/account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,25 @@ def clean_password2(self):
raise forms.ValidationError("Passwords don't match.")
return cd['password2']

def clean_email(self):
data = self.cleaned_data['email']
if User.objects.filter(email=data).exists():
raise forms.ValidationError('Email already exists.')
return data


class UserEditForm(forms.ModelForm):
class Meta:
model = User
fields = ['first_name', 'last_name', 'email']

def clean_email(self):
data = self.cleaned_data['email']
qs = User.objects.exclude(id=self.instance.id).filter(email=data)
if qs.exists():
raise forms.ValidationError('Email already exists.')
return data

class ProfileEditForm(forms.ModelForm):
class Meta:
model = Profile
Expand Down
Binary file modified Module04/bookmarks/db.sqlite3
Binary file not shown.

0 comments on commit 78c8f5a

Please sign in to comment.