forms: add an example of email address in registration form (#83254)
gitea/authentic/pipeline/head This commit looks good
Details
gitea/authentic/pipeline/head This commit looks good
Details
This commit is contained in:
parent
891dd6a1de
commit
137a5898b4
|
@ -140,8 +140,12 @@ class ValidatedEmailField(EmailField):
|
|||
widget = EmailInput
|
||||
|
||||
def __init__(self, *args, max_length=254, **kwargs):
|
||||
# pylint: disable=useless-super-delegation
|
||||
super().__init__(*args, max_length=max_length, **kwargs)
|
||||
error_messages = kwargs.pop('error_messages', {})
|
||||
if 'invalid' not in error_messages:
|
||||
error_messages['invalid'] = _(
|
||||
'Please enter a valid email address (example: john.doe@entrouvert.com)'
|
||||
)
|
||||
super().__init__(*args, max_length=max_length, error_messages=error_messages, **kwargs)
|
||||
|
||||
|
||||
class RoleChoiceField(ModelChoiceField):
|
||||
|
|
|
@ -45,7 +45,7 @@ class RegistrationForm(HoneypotForm):
|
|||
|
||||
email = ValidatedEmailField(
|
||||
label=_('Email'),
|
||||
help_text=_('Your email address'),
|
||||
help_text=_('Your email address (example: name@example.com)'),
|
||||
required=False,
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
{% block registration %}
|
||||
<div>
|
||||
<form enctype="multipart/form-data" method="post" class="pk-mark-optional-fields">
|
||||
<form enctype="multipart/form-data" method="post" class="pk-mark-optional-fields" novalidate>
|
||||
{% csrf_token %}
|
||||
{{ form|with_template }}
|
||||
<div class="buttons">
|
||||
|
|
|
@ -70,7 +70,7 @@ class EmailValidator:
|
|||
smtp.mail('')
|
||||
status = smtp.rcpt(value)
|
||||
if status[0] // 100 == 5:
|
||||
raise ValidationError(_('Invalid email address.'), code='rcpt-check-failed')
|
||||
raise ValidationError(_('Invalid email address'), code='invalid-fails-rcpt')
|
||||
break
|
||||
except smtplib.SMTPServerDisconnected:
|
||||
continue
|
||||
|
@ -88,7 +88,9 @@ class EmailValidator:
|
|||
if app_settings.A2_VALIDATE_EMAIL_DOMAIN:
|
||||
mxs = self.query_mxs(hostname)
|
||||
if not mxs:
|
||||
raise ValidationError(_('Email domain is invalid'), code='invalid-domain')
|
||||
raise ValidationError(
|
||||
_('Email domain (%(dom)s) does not exists') % {'dom': hostname}, code='invalid-domain'
|
||||
)
|
||||
if self.rcpt_check and app_settings.A2_VALIDATE_EMAIL:
|
||||
self.check_rcpt(value, mxs)
|
||||
|
||||
|
|
|
@ -471,7 +471,7 @@ def test_manager_create_user_email_validation(superuser_or_admin, app, settings,
|
|||
resp.form.set('password1', 'ABcd1234')
|
||||
resp.form.set('password2', 'ABcd1234')
|
||||
resp = resp.form.submit()
|
||||
assert 'domain is invalid' in resp.text
|
||||
assert 'Email domain (entrouvert.com) does not exists' in resp.text
|
||||
|
||||
monkeypatch.setattr(EmailValidator, 'query_mxs', lambda x, y: ['mx1.entrouvert.org'])
|
||||
resp.form.submit()
|
||||
|
|
|
@ -444,7 +444,7 @@ def test_email_validation(app, db):
|
|||
resp = app.get('/password/reset/')
|
||||
resp.form.set('email', 'coin@')
|
||||
resp = resp.form.submit()
|
||||
assert 'Enter a valid email address.' in resp
|
||||
assert 'Please enter a valid email address (example: john.doe@entrouvert.com)' in resp
|
||||
|
||||
|
||||
def test_honeypot(app, db, settings, mailoutbox):
|
||||
|
|
|
@ -181,7 +181,7 @@ def test_registration_email_validation(app, db, monkeypatch, settings):
|
|||
resp = app.get(reverse('registration_register'))
|
||||
resp.form.set('email', 'testbot@entrouvert.com')
|
||||
resp = resp.form.submit()
|
||||
assert 'domain is invalid' in resp.text
|
||||
assert 'Email domain (entrouvert.com) does not exists' in resp.text
|
||||
|
||||
|
||||
def test_username_settings(app, db, settings, mailoutbox):
|
||||
|
@ -426,10 +426,16 @@ def test_registration_bad_email(app, db, settings):
|
|||
settings.LANGUAGE_CODE = 'en-us'
|
||||
|
||||
response = app.post(reverse('registration_register'), params={'email': 'fred@0d..be'}, status=200)
|
||||
assert 'Enter a valid email address.' in response.context['form'].errors['email']
|
||||
assert (
|
||||
'Please enter a valid email address (example: john.doe@entrouvert.com)'
|
||||
in response.context['form'].errors['email']
|
||||
)
|
||||
|
||||
response = app.post(reverse('registration_register'), params={'email': 'ééééé'}, status=200)
|
||||
assert 'Enter a valid email address.' in response.context['form'].errors['email']
|
||||
assert (
|
||||
'Please enter a valid email address (example: john.doe@entrouvert.com)'
|
||||
in response.context['form'].errors['email']
|
||||
)
|
||||
|
||||
response = app.post(reverse('registration_register'), params={'email': ''}, status=200)
|
||||
assert response.pyquery('title')[0].text.endswith('there are errors in the form')
|
||||
|
|
Loading…
Reference in New Issue