mirror of
https://github.com/simple-login/app.git
synced 2024-11-18 01:40:38 +01:00
7eb44a5947
* Fixes for connect with proton on mobile * Added a test Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
30 lines
902 B
Python
30 lines
902 B
Python
import arrow
|
|
from flask import redirect, url_for, request, flash
|
|
from flask_login import login_user
|
|
|
|
from app.auth.base import auth_bp
|
|
from app.models import ApiToCookieToken
|
|
from app.utils import sanitize_next_url
|
|
|
|
|
|
@auth_bp.route("/api_to_cookie", methods=["GET"])
|
|
def api_to_cookie():
|
|
code = request.args.get("token")
|
|
if not code:
|
|
flash("Missing token", "error")
|
|
return redirect(url_for("auth.login"))
|
|
|
|
token = ApiToCookieToken.get_by(code=code)
|
|
if not token or token.created_at < arrow.now().shift(minutes=-5):
|
|
flash("Missing token", "error")
|
|
return redirect(url_for("auth.login"))
|
|
|
|
user = token.user
|
|
ApiToCookieToken.delete(token.id, commit=True)
|
|
login_user(user)
|
|
|
|
next_url = sanitize_next_url(request.args.get("next"))
|
|
if next_url:
|
|
return redirect(next_url)
|
|
else:
|
|
return redirect(url_for("dashboard.index"))
|