fnp
/
redakcja.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
56020b3
)
validate username (email) at registration
author
Jan Szejko
<janek37@gmail.com>
Tue, 14 Feb 2017 12:00:35 +0000
(13:00 +0100)
committer
Jan Szejko
<janek37@gmail.com>
Tue, 14 Feb 2017 12:00:35 +0000
(13:00 +0100)
redakcja/forms.py
patch
|
blob
|
history
diff --git
a/redakcja/forms.py
b/redakcja/forms.py
index
16ad87e
..
0d21bb3
100644
(file)
--- a/
redakcja/forms.py
+++ b/
redakcja/forms.py
@@
-4,6
+4,8
@@
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django import forms
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django import forms
+from django.utils.translation import ugettext as _
+from django.contrib.auth.models import User
class RegistrationForm(forms.Form):
class RegistrationForm(forms.Form):
@@
-11,3
+13,12
@@
class RegistrationForm(forms.Form):
last_name = forms.CharField()
email = forms.EmailField()
password = forms.CharField(widget=forms.PasswordInput)
last_name = forms.CharField()
email = forms.EmailField()
password = forms.CharField(widget=forms.PasswordInput)
+
+ def clean_email(self):
+ max_length = User._meta.get_field('username').max_length
+ email = self.cleaned_data['email']
+ if User.objects.filter(username=email).exists():
+ raise forms.ValidationError(_('User with this email address already exists.'))
+ if len(email) > max_length:
+ raise forms.ValidationError(_('Username too long. Max length: %s') % max_length)
+ return email