Karl afca94af6c
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 1m14s
fix login
2025-07-15 09:28:47 +01:00

28 lines
954 B
Python

from functools import wraps
from flask import request, jsonify, Blueprint
from ktvmanager.lib.get_users import get_users
auth_blueprint = Blueprint("auth", __name__)
def check_auth(username, password):
users = get_users()
stored_password = users.get(username)
return stored_password == password
def requires_basic_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return jsonify({"message": "Could not verify"}), 401, {'WWW-Authenticate': 'Basic realm="Login Required"'}
return f(auth.username,auth.password, *args, **kwargs)
return decorated
def check_login(username, password):
users = get_users()
try:
user_password = users[username]
assert user_password == password
return jsonify({"auth": "Success"})
except KeyError:
return jsonify({"auth": "Fail"})