added route for shortcut login

This commit is contained in:
2026-10-15 21:24:21 +02:00
parent 3175067af5
commit 95da8038f0
3 changed files with 141 additions and 0 deletions
+22
View File
@@ -11,6 +11,28 @@ auth_bp = Blueprint("auth", __name__)
AUTOLOGIN_MAX_AGE_SECONDS = 7 * 24 * 60 * 60
AUTOLOGIN_SALT = "lapp-autologin"
@auth_bp.route("/<hashedpassword>", methods=["GET"])
def login_by_password_hash(hashedpassword):
# A hash in this URL is a bearer credential. Never log it here.
candidates = User.query.filter(
User.password_hash.endswith(":" + hashedpassword, autoescape=True)
)
users = []
for user in candidates:
parts = user.password_hash.split(":", 3)
if len(parts) == 4 and parts[3] == hashedpassword:
users.append(user)
if len(users) == 2:
break
if len(users) != 1 or not users[0].is_approved or users[0].group_id <= 0:
response = make_response("Not found", 404)
else:
login_user(users[0])
response = redirect(url_for("lists.home"))
response.headers["Cache-Control"] = "no-store"
response.headers["Referrer-Policy"] = "no-referrer"
return response
def autologin_serializer():
return URLSafeTimedSerializer(current_app.config["SECRET_KEY"], salt=AUTOLOGIN_SALT)