Merge pull request #705 from jsma/custom-user-model-fixes

Fixed login form to reference USERNAME_FIELD
This commit is contained in:
Karl Hobley 2014-10-28 16:25:58 +00:00
commit 9b01f9e2d7
3 changed files with 9 additions and 4 deletions

View file

@ -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)

View file

@ -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 %}

View file

@ -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,
},
)