diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py index f39bb8b..758500f 100644 --- a/tubearchivist/home/forms.py +++ b/tubearchivist/home/forms.py @@ -16,6 +16,7 @@ class CustomAuthForm(AuthenticationForm): password = forms.CharField( widget=PasswordInput(attrs={"placeholder": "Password"}), label=False ) + remember_me = forms.BooleanField(required=False) class UserSettingsForm(forms.Form): diff --git a/tubearchivist/home/templates/home/login.html b/tubearchivist/home/templates/home/login.html index 03d2167..dbcd3ba 100644 --- a/tubearchivist/home/templates/home/login.html +++ b/tubearchivist/home/templates/home/login.html @@ -29,9 +29,9 @@ {% endif %}
{% csrf_token %} - {% for field in form %} - {{ field }}
- {% endfor %} + {{ form.username }}
+ {{ form.password }}
+

Remember me: {{ form.remember_me }}

diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 340f69d..5cc04e7 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -173,6 +173,8 @@ class LoginView(View): Greeting and login page """ + SEC_IN_DAY = 60 * 60 * 24 + @staticmethod def get(request): """handle get requests""" @@ -182,11 +184,17 @@ class LoginView(View): context = {"colors": colors, "form": form, "form_error": failed} return render(request, "home/login.html", context) - @staticmethod - def post(request): + def post(self, request): """handle login post request""" form = AuthenticationForm(data=request.POST) if form.is_valid(): + remember_me = request.POST.get("remember_me") or False + if remember_me == "on": + request.session.set_expiry(self.SEC_IN_DAY * 365) + else: + request.session.set_expiry(self.SEC_IN_DAY * 2) + print(f"expire session in {request.session.get_expiry_age()} secs") + next_url = request.POST.get("next") or "home" user = form.get_user() login(request, user) diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index c6ac41d..72fabf7 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -543,6 +543,10 @@ button:hover { min-width: 200px; } +#id_remember_me { + min-width: unset; +} + .login-page button, .login-page .danger-zone { width: 210px;