File size: 3,143 Bytes
dcb132a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import flask
import src.functions.config

authBP = flask.Blueprint("auth", __name__)


@authBP.route("/api/v1/auth")
async def authFunction():
    a = flask.request.args.get("a")  # AUTH
    p = flask.request.args.get("p")  # PASSWORD
    u = flask.request.args.get("u")  # USERNAME
    config = src.functions.config.readConfig()

    rules = flask.request.args.get("rules")  # RULES
    if config.get("auth") == False:
        return (
            flask.jsonify(
                {
                    "code": 200,
                    "content": {"ui_config": config.get("ui_config", {})},
                    "message": "Authentication completed successfully.",
                    "success": True,
                }
            ),
            200,
        )
    elif rules == "signup":
        if config.get("signup") == True:
            return (
                flask.jsonify(
                    {
                        "code": 202,
                        "content": True,
                        "message": "Signup is available on this server.",
                        "success": True,
                    }
                ),
                202,
            )
        else:
            return (
                flask.jsonify(
                    {
                        "code": 202,
                        "content": False,
                        "message": "Signup is not available on this server.",
                        "success": True,
                    }
                ),
                202,
            )
    elif any(u == account["username"] for account in config["account_list"]) and any(
        p == account["password"] for account in config["account_list"]
    ):
        account = next(
            (
                i
                for i in config["account_list"]
                if i["username"] == u and i["password"] == p
            ),
            None,
        )
        return (
            flask.jsonify(
                {
                    "code": 200,
                    "content": {"auth": account["auth"], "ui_config": config.get("ui_config", {})},
                    "message": "Authentication was successful.",
                    "success": True,
                }
            ),
            200,
        )
    elif any(a == account["auth"] for account in config["account_list"]):
        account = next((i for i in config["account_list"] if i["auth"] == a), None)
        return (
            flask.jsonify(
                {
                    "code": 200,
                    "content": account,
                    "message": "Authentication was successful.",
                    "success": True,
                }
            ),
            200,
        )
    else:
        return (
            flask.jsonify(
                {
                    "code": 401,
                    "content": None,
                    "message": "The username and/or password provided was incorrect.",
                    "success": False,
                }
            ),
            401,
        )