From e3bf217b927bb1c28dbb1d6563d43869949dd96e Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 19 Jul 2018 16:12:59 +0200 Subject: [PATCH 8/9] use new password fields in registration form (fixes #24439) --- src/authentic2/registration_backend/forms.py | 7 +++---- tests/test_registration.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/authentic2/registration_backend/forms.py b/src/authentic2/registration_backend/forms.py index 8ca7d9c5..fa31cbac 100644 --- a/src/authentic2/registration_backend/forms.py +++ b/src/authentic2/registration_backend/forms.py @@ -19,6 +19,7 @@ from django.template.loader import render_to_string from django.core.urlresolvers import reverse from django.core.validators import RegexValidator +from authentic2.forms.fields import NewPasswordField, CheckPasswordField from .. import app_settings, compat, forms, utils, validators, models, middleware, hooks from authentic2.a2_rbac.models import OrganizationalUnit @@ -115,10 +116,8 @@ class RegistrationCompletionFormNoPassword(forms.BaseUserForm): class RegistrationCompletionForm(RegistrationCompletionFormNoPassword): - password1 = CharField(widget=PasswordInput, label=_("Password"), - validators=[validators.validate_password], - help_text=validators.password_help_text()) - password2 = CharField(widget=PasswordInput, label=_("Password (again)")) + password1 = NewPasswordField(label=_('Password')) + password2 = CheckPasswordField(label=_("Password (again)")) def clean(self): """ diff --git a/tests/test_registration.py b/tests/test_registration.py index d6d3a104..bbd040e7 100644 --- a/tests/test_registration.py +++ b/tests/test_registration.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import re from urlparse import urlparse from django.core.urlresolvers import reverse @@ -585,3 +586,19 @@ def test_registration_redirect_tuple(app, db, settings, mailoutbox, external_red response = response.form.submit() assert new_next_url in response.content + +def test_registration_activate_passwords_not_equal(app, db, settings, mailoutbox): + settings.LANGUAGE_CODE = 'en-us' + settings.A2_VALIDATE_EMAIL_DOMAIN = can_resolve_dns() + settings.A2_EMAIL_IS_UNIQUE = True + + response = app.get(reverse('registration_register')) + response.form.set('email', 'testbot@entrouvert.com') + response = response.form.submit() + response = response.follow() + link = get_link_from_mail(mailoutbox[0]) + response = app.get(link) + response.form.set('password1', 'azerty12AZ') + response.form.set('password2', 'AAAazerty12AZ') + response = response.form.submit() + assert "The two password fields didn't match." in response.content -- 2.18.0