Skip to content

Commit

Permalink
add email new checks for duplicates
Browse files Browse the repository at this point in the history
git-svn-id: http://django-email-confirmation.googlecode.com/svn/trunk@19 e143efbd-a74b-0410-b764-bd10452ab0ba
  • Loading branch information
jtauber committed Apr 26, 2008
1 parent b937dd9 commit 7e93516
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions devproject/devtest/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,19 @@ def save(self):

class AddEmailForm(forms.Form):

def __init__(self, data=None, user=None):
super(AddEmailForm, self).__init__(data=data)
self.user = user

email = forms.EmailField(label="Email", required=True, widget=forms.TextInput())

def save(self, user):
return EmailAddress.objects.add_email(user, self.cleaned_data["email"])
def clean_email(self):
try:
EmailAddress.objects.get(user=self.user, email=self.cleaned_data["email"])
except EmailAddress.DoesNotExist:
return self.cleaned_data["email"]
raise forms.ValidationError(u"This email address already associated with this account.")

def save(self):
return EmailAddress.objects.add_email(self.user, self.cleaned_data["email"])

4 changes: 2 additions & 2 deletions devproject/devtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def signup(request):

def homepage(request):
if request.method == "POST" and request.user.is_authenticated():
add_email_form = AddEmailForm(request.POST)
add_email_form = AddEmailForm(request.POST, request.user)
if add_email_form.is_valid():
add_email_form.save(request.user)
add_email_form.save()
else:
add_email_form = AddEmailForm()

Expand Down

0 comments on commit 7e93516

Please sign in to comment.