sso, users: Turn off autocapitalization on the username field

Set autocapitalization='none' and autocomplete='username' on the username field.
Latest Django version uses those attributes by default on the username field.

Closes #1207

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Veiko Aasa 2020-02-03 19:41:41 +02:00 committed by James Valleroy
parent bcadf26ffc
commit 72f653f5e8
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 26 additions and 10 deletions

View File

@ -24,9 +24,17 @@ from django.contrib.auth.forms import \
class AuthenticationForm(DjangoAuthenticationForm):
"""Authentication form with an additional Captcha field."""
captcha = CaptchaField()
"""Authentication form with an additional username field attributes."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
self.fields['username'].widget.attrs.update({
'autofocus': 'autofocus',
'autocapitalize': 'none',
'autocomplete': 'username'
})
class CaptchaAuthenticationForm(AuthenticationForm):
"""Authentication form with an additional Captcha field."""
captcha = CaptchaField()

View File

@ -27,10 +27,9 @@ from axes.decorators import axes_form_invalid
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.views import LoginView, LogoutView
from django.http import HttpResponseRedirect
from plinth import actions, utils, web_framework
from .forms import AuthenticationForm
from .forms import AuthenticationForm, CaptchaAuthenticationForm
PRIVATE_KEY_FILE_NAME = 'privkey.pem'
SSO_COOKIE_NAME = 'auth_pubtkt'
@ -61,6 +60,7 @@ class SSOLoginView(LoginView):
"""
redirect_authenticated_user = True
template_name = 'login.html'
form_class = AuthenticationForm
def dispatch(self, request, *args, **kwargs):
response = super(SSOLoginView, self).dispatch(request, *args, **kwargs)
@ -79,11 +79,11 @@ class SSOLoginView(LoginView):
class CaptchaLoginView(LoginView):
redirect_authenticated_user = True
template_name = 'login.html'
form_class = AuthenticationForm
form_class = CaptchaAuthenticationForm
def dispatch(self, request, *args, **kwargs):
response = super(CaptchaLoginView,
self).dispatch(request, *args, **kwargs)
response = super(CaptchaLoginView, self).dispatch(
request, *args, **kwargs)
if not request.POST:
return response

View File

@ -125,7 +125,11 @@ class CreateUserForm(ValidNewUsernameCheckMixin,
self.request = request
super(CreateUserForm, self).__init__(*args, **kwargs)
self.fields['groups'].choices = get_group_choices()
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
self.fields['username'].widget.attrs.update({
'autofocus': 'autofocus',
'autocapitalize': 'none',
'autocomplete': 'username'
})
def save(self, commit=True):
"""Save the user model and create LDAP user if required."""
@ -194,7 +198,11 @@ class UserUpdateForm(ValidNewUsernameCheckMixin,
self.username = username
super(UserUpdateForm, self).__init__(*args, **kwargs)
self.is_last_admin_user = get_last_admin_user() == self.username
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
self.fields['username'].widget.attrs.update({
'autofocus': 'autofocus',
'autocapitalize': 'none',
'autocomplete': 'username'
})
choices = []