From ab10009e4dd493377d18ed3521c3440832e57f07 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Mon, 5 Oct 2020 15:38:34 +0100 Subject: [PATCH] Redirect link included in links for password reset on sign-in page. --- app/main/views/sign_in.py | 10 ++++++---- app/templates/views/signin.html | 2 +- tests/app/main/views/test_sign_in.py | 10 ++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/main/views/sign_in.py b/app/main/views/sign_in.py index ae15fa751..d5b9cd1bb 100644 --- a/app/main/views/sign_in.py +++ b/app/main/views/sign_in.py @@ -24,6 +24,7 @@ def sign_in(): return redirect(url_for('main.show_accounts_or_dashboard')) form = LoginForm() + password_reset_url = url_for('.forgot_password', next=request.args.get('next')) if form.validate_on_submit(): @@ -51,9 +52,9 @@ def sign_in(): # Vague error message for login in case of user not known, locked, inactive or password not verified flash(Markup( ( - "The email address or password you entered is incorrect." - " Forgotten your password?" - ).format(password_reset=url_for('.forgot_password')) + f"The email address or password you entered is incorrect." + f" Forgotten your password?" + ) )) other_device = current_user.logged_in_elsewhere() @@ -61,7 +62,8 @@ def sign_in(): 'views/signin.html', form=form, again=bool(request.args.get('next')), - other_device=other_device + other_device=other_device, + password_reset_url=password_reset_url ) diff --git a/app/templates/views/signin.html b/app/templates/views/signin.html index 374e59f89..c4dd5c609 100644 --- a/app/templates/views/signin.html +++ b/app/templates/views/signin.html @@ -33,7 +33,7 @@ {% call form_wrapper(autocomplete=True) %} {{ form.email_address(param_extensions={"autocomplete": "email"}) }} {{ form.password(param_extensions={"autocomplete": "current-password"}) }} - {{ page_footer("Continue", secondary_link=url_for('.forgot_password'), secondary_link_text="Forgotten your password?") }} + {{ page_footer("Continue", secondary_link=password_reset_url, secondary_link_text="Forgotten your password?") }} {% endcall %} diff --git a/tests/app/main/views/test_sign_in.py b/tests/app/main/views/test_sign_in.py index 671305998..8e0208f20 100644 --- a/tests/app/main/views/test_sign_in.py +++ b/tests/app/main/views/test_sign_in.py @@ -27,6 +27,16 @@ def test_render_sign_in_template_for_new_user( assert 'Sign in again' not in normalize_spaces(page.text) +def test_render_sign_in_template_with_next_link_for_password_reset( + client_request +): + client_request.logout() + page = client_request.get('main.sign_in', _optional_args="?next=blob", _test_page_title=False) + forgot_password_link = page.find('a', class_="govuk-link govuk-link--no-visited-state page-footer-secondary-link") + assert forgot_password_link.text == 'Forgotten your password?' + assert forgot_password_link['href'] == url_for('main.forgot_password') + "?next=blob" + + def test_sign_in_explains_session_timeout(client): response = client.get(url_for('main.sign_in', next='/foo')) assert response.status_code == 200