diff --git a/cps/redirect.py b/cps/redirect.py new file mode 100644 index 00000000..fa3fa5c7 --- /dev/null +++ b/cps/redirect.py @@ -0,0 +1,25 @@ +# http://flask.pocoo.org/snippets/62/ + +from urlparse import urlparse, urljoin +from flask import request, url_for, redirect + + +def is_safe_url(target): + ref_url = urlparse(request.host_url) + test_url = urlparse(urljoin(request.host_url, target)) + return test_url.scheme in ('http', 'https') and ref_url.netloc == test_url.netloc + + +def get_redirect_target(): + for target in request.values.get('next'), request.referrer: + if not target: + continue + if is_safe_url(target): + return target + + +def redirect_back(endpoint, **values): + target = request.form['next'] + if not target or not is_safe_url(target): + target = url_for(endpoint, **values) + return redirect(target) diff --git a/cps/templates/admin.html b/cps/templates/admin.html index 18d99ab8..96d2ceb8 100644 --- a/cps/templates/admin.html +++ b/cps/templates/admin.html @@ -64,6 +64,7 @@
+ {{_('Using your another device, visit')}} {{verify_url}} {{_('and log in')}}. +
++ {{_('Once you do so, you will automatically get logged in on this device.')}} +
++ {{_('The link will expire after %s minutes.' % 10)}} +
+