fix login
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
1c3918354c
commit
afca94af6c
@ -15,5 +15,14 @@ def requires_basic_auth(f):
|
|||||||
auth = request.authorization
|
auth = request.authorization
|
||||||
if not auth or not check_auth(auth.username, auth.password):
|
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 jsonify({"message": "Could not verify"}), 401, {'WWW-Authenticate': 'Basic realm="Login Required"'}
|
||||||
return f(auth.username, *args, **kwargs)
|
return f(auth.username,auth.password, *args, **kwargs)
|
||||||
return decorated
|
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"})
|
@ -1,13 +1,13 @@
|
|||||||
from flask import Blueprint, jsonify
|
from flask import Blueprint, jsonify
|
||||||
from ktvmanager.lib.database import get_user_accounts, get_stream_names, single_check, add_account, delete_account, get_user_id_from_username
|
from ktvmanager.lib.database import get_user_accounts, get_stream_names, single_check, add_account, delete_account, get_user_id_from_username
|
||||||
from ktvmanager.lib.get_urls import get_latest_urls_from_dns
|
from ktvmanager.lib.get_urls import get_latest_urls_from_dns
|
||||||
from ktvmanager.lib.auth import requires_basic_auth
|
from ktvmanager.lib.auth import requires_basic_auth, check_login
|
||||||
|
|
||||||
api_blueprint = Blueprint("api", __name__)
|
api_blueprint = Blueprint("api", __name__)
|
||||||
|
|
||||||
@api_blueprint.route("/getUserAccounts")
|
@api_blueprint.route("/getUserAccounts")
|
||||||
@requires_basic_auth
|
@requires_basic_auth
|
||||||
def get_user_accounts_route(username):
|
def get_user_accounts_route(username, password):
|
||||||
user_id = get_user_id_from_username(username)
|
user_id = get_user_id_from_username(username)
|
||||||
if user_id:
|
if user_id:
|
||||||
return get_user_accounts(user_id)
|
return get_user_accounts(user_id)
|
||||||
@ -15,27 +15,32 @@ def get_user_accounts_route(username):
|
|||||||
|
|
||||||
@api_blueprint.route("/getStreamNames")
|
@api_blueprint.route("/getStreamNames")
|
||||||
@requires_basic_auth
|
@requires_basic_auth
|
||||||
def get_stream_names_route(username):
|
def get_stream_names_route(username, password):
|
||||||
return get_stream_names()
|
return get_stream_names()
|
||||||
|
|
||||||
@api_blueprint.route("/getUserAccounts/streams")
|
@api_blueprint.route("/getUserAccounts/streams")
|
||||||
@requires_basic_auth
|
@requires_basic_auth
|
||||||
def get_user_accounts_streams_route(username):
|
def get_user_accounts_streams_route(username, password):
|
||||||
return jsonify(get_latest_urls_from_dns())
|
return jsonify(get_latest_urls_from_dns())
|
||||||
|
|
||||||
@api_blueprint.route("/singleCheck", methods=["POST"])
|
@api_blueprint.route("/singleCheck", methods=["POST"])
|
||||||
@requires_basic_auth
|
@requires_basic_auth
|
||||||
def single_check_route(username):
|
def single_check_route(username, password):
|
||||||
return single_check()
|
return single_check()
|
||||||
|
|
||||||
@api_blueprint.route("/addAccount", methods=["POST"])
|
@api_blueprint.route("/addAccount", methods=["POST"])
|
||||||
@requires_basic_auth
|
@requires_basic_auth
|
||||||
def add_account_route(username):
|
def add_account_route(username, password):
|
||||||
user_id = get_user_id_from_username(username)
|
user_id = get_user_id_from_username(username)
|
||||||
return add_account(user_id)
|
return add_account(user_id)
|
||||||
|
|
||||||
@api_blueprint.route("/deleteAccount", methods=["POST"])
|
@api_blueprint.route("/deleteAccount", methods=["POST"])
|
||||||
@requires_basic_auth
|
@requires_basic_auth
|
||||||
def delete_account_route(username):
|
def delete_account_route(username, password):
|
||||||
user_id = get_user_id_from_username(username)
|
user_id = get_user_id_from_username(username)
|
||||||
return delete_account(user_id)
|
return delete_account(user_id)
|
||||||
|
|
||||||
|
@api_blueprint.route("/Login")
|
||||||
|
@requires_basic_auth
|
||||||
|
def login_route(username, password):
|
||||||
|
return check_login(username, password)
|
Loading…
x
Reference in New Issue
Block a user