From c067301452943085950f720320d7d04e67153e8f Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Wed, 22 May 2024 08:26:05 +0200 Subject: [PATCH] Add a Remeber me checkbox to login that extend session time. (#3926) Fixes #3897 "Remember me" is only available when logging in with password. I see this as an "advanced" feature. The passwordless login flow is easy so not a big hassle to do it once a day. Organisation that wants to can set `SESSION_COOKIE_AGE` to a custom value, e.g. set it to two weeks to reagin the old behaviour. To disable "Remember me" set `SESSION_COOKIE_AGE` to the same value as `SESSION_COOKIE_AGE_LONG` This PR also: * removes unused code is_public_site * removes unused code register_extra_text * removes all use of link-button* classes. Buttons are now only handled by the button class. * add a tiny border radius to all buttons (this is something we implement on all elements in Hypha) --- docs/setup/administrators/configuration.md | 9 +++- .../dashboard/includes/my-tasks.html | 2 +- .../templates/review/review_detail.html | 2 +- .../forms/includes/multi_input_field.html | 2 +- hypha/apply/users/forms.py | 21 +++++++- ...remove_authsettings_register_extra_text.py | 16 ++++++ hypha/apply/users/models.py | 9 ---- hypha/apply/users/templates/users/login.html | 2 +- .../partials/confirmation_code_sent.html | 2 +- .../templates/users/password_reset/form.html | 2 +- .../users/passwordless_login_signup.html | 2 +- hypha/apply/users/views.py | 13 +++-- .../news/templates/news/news_index.html | 2 +- hypha/settings/base.py | 9 +++- .../javascript/submission-form-copy.js | 6 +-- hypha/static_src/javascript/toggle-related.js | 2 +- hypha/static_src/sass/abstracts/_mixins.scss | 20 ++------ .../static_src/sass/abstracts/_variables.scss | 10 ++++ hypha/static_src/sass/components/_button.scss | 42 ++++++++++++---- hypha/static_src/sass/components/_link.scss | 50 ------------------- .../sass/components/_status-bar.scss | 1 + hypha/templates/base-apply.html | 6 +-- hypha/templates/includes/login_button.html | 6 +-- .../templates/includes/org_login_button.html | 4 +- .../includes/password_login_button.html | 4 +- .../includes/passwordless_login_button.html | 2 +- 26 files changed, 126 insertions(+), 120 deletions(-) create mode 100644 hypha/apply/users/migrations/0025_remove_authsettings_register_extra_text.py diff --git a/docs/setup/administrators/configuration.md b/docs/setup/administrators/configuration.md index 37f5dc489a..238c75605a 100644 --- a/docs/setup/administrators/configuration.md +++ b/docs/setup/administrators/configuration.md @@ -62,10 +62,15 @@ Seconds to enter password on password page while email change/2FA change (defaul The age of session cookies, in seconds. -This determines the length of time for which the user will remain logged in. The default value is 2 weeks. +This determines the length of time for which the user will remain logged in. The default value is 12 hours. - SESSION_COOKIE_AGE = env.int('SESSION_COOKIE_AGE', 60 * 60 * 24 * 7 * 2) + SSESSION_COOKIE_AGE = env.int("SESSION_COOKIE_AGE", 60 * 60 * 12) +The age of session cookies when users check "Remember me" etc., in seconds. The default value is 2 weeks. + + SESSION_COOKIE_AGE_LONG = env.int("SESSION_COOKIE_AGE_LONG", 60 * 60 * 24 * 7 * 2) + +If both session value are equal the "Remember me" feature are disabled. ## Hypha custom settings diff --git a/hypha/apply/dashboard/templates/dashboard/includes/my-tasks.html b/hypha/apply/dashboard/templates/dashboard/includes/my-tasks.html index fdefb9137c..22946b655f 100644 --- a/hypha/apply/dashboard/templates/dashboard/includes/my-tasks.html +++ b/hypha/apply/dashboard/templates/dashboard/includes/my-tasks.html @@ -17,7 +17,7 @@

{% trans "My tasks" %}

{% endif %} - {% trans "View" %} + {% trans "View" %} {% endfor %} diff --git a/hypha/apply/review/templates/review/review_detail.html b/hypha/apply/review/templates/review/review_detail.html index 0c84fc7e4f..b1bbdccf64 100644 --- a/hypha/apply/review/templates/review/review_detail.html +++ b/hypha/apply/review/templates/review/review_detail.html @@ -60,7 +60,7 @@
{% trans "Score" %}

* {% trans "Review was not against the latest version" %}

- {% trans "Compare" %} + {% trans "Compare" %} {% comment %} {% endif %} {% endcomment %} diff --git a/hypha/apply/templates/forms/includes/multi_input_field.html b/hypha/apply/templates/forms/includes/multi_input_field.html index 75e4657cba..ccf068a53e 100644 --- a/hypha/apply/templates/forms/includes/multi_input_field.html +++ b/hypha/apply/templates/forms/includes/multi_input_field.html @@ -11,7 +11,7 @@ {% if field.field.multi_input_add_button %} +
diff --git a/hypha/apply/users/templates/users/partials/confirmation_code_sent.html b/hypha/apply/users/templates/users/partials/confirmation_code_sent.html index 8b998aad34..e8f1c43420 100644 --- a/hypha/apply/users/templates/users/partials/confirmation_code_sent.html +++ b/hypha/apply/users/templates/users/partials/confirmation_code_sent.html @@ -33,7 +33,7 @@
+
diff --git a/hypha/apply/users/templates/users/passwordless_login_signup.html b/hypha/apply/users/templates/users/passwordless_login_signup.html index 40c99a60a5..1d0774c893 100644 --- a/hypha/apply/users/templates/users/passwordless_login_signup.html +++ b/hypha/apply/users/templates/users/passwordless_login_signup.html @@ -44,7 +44,7 @@

{% endif %}
- +
diff --git a/hypha/apply/users/views.py b/hypha/apply/users/views.py index 430643ced2..4a93f986d6 100644 --- a/hypha/apply/users/views.py +++ b/hypha/apply/users/views.py @@ -50,7 +50,6 @@ from wagtail.users.views.users import change_user_perm from hypha.core.mail import MarkdownMail -from hypha.home.models import ApplyHomePage from .decorators import require_oauth_whitelist from .forms import ( @@ -94,17 +93,17 @@ class LoginView(TwoFactorLoginView): def get_context_data(self, form, **kwargs): context_data = super(LoginView, self).get_context_data(form, **kwargs) - context_data["is_public_site"] = True context_data["redirect_url"] = get_redirect_url( self.request, self.redirect_field_name ) - if ( - Site.find_for_request(self.request) - == ApplyHomePage.objects.first().get_site() - ): - context_data["is_public_site"] = False return context_data + def post(self, *args, **kwargs): + # Set longer session time if Remember me is checked. + if bool(self.request.POST.get("auth-remember_me", None) == "on"): + self.request.session.set_expiry(settings.SESSION_COOKIE_AGE_LONG) + return super().post(*args, **kwargs) + @method_decorator(login_required, name="dispatch") class AccountView(UpdateView): diff --git a/hypha/public/news/templates/news/news_index.html b/hypha/public/news/templates/news/news_index.html index 1cdeb62207..81dc40ff76 100644 --- a/hypha/public/news/templates/news/news_index.html +++ b/hypha/public/news/templates/news/news_index.html @@ -19,7 +19,7 @@

{{ page.introduction|markdown {% endfor %}

- + {% if news %} diff --git a/hypha/settings/base.py b/hypha/settings/base.py index a74a745d79..044aee86cf 100644 --- a/hypha/settings/base.py +++ b/hypha/settings/base.py @@ -494,8 +494,13 @@ # Sessions # https://docs.djangoproject.com/en/stable/ref/settings/#sessions -# The age of session cookies, in seconds. -SESSION_COOKIE_AGE = env.int("SESSION_COOKIE_AGE", 60 * 60 * 24 * 7 * 2) # 2 weeks +# The default age of session cookies, in seconds. +SESSION_COOKIE_AGE = env.int("SESSION_COOKIE_AGE", 60 * 60 * 12) # 12 hours + +# The age of session cookies when users check "Remember me" etc., in seconds. +SESSION_COOKIE_AGE_LONG = env.int( + "SESSION_COOKIE_AGE_LONG", 60 * 60 * 24 * 7 * 2 +) # 2 weeks # This is used by Wagtail's email notifications for constructing absolute URLs. PRIMARY_HOST = env.str("PRIMARY_HOST", None) diff --git a/hypha/static_src/javascript/submission-form-copy.js b/hypha/static_src/javascript/submission-form-copy.js index 739a2d4d55..5a7f89beea 100644 --- a/hypha/static_src/javascript/submission-form-copy.js +++ b/hypha/static_src/javascript/submission-form-copy.js @@ -95,7 +95,7 @@ var $button = $("