Merge remote-tracking branch 'button_padding/magic-link'
commit
5a6ad970d8
@ -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)
|
@ -0,0 +1,40 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block body %}
|
||||
<div class="well">
|
||||
<h2 style="margin-top: 0">{{_('Remote Login')}}</h2>
|
||||
<p>
|
||||
{{_('Using your another device, visit')}} <a href="{{verify_url}}">{{verify_url}}</a> {{_('and log in')}}.
|
||||
</p>
|
||||
<p>
|
||||
{{_('Once you do so, you will automatically get logged in on this device.')}}
|
||||
</p>
|
||||
<p>
|
||||
{{_('The link will expire after %s minutes.' % 10)}}
|
||||
</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script type="text/javascript">
|
||||
(function () {
|
||||
// Poll the server to check if the user has authenticated
|
||||
var t = setInterval(function () {
|
||||
$.post('{{url_for("token_verified")}}', { token: '{{token}}' })
|
||||
.done(function(response) {
|
||||
if (response.status === 'success') {
|
||||
// Wait a tick so cookies are updated
|
||||
setTimeout(function () {
|
||||
window.location.href = '{{url_for("index")}}';
|
||||
}, 0);
|
||||
}
|
||||
})
|
||||
.fail(function (xhr) {
|
||||
clearInterval(t);
|
||||
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
alert(response.message);
|
||||
});
|
||||
}, 5000);
|
||||
})()
|
||||
</script>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue