mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-08 00:51:10 +00:00
Merge pull request #705 from jsma/custom-user-model-fixes
Fixed login form to reference USERNAME_FIELD
This commit is contained in:
commit
9b01f9e2d7
3 changed files with 9 additions and 4 deletions
|
|
@ -40,9 +40,7 @@ class EmailLinkChooserWithLinkTextForm(forms.Form):
|
|||
class LoginForm(AuthenticationForm):
|
||||
username = forms.CharField(
|
||||
max_length=254,
|
||||
widget=forms.TextInput(attrs={'placeholder': ugettext_lazy("Enter your username"),
|
||||
'tabindex': '1',
|
||||
}),
|
||||
widget=forms.TextInput(attrs={'tabindex': '1',}),
|
||||
)
|
||||
password = forms.CharField(
|
||||
widget=forms.PasswordInput(attrs={'placeholder': ugettext_lazy("Enter password"),
|
||||
|
|
@ -50,6 +48,11 @@ class LoginForm(AuthenticationForm):
|
|||
}),
|
||||
)
|
||||
|
||||
def __init__(self, request=None, *args, **kwargs):
|
||||
super(LoginForm, self).__init__(request=request, *args, **kwargs)
|
||||
self.fields['username'].widget.attrs['placeholder'] = ugettext_lazy("Enter your %s") % self.username_field.verbose_name
|
||||
|
||||
|
||||
|
||||
class PasswordResetForm(PasswordResetForm):
|
||||
email = forms.EmailField(label=ugettext_lazy("Enter your email address to reset your password"), max_length=254)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
{% if form.errors %}
|
||||
<div class="messages">
|
||||
<ul>
|
||||
<li class="error">{% trans "Your username and password didn't match. Please try again." %}</li>
|
||||
<li class="error">{% blocktrans %}Your {{ username_field }} and password didn't match. Please try again.{% endblocktrans %}</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -78,11 +78,13 @@ def login(request):
|
|||
if request.user.is_authenticated() and request.user.has_perm('wagtailadmin.access_admin'):
|
||||
return redirect('wagtailadmin_home')
|
||||
else:
|
||||
from django.contrib.auth import get_user_model
|
||||
return auth_login(request,
|
||||
template_name='wagtailadmin/login.html',
|
||||
authentication_form=forms.LoginForm,
|
||||
extra_context={
|
||||
'show_password_reset': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True),
|
||||
'username_field': get_user_model().USERNAME_FIELD,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue