working auth
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 1m14s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 1m14s
This commit is contained in:
parent
afca94af6c
commit
1603b7fe3a
@ -1,13 +1,15 @@
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from flask import request, jsonify, Blueprint
|
from flask import request, jsonify, Blueprint, make_response
|
||||||
from ktvmanager.lib.get_users import get_users
|
from ktvmanager.lib.get_users import get_users
|
||||||
|
|
||||||
auth_blueprint = Blueprint("auth", __name__)
|
auth_blueprint = Blueprint("auth", __name__)
|
||||||
|
|
||||||
def check_auth(username, password):
|
def check_auth(username, password):
|
||||||
users = get_users()
|
users = get_users()
|
||||||
stored_password = users.get(username)
|
for user in users:
|
||||||
return stored_password == password
|
if user['userName'] == username and user['password'] == password:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def requires_basic_auth(f):
|
def requires_basic_auth(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
@ -20,9 +22,17 @@ def requires_basic_auth(f):
|
|||||||
|
|
||||||
def check_login(username, password):
|
def check_login(username, password):
|
||||||
users = get_users()
|
users = get_users()
|
||||||
try:
|
for user in users:
|
||||||
user_password = users[username]
|
if user['userName'] == username and user['password'] == password:
|
||||||
assert user_password == password
|
response = make_response(jsonify({"auth": "Success"}))
|
||||||
return jsonify({"auth": "Success"})
|
user_id = str(user.get('id'))
|
||||||
except KeyError:
|
if user_id:
|
||||||
return jsonify({"auth": "Fail"})
|
response.set_cookie(
|
||||||
|
'user',
|
||||||
|
user_id,
|
||||||
|
domain='tv-ui.k-world.me.uk',
|
||||||
|
path='/',
|
||||||
|
samesite=None
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
return jsonify({"auth": "Fail"})
|
@ -1,7 +1,10 @@
|
|||||||
from ktvmanager.lib.database import _execute_query
|
from ktvmanager.lib.database import _execute_query
|
||||||
|
|
||||||
def get_users():
|
def get_users():
|
||||||
query = "SELECT userName, password FROM users"
|
query = "SELECT id, userName, password FROM users"
|
||||||
results = _execute_query(query)
|
results = _execute_query(query)
|
||||||
users = {user['userName']: user['password'] for user in results}
|
users = [
|
||||||
|
{'id': user['id'], 'userName': user['userName'], 'password': user['password']}
|
||||||
|
for user in results
|
||||||
|
]
|
||||||
return users
|
return users
|
Loading…
x
Reference in New Issue
Block a user