@@ -35,12 +35,26 @@ def __init__(self) -> None:
35
35
app : AuthenticationServer = AuthenticationServer ()
36
36
37
37
# Routing
38
+ @app .post (path = "/api/profile" )
39
+ async def route_api_profile (payload : models .BaseTokenModel ) -> JSONResponse :
40
+ """Fetches a users profile. This method is POST to prevent query strings with account tokens
41
+ from being logged via uvicorn or whatever HTTP server is running at the moment."""
42
+ response : dict | None = app .db .tokens .find_one (filter = {"token" : payload .token .get_secret_value ()})
43
+ if response is None :
44
+ return JSONResponse (
45
+ content = {"code" : 403 , "data" : "Invalid account token." },
46
+ status_code = 403
47
+ )
48
+
49
+ return JSONResponse (content = {"code" : 200 , "data" : {"username" : response ["username" ]}})
50
+
38
51
@app .post (path = "/api/authorize" )
39
52
async def route_api_authorize (payload : models .AuthorizeModel ) -> JSONResponse :
53
+ """Authorizes a new external Nightwatch server with a burner account token."""
40
54
response : dict | None = app .db .users .find_one (filter = {"token" : payload .token .get_secret_value ()})
41
55
if response is None :
42
56
return JSONResponse (
43
- content = {"code " : 403 , "data" : "Invalid account token." },
57
+ content = {"comde " : 403 , "data" : "Invalid account token." },
44
58
status_code = 403
45
59
)
46
60
@@ -57,6 +71,7 @@ async def route_api_authorize(payload: models.AuthorizeModel) -> JSONResponse:
57
71
58
72
@app .post (path = "/api/signup" )
59
73
async def route_api_signup (payload : models .BaseAuthenticationModel ) -> JSONResponse :
74
+ """Creates a new account and returns its token given a basic username and password."""
60
75
response : dict | None = app .db .users .find_one (filter = {"username" : payload .username })
61
76
if response is not None :
62
77
return JSONResponse (
@@ -75,14 +90,14 @@ async def route_api_signup(payload: models.BaseAuthenticationModel) -> JSONRespo
75
90
76
91
@app .post (path = "/api/login" )
77
92
async def route_api_login (payload : models .BaseAuthenticationModel ) -> JSONResponse :
93
+ """Logs in and returns the master token for a given account."""
78
94
response : dict | None = app .db .users .find_one (filter = {"username" : payload .username })
79
95
if response is None :
80
96
return JSONResponse (
81
97
content = {"code" : 404 , "data" : "No account with that username exists." },
82
98
status_code = 404
83
99
)
84
100
85
- # Check password
86
101
try :
87
102
app .hasher .verify (hash = response ["password" ], password = payload .password .get_secret_value ())
88
103
if app .hasher .check_needs_rehash (hash = response ["password" ]):
0 commit comments