Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
af4eb974
Commit
af4eb974
authored
Jan 25, 2012
by
Sofia Papagiannaki
Browse files
user registration form checks whether the email is reserved
parent
5d8dfc69
Changes
1
Hide whitespace changes
Inline
Side-by-side
astakos/im/forms.py
View file @
af4eb974
...
...
@@ -46,28 +46,13 @@ from astakos.im.util 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
)
try
:
AstakosUser
.
objects
.
get
(
email
=
value
)
raise
forms
.
ValidationError
(
"Email already exists"
)
except
AstakosUser
.
MultipleObjectsReturned
:
raise
forms
.
ValidationError
(
"Email already exists"
)
except
AstakosUser
.
DoesNotExist
:
pass
class
ExtendedUserCreationForm
(
UserCreationForm
):
"""
Extends the built in UserCreationForm in several ways:
* Adds
an
email
field, which uses the custom UniqueUserEmailF
ield.
* Adds email
, first_name and last_name f
ield.
* 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'
]
try
:
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment