Commit daedae1c authored by Brian Guadalupe's avatar Brian Guadalupe

Add form validation for checking email

parent fe29d113
......@@ -2,7 +2,6 @@ from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=255)
last_name = forms.CharField(max_length=255)
......@@ -11,3 +10,10 @@ class SignUpForm(UserCreationForm):
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', )
def clean_email(self):
email = self.cleaned_data.get('email')
username = self.cleaned_data.get('username')
if email and User.objects.filter(email=email).exclude(username=username).exists():
raise forms.ValidationError('User with this Email address already exists.')
return email
\ No newline at end of file
......@@ -29,3 +29,9 @@ class EditProfile(UpdateView):
slug_field = 'username'
slug_url_kwarg = 'slug'
def clean_email(self):
email = self.cleaned_data.get('email')
username = self.cleaned_data.get('username')
if email and User.objects.filter(email=email).exclude(username=username).exists():
raise forms.ValidationError('This email address has been already used by another user.')
return email
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment