Commit af4eb974 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

user registration form checks whether the email is reserved

parent 5d8dfc69
......@@ -46,28 +46,13 @@ from import get_or_create_user
import logging
import uuid
class UniqueUserEmailField(forms.EmailField):
An EmailField which only is valid if no User has that email.
def validate(self, value):
super(forms.EmailField, self).validate(value)
AstakosUser.objects.get(email = value)
raise forms.ValidationError("Email already exists")
except AstakosUser.MultipleObjectsReturned:
raise forms.ValidationError("Email already exists")
except AstakosUser.DoesNotExist:
class ExtendedUserCreationForm(UserCreationForm):
Extends the built in UserCreationForm in several ways:
* Adds an email field, which uses the custom UniqueUserEmailField.
* Adds email, first_name and last_name field.
* The username field isn't visible and it is assigned a generated id.
* first_name and last_name fields are added.
* User is created not active.
* User created is not active.
class Meta:
......@@ -82,6 +67,14 @@ class ExtendedUserCreationForm(UserCreationForm):
self.fields.keyOrder = ['email', 'first_name', 'last_name',
'password1', 'password2']
def clean_email(self):
email = self.cleaned_data['email']
AstakosUser.objects.get(email = email)
raise forms.ValidationError(_("Email is reserved"))
except AstakosUser.DoesNotExist:
return email
def save(self, commit=True):
Saves the email, first_name and last_name properties, after the normal
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