Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mymusiclist
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Brian Guadalupe
mymusiclist
Commits
daedae1c
Commit
daedae1c
authored
Nov 15, 2017
by
Brian Guadalupe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add form validation for checking email
parent
fe29d113
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
forms.py
user/forms.py
+7
-1
views.py
user/views.py
+6
-0
No files found.
user/forms.py
View file @
daedae1c
...
...
@@ -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
user/views.py
View file @
daedae1c
...
...
@@ -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
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