From d80fc4863595fb1eb895a0396d341e502596a4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 1 Sep 2017 17:04:41 +0200 Subject: [PATCH] Redirect properly after login - Use next=xxx URL parameter - Redirect to / when no next=xxx was given and the referrer is /welcome --- cloud/routes.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cloud/routes.py b/cloud/routes.py index 1fccd07..e1ffa00 100644 --- a/cloud/routes.py +++ b/cloud/routes.py @@ -93,7 +93,19 @@ def homepage(): @blueprint.route('/login') def login(): - session['next_after_login'] = '/' + from flask import request + + next_after_login = request.args.get('next') + + # Redirect to /welcome if explicitly given, but not when falling back to the referrer. + if not next_after_login: + url_for_welcome = url_for('cloud.welcome', _external=True) + if request.referrer == url_for_welcome: + next_after_login = '/' + else: + next_after_login = request.referrer + + session['next_after_login'] = next_after_login return redirect(url_for('users.oauth_authorize', provider='blender-id'))