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