New password confirmation field in mobile registration form. Password now requires at least 8 chars as per Mozilla security guidelines.

This commit is contained in:
sork 2011-02-23 21:50:55 +01:00
Родитель 35a1e47e9a
Коммит 0353f5c2c2
4 изменённых файлов: 31 добавлений и 35 удалений

Просмотреть файл

@ -19,11 +19,9 @@ USERNAME_LONG = _lazy(u'Username is too long (%(show_value)s characters). '
EMAIL_INVALID = _lazy(u'Please enter a valid email address.')
EMAIL_REQUIRED = _lazy(u'Please enter an email address.')
PASSWD_REQUIRED = _lazy(u'Please enter a valid password.')
#PASSWD2_REQUIRED = _lazy(u'Please enter your password twice.')
PASSWD2_REQUIRED = _lazy(u'Please enter your password twice.')
PASSWD_SHORT = _lazy(u'Password is too short '
'(At least %(limit_value)s characters).')
PASSWD_LONG = _lazy(u'Password is too long '
'(%(limit_value)s characters or less).')
PASSWD_CURRENT = _lazy(u'Please enter your current password.')
@ -42,33 +40,30 @@ class RegisterForm(forms.ModelForm):
'min_length': USERNAME_SHORT,
'max_length': USERNAME_LONG})
password = forms.CharField(error_messages={'required': PASSWD_REQUIRED,
'min_length': PASSWD_SHORT,
'max_length': PASSWD_LONG},
min_length=6, max_length=30)
'min_length': PASSWD_SHORT},
min_length=8)
password2 = forms.CharField(error_messages={'required': PASSWD2_REQUIRED})
email = forms.EmailField(error_messages={'required': EMAIL_REQUIRED,
'invalid': EMAIL_INVALID})
#password2 = forms.CharField(error_messages={'required': PASSWD2_REQUIRED})
newsletter = forms.BooleanField(required=False)
class Meta(object):
model = User
#fields = ('username', 'password', 'password2', 'email')
fields = ('username', 'password', 'email')
fields = ('username', 'password', 'password2', 'email')
def clean(self):
super(RegisterForm, self).clean()
password = self.cleaned_data.get('password')
#password2 = self.cleaned_data.get('password2')
#if not password == password2:
# raise forms.ValidationError(_('Passwords must match.'))
password2 = self.cleaned_data.get('password2')
if not password == password2:
raise forms.ValidationError(_('Passwords do not match.'))
return self.cleaned_data
def clean_email(self):
email = self.cleaned_data['email']
if email and User.objects.filter(email=email).exists():
raise forms.ValidationError(_('A user with that email address '
'already exists.'))
raise forms.ValidationError(_('Username already in use.'))
return email
def __init__(self, request=None, *args, **kwargs):
@ -129,11 +124,9 @@ class PasswordChangeForm(forms.Form):
and two matching new password values."""
password = forms.CharField(error_messages={'required': PASSWD_CURRENT})
new_password = forms.CharField(error_messages={'required': PASSWD_CURRENT,
'min_length': PASSWD_SHORT,
'max_length': PASSWD_LONG})
'min_length': PASSWD_SHORT})
new_password2 = forms.CharField(error_messages={'required': PASSWD_CURRENT,
'min_length': PASSWD_SHORT,
'max_length': PASSWD_LONG})
'min_length': PASSWD_SHORT})
def __init__(self, user, *args, **kwargs):
super(PasswordChangeForm, self).__init__(*args, **kwargs)

Просмотреть файл

@ -21,7 +21,7 @@
<input tabindex="1" type="text" name="username" value="{{ form.username.data }}" placeholder="{{ _('Username') }}" required>
</div>
<div class="input-wrapper">
<input tabindex="2" type="text" name="password" value="" placeholder="{{ _('Password') }}" required>
<input tabindex="2" type="password" name="password" value="" placeholder="{{ _('Password') }}" required>
</div>
</fieldset>
<hr>

Просмотреть файл

@ -24,7 +24,10 @@
</div>
{{ form.password.errors|safe }}
<div class="input-wrapper">
<input tabindex="2" type="password" name="password2" value="" placeholder="{{ _('Confirm Password') }}" required>
</div>
{{ form.password2.errors|safe }}
<div class="input-wrapper">
<input tabindex="3" type="email" name="email" value="{{ form.email.data|safe|replace('None','') }}" placeholder="{{ _('Email address') }}" required>
</div>
{{ form.email.errors|safe }}

Просмотреть файл

@ -28,8 +28,8 @@ class RegisterTestCase(TestCase):
response = self.client.post(reverse('users.mobile_register', locale='en-US'),
{'username': 'newbie',
'email': 'newbie@example.com',
'password': 'foobar',
'password2': 'foobar'})
'password': 'foobarbaz',
'password2': 'foobarbaz'})
eq_(302, response.status_code)
u = User.objects.get(username='newbie')
assert u.password.startswith('sha256')
@ -38,7 +38,7 @@ class RegisterTestCase(TestCase):
u.save()
response = self.client.post(reverse('users.mobile_login', locale='en-US'),
{'username': 'newbie',
'password': 'foobar'}, follow=True)
'password': 'foobarbaz'}, follow=True)
eq_(200, response.status_code)
eq_('http://testserver/en-US/m/home', response.redirect_chain[0][0])
@ -68,8 +68,8 @@ class RegisterTestCase(TestCase):
response = self.client.post(reverse('users.mobile_register', locale='en-US'),
{'username': 'jsocol',
'email': 'newbie@example.com',
'password': 'foobar',
'password2': 'foobar'}, follow=True)
'password': 'foobarbaz',
'password2': 'foobarbaz'}, follow=True)
self.assertContains(response, "not right")
def test_duplicate_email(self):
@ -77,18 +77,18 @@ class RegisterTestCase(TestCase):
response = self.client.post(reverse('users.mobile_register', locale='en-US'),
{'username': 'newbie',
'email': 'noob@example.com',
'password': 'foobar',
'password2': 'foobar'}, follow=True)
'password': 'foobarbaz',
'password2': 'foobarbaz'}, follow=True)
self.assertContains(response, "not right")
## Not sure yet if we need a password2 field
# def test_no_match_passwords(self):
# response = self.client.post(reverse('users.register', locale='en-US'),
# {'username': 'newbie',
# 'email': 'newbie@example.com',
# 'password': 'foo',
# 'password2': 'bar'}, follow=True)
# self.assertContains(response, 'must match')
def test_no_match_passwords(self):
response = self.client.post(reverse('users.mobile_register', locale='en-US'),
{'username': 'newbie',
'email': 'newbie@example.com',
'password': 'foobarbaz',
'password2': 'barfoobaz'}, follow=True)
self.assertContains(response, 'do not match')
class ChangeEmailTestCase(TestCase):