Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
a72297f5
Commit
a72297f5
authored
Apr 25, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate unique email when adding users
Issue #1086 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
ccc3dd4c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
17 deletions
+20
-17
weblate/accounts/admin.py
weblate/accounts/admin.py
+2
-1
weblate/accounts/forms.py
weblate/accounts/forms.py
+18
-16
No files found.
weblate/accounts/admin.py
View file @
a72297f5
...
...
@@ -24,6 +24,7 @@ from django.contrib.auth.admin import UserAdmin
from
django.contrib.auth.forms
import
UserCreationForm
,
UserChangeForm
from
django.contrib.auth.models
import
User
from
weblate.accounts.forms
import
UniqueEmailMixin
from
weblate.accounts.models
import
Profile
,
VerifiedEmail
,
AutoGroup
...
...
@@ -61,7 +62,7 @@ class WeblateUserChangeForm(UserChangeForm):
self
.
fields
[
'email'
].
required
=
True
class
WeblateUserCreationForm
(
UserCreationForm
):
class
WeblateUserCreationForm
(
UserCreationForm
,
UniqueEmailMixin
):
class
Meta
(
object
):
fields
=
(
'username'
,
'email'
)
...
...
weblate/accounts/forms.py
View file @
a72297f5
...
...
@@ -69,6 +69,23 @@ def sort_choices(choices):
)
class
UniqueEmailMixin
(
object
):
def
clean_email
(
self
):
"""
Validate that the supplied email address is unique for the
site.
"""
if
User
.
objects
.
filter
(
email__iexact
=
self
.
cleaned_data
[
'email'
]):
raise
forms
.
ValidationError
(
_
(
"This email address is already in use. "
"Please supply a different email address."
)
)
return
self
.
cleaned_data
[
'email'
]
class
NoStripEmailField
(
forms
.
EmailField
):
"""
Email field which does no stripping.
...
...
@@ -311,7 +328,7 @@ class ContactForm(forms.Form):
return ''
class EmailForm(forms.Form):
class EmailForm(forms.Form
, UniqueEmailMixin
):
'''
Email change form.
'''
...
...
@@ -325,21 +342,6 @@ class EmailForm(forms.Form):
)
content = forms.CharField(required=False)
def clean_email(self):
"""
Validate that the supplied email address is unique for the
site.
"""
if User.objects.filter(email__iexact=self.cleaned_data['
email
']):
raise forms.ValidationError(
_(
"This email address is already in use. "
"Please supply a different email address."
)
)
return self.cleaned_data['
email
']
def clean_content(self):
'''
Check if content is empty.
...
...
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