mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
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:
parent
bcadf26ffc
commit
72f653f5e8
@ -24,9 +24,17 @@ from django.contrib.auth.forms import \
|
|||||||
|
|
||||||
|
|
||||||
class AuthenticationForm(DjangoAuthenticationForm):
|
class AuthenticationForm(DjangoAuthenticationForm):
|
||||||
"""Authentication form with an additional Captcha field."""
|
"""Authentication form with an additional username field attributes."""
|
||||||
captcha = CaptchaField()
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*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()
|
||||||
|
|||||||
@ -27,10 +27,9 @@ from axes.decorators import axes_form_invalid
|
|||||||
from django.contrib.auth import REDIRECT_FIELD_NAME
|
from django.contrib.auth import REDIRECT_FIELD_NAME
|
||||||
from django.contrib.auth.views import LoginView, LogoutView
|
from django.contrib.auth.views import LoginView, LogoutView
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
|
|
||||||
from plinth import actions, utils, web_framework
|
from plinth import actions, utils, web_framework
|
||||||
|
|
||||||
from .forms import AuthenticationForm
|
from .forms import AuthenticationForm, CaptchaAuthenticationForm
|
||||||
|
|
||||||
PRIVATE_KEY_FILE_NAME = 'privkey.pem'
|
PRIVATE_KEY_FILE_NAME = 'privkey.pem'
|
||||||
SSO_COOKIE_NAME = 'auth_pubtkt'
|
SSO_COOKIE_NAME = 'auth_pubtkt'
|
||||||
@ -61,6 +60,7 @@ class SSOLoginView(LoginView):
|
|||||||
"""
|
"""
|
||||||
redirect_authenticated_user = True
|
redirect_authenticated_user = True
|
||||||
template_name = 'login.html'
|
template_name = 'login.html'
|
||||||
|
form_class = AuthenticationForm
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
response = super(SSOLoginView, self).dispatch(request, *args, **kwargs)
|
response = super(SSOLoginView, self).dispatch(request, *args, **kwargs)
|
||||||
@ -79,11 +79,11 @@ class SSOLoginView(LoginView):
|
|||||||
class CaptchaLoginView(LoginView):
|
class CaptchaLoginView(LoginView):
|
||||||
redirect_authenticated_user = True
|
redirect_authenticated_user = True
|
||||||
template_name = 'login.html'
|
template_name = 'login.html'
|
||||||
form_class = AuthenticationForm
|
form_class = CaptchaAuthenticationForm
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
response = super(CaptchaLoginView,
|
response = super(CaptchaLoginView, self).dispatch(
|
||||||
self).dispatch(request, *args, **kwargs)
|
request, *args, **kwargs)
|
||||||
if not request.POST:
|
if not request.POST:
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|||||||
@ -125,7 +125,11 @@ class CreateUserForm(ValidNewUsernameCheckMixin,
|
|||||||
self.request = request
|
self.request = request
|
||||||
super(CreateUserForm, self).__init__(*args, **kwargs)
|
super(CreateUserForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['groups'].choices = get_group_choices()
|
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):
|
def save(self, commit=True):
|
||||||
"""Save the user model and create LDAP user if required."""
|
"""Save the user model and create LDAP user if required."""
|
||||||
@ -194,7 +198,11 @@ class UserUpdateForm(ValidNewUsernameCheckMixin,
|
|||||||
self.username = username
|
self.username = username
|
||||||
super(UserUpdateForm, self).__init__(*args, **kwargs)
|
super(UserUpdateForm, self).__init__(*args, **kwargs)
|
||||||
self.is_last_admin_user = get_last_admin_user() == self.username
|
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 = []
|
choices = []
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user