diff --git a/canaille/core/endpoints/auth.py b/canaille/core/endpoints/auth.py index 1082f3a9..b222bb4a 100644 --- a/canaille/core/endpoints/auth.py +++ b/canaille/core/endpoints/auth.py @@ -56,7 +56,13 @@ def login(): @bp.route("/password", methods=("GET", "POST")) def password(): + if current_user(): + return redirect( + url_for("core.account.profile_edition", edited_user=current_user()) + ) + if "attempt_login" not in session: + flash(_("Cannot remember the login you attempted to sign in with"), "warning") return redirect(url_for("core.auth.login")) form = PasswordForm(request.form or None) diff --git a/canaille/translations/messages.pot b/canaille/translations/messages.pot index 8443ba72..67bc7856 100644 --- a/canaille/translations/messages.pot +++ b/canaille/translations/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-04-08 14:43+0200\n" +"POT-Creation-Date: 2024-04-09 09:20+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -212,7 +212,7 @@ msgid "" "It should be received within a few minutes." msgstr "" -#: canaille/core/endpoints/account.py:689 canaille/core/endpoints/auth.py:136 +#: canaille/core/endpoints/account.py:689 canaille/core/endpoints/auth.py:142 msgid "Could not send the password initialization email" msgstr "" @@ -239,7 +239,7 @@ msgstr "" msgid "The user %(user)s has been sucessfuly deleted" msgstr "" -#: canaille/core/endpoints/account.py:823 canaille/core/endpoints/auth.py:92 +#: canaille/core/endpoints/account.py:823 canaille/core/endpoints/auth.py:98 #, python-format msgid "Connection successful. Welcome %(user)s" msgstr "" @@ -272,48 +272,52 @@ msgstr "" msgid "Email confirmation on {website_name}" msgstr "" -#: canaille/core/endpoints/auth.py:50 canaille/core/endpoints/auth.py:76 -#: canaille/core/endpoints/auth.py:84 +#: canaille/core/endpoints/auth.py:50 canaille/core/endpoints/auth.py:82 +#: canaille/core/endpoints/auth.py:90 msgid "Login failed, please check your information" msgstr "" -#: canaille/core/endpoints/auth.py:104 +#: canaille/core/endpoints/auth.py:65 +msgid "Cannot remember the login you attempted to sign in with" +msgstr "" + +#: canaille/core/endpoints/auth.py:110 #, python-format msgid "You have been disconnected. See you next time %(user)s" msgstr "" -#: canaille/core/endpoints/auth.py:129 +#: canaille/core/endpoints/auth.py:135 msgid "" "A password initialization link has been sent at your email address. You " "should receive it within a few minutes." msgstr "" -#: canaille/core/endpoints/auth.py:152 +#: canaille/core/endpoints/auth.py:158 msgid "Could not send the password reset link." msgstr "" -#: canaille/core/endpoints/auth.py:156 +#: canaille/core/endpoints/auth.py:162 msgid "" "A password reset link has been sent at your email address. You should " "receive it within a few minutes." msgstr "" -#: canaille/core/endpoints/auth.py:168 +#: canaille/core/endpoints/auth.py:174 #, python-format msgid "" "The user '%(user)s' does not have permissions to update their password. " "We cannot send a password reset email." msgstr "" -#: canaille/core/endpoints/auth.py:184 +#: canaille/core/endpoints/auth.py:190 msgid "We encountered an issue while we sent the password recovery email." msgstr "" -#: canaille/core/endpoints/auth.py:207 +#: canaille/core/endpoints/auth.py:213 msgid "The password reset link that brought you here was invalid." msgstr "" -#: canaille/core/endpoints/auth.py:216 +#: canaille/core/endpoints/auth.py:222 msgid "Your password has been updated successfully" msgstr "" diff --git a/tests/core/test_account.py b/tests/core/test_account.py index 185648e7..79566200 100644 --- a/tests/core/test_account.py +++ b/tests/core/test_account.py @@ -136,6 +136,14 @@ def test_signin_with_alternate_attribute(testclient, user): def test_password_page_without_signin_in_redirects_to_login_page(testclient, user): res = testclient.get("/password", status=302) assert res.location == "/login" + assert res.flashes == [ + ("warning", "Cannot remember the login you attempted to sign in with") + ] + + +def test_password_page_already_logged_in(testclient, logged_user): + res = testclient.get("/password", status=302) + assert res.location == "/profile/user" def test_user_without_password_first_login(testclient, backend, smtpd):