Karl 1603b7fe3a
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 1m14s
working auth
2025-07-15 09:54:01 +01:00

38 lines
1.3 KiB
Python

from functools import wraps
from flask import request, jsonify, Blueprint, make_response
from ktvmanager.lib.get_users import get_users
auth_blueprint = Blueprint("auth", __name__)
def check_auth(username, password):
users = get_users()
for user in users:
if user['userName'] == username and user['password'] == password:
return True
return False
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()
for user in users:
if user['userName'] == username and user['password'] == password:
response = make_response(jsonify({"auth": "Success"}))
user_id = str(user.get('id'))
if user_id:
response.set_cookie(
'user',
user_id,
domain='tv-ui.k-world.me.uk',
path='/',
samesite=None
)
return response
return jsonify({"auth": "Fail"})