From e1a2618d465cb6a49739568d3dd8f83282702add Mon Sep 17 00:00:00 2001 From: m5ka Date: Tue, 26 Mar 2024 17:05:43 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=99=8B=E2=80=8D=20allow=20case-ins?= =?UTF-8?q?ensitive=20login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moku/forms/auth.py | 12 ++++++++++++ moku/views/auth.py | 2 ++ 2 files changed, 14 insertions(+) create mode 100644 moku/forms/auth.py diff --git a/moku/forms/auth.py b/moku/forms/auth.py new file mode 100644 index 0000000..88a503f --- /dev/null +++ b/moku/forms/auth.py @@ -0,0 +1,12 @@ +from django.contrib.auth.forms import AuthenticationForm as BaseAuthenticationForm +from django.utils.translation import gettext_lazy as _ + + +class AuthenticationForm(BaseAuthenticationForm): + error_messages = { + "invalid_login": _("sorry! that username and password didn't work."), + "inactive": _("your account has been deactivated."), + } + + def clean_username(self): + return self.cleaned_data.get("username").lower() diff --git a/moku/views/auth.py b/moku/views/auth.py index 6197a0b..5d42d65 100644 --- a/moku/views/auth.py +++ b/moku/views/auth.py @@ -5,6 +5,7 @@ from django.shortcuts import redirect from django.urls import reverse_lazy from django.utils.translation import gettext as _ +from moku.forms.auth import AuthenticationForm from moku.views.base import View @@ -12,6 +13,7 @@ class LoginView(View, BaseLoginView): """Allows users to log in by username and password.""" template_name = "moku/login.jinja" + form_class = AuthenticationForm page_title = "log in" def get(self, request, *args, **kwargs):