From cabd0a87f1fca7225e890cc3b15d116da9e1319b Mon Sep 17 00:00:00 2001 From: Raynaldo Rivera Date: Thu, 23 Oct 2014 01:14:36 -0700 Subject: [PATCH] Added the check for duplicate email registration --- registration/forms.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/registration/forms.py b/registration/forms.py index 60b1ca12..11d66f51 100644 --- a/registration/forms.py +++ b/registration/forms.py @@ -1,4 +1,5 @@ from django import forms +from django.contrib.auth.models import User class RegistrationForm(forms.Form): @@ -12,6 +13,13 @@ class RegistrationForm(forms.Form): if ' ' in self.cleaned_data['username']: raise forms.ValidationError(u'Username can not contain a space') + # We attempt to get the user object if we succeed we know email as been used + try: + User.objects.get(email=self.cleaned_data['email']) + raise forms.ValidationError(u'Email as already been used') + except: + pass + if 'password' in self.cleaned_data and 'password_again' in self.cleaned_data: if self.cleaned_data['password'] != self.cleaned_data['password_again']: raise forms.ValidationError(u'Passwords do not match')