kopia lustrzana https://github.com/wagtail/wagtail
Display username in password reset email - fixes #2240
rodzic
5945ad8b28
commit
3a6018e7d4
|
@ -661,6 +661,23 @@
|
|||
"email": "admin_only_user@example.com"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 5,
|
||||
"model": "customuser.emailuser",
|
||||
"fields": {
|
||||
"first_name": "",
|
||||
"last_name": "",
|
||||
"is_active": true,
|
||||
"is_superuser": false,
|
||||
"is_staff": false,
|
||||
"groups": [
|
||||
["Site-wide editors"]
|
||||
],
|
||||
"user_permissions": [],
|
||||
"password": "md5$seasalt$1e9bf2bf5606aa5c39852cc30f0f6f22",
|
||||
"email": "siteeditor@example.com"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"pk": 1,
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %}
|
||||
{% trans "Please follow the link below to reset your password" %}
|
||||
{% trans "Please follow the link below to reset your password:" %}
|
||||
{% if base_url %}{{ base_url }}{% else %}{{ protocol }}://{{ domain }}{% endif %}{% url 'wagtailadmin_password_reset_confirm' uidb64=uid token=token %}
|
||||
|
||||
{% if user.USERNAME_FIELD != "email" %}
|
||||
{% trans "Your username (in case you've forgotten):" %} {% username user %}
|
||||
{% endif %}
|
||||
|
|
|
@ -312,3 +312,12 @@ def message_tags(message):
|
|||
return level_tag
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def username(user):
|
||||
"""
|
||||
Output the username of the given user (this accounts for user models that
|
||||
give this field a name other than 'username').
|
||||
"""
|
||||
return getattr(user, user.USERNAME_FIELD)
|
||||
|
|
|
@ -58,3 +58,20 @@ class TestUserPasswordReset(TestCase, WagtailTestUtils):
|
|||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
self.assertIn("mysite.com", mail.outbox[0].body)
|
||||
|
||||
def test_password_reset_email_contains_username(self):
|
||||
self.client.post(
|
||||
reverse('wagtailadmin_password_reset'), {'email': 'siteeditor@example.com'}
|
||||
)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
self.assertIn("Your username (in case you've forgotten): siteeditor", mail.outbox[0].body)
|
||||
|
||||
@override_settings(AUTH_USER_MODEL='customuser.EmailUser')
|
||||
def test_password_reset_no_username_when_email_is_username(self):
|
||||
# When the user model is using email as the username, the password reset email
|
||||
# should not contain "Your username (in case you've forgotten)..."
|
||||
self.client.post(
|
||||
reverse('wagtailadmin_password_reset'), {'email': 'siteeditor@example.com'}
|
||||
)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
self.assertNotIn("Your username (in case you've forgotten)", mail.outbox[0].body)
|
||||
|
|
Ładowanie…
Reference in New Issue