Turn on redirects two_factor_email

This is part of the work to make sure user is redirected
to the page they initially were meant to visit after
they sign in.
This commit is contained in:
Pea Tyczynska
2020-10-09 11:41:47 +01:00
parent 5dd010ece8
commit a531c888ba
3 changed files with 27 additions and 7 deletions

View File

@@ -36,6 +36,7 @@ def two_factor_email_interstitial(token):
@main.route('/email-auth/<token>', methods=['POST'])
def two_factor_email(token):
redirect_url = request.args.get('next')
if current_user.is_authenticated:
return redirect_when_logged_in(platform_admin=current_user.platform_admin)
@@ -48,14 +49,14 @@ def two_factor_email(token):
current_app.config['EMAIL_2FA_EXPIRY_SECONDS']
))
except SignatureExpired:
return render_template('views/email-link-invalid.html')
return render_template('views/email-link-invalid.html', redirect_url=redirect_url)
user_id = token_data['user_id']
# checks if code was already used
logged_in, msg = user_api_client.check_verify_code(user_id, token_data['secret_code'], "email")
if not logged_in:
return render_template('views/email-link-invalid.html')
return render_template('views/email-link-invalid.html', redirect_url=redirect_url)
return log_in_user(user_id)

View File

@@ -11,7 +11,11 @@
<div class="govuk-grid-column-two-thirds">
<h1 class="heading-large">The link has expired</h1>
<p class="govuk-body"><a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('main.sign_in') }}">Sign in again</a> to get a new link.</p>
<p class="govuk-body">
<a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('main.sign_in', next=redirect_url) }}">
Sign in again
</a> to get a new link.
</p>
</div>
</div>