Redirect link included in links for password reset

on sign-in page.
This commit is contained in:
Pea Tyczynska
2020-10-05 15:38:34 +01:00
parent 1b310a0f8a
commit ab10009e4d
3 changed files with 17 additions and 5 deletions

View File

@@ -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."
" <a href={password_reset}>Forgotten your password?</a>"
).format(password_reset=url_for('.forgot_password'))
f"The email address or password you entered is incorrect."
f" <a href={password_reset_url}>Forgotten your password?</a>"
)
))
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
)

View File

@@ -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 %}
</div>
</div>

View File

@@ -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