mirror of
https://github.com/norohind/FDEV-CAPI-Handler.git
synced 2025-06-10 04:12:09 +03:00
web: fix /random_token when no users in DB
This commit is contained in:
parent
317dff9e3b
commit
2b134d26f4
10
web.py
10
web.py
@ -95,8 +95,16 @@ class RandomToken:
|
|||||||
# for legacy reasons
|
# for legacy reasons
|
||||||
@falcon.before(check_secret)
|
@falcon.before(check_secret)
|
||||||
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response):
|
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response):
|
||||||
|
resp.content_type = falcon.MEDIA_JSON
|
||||||
import random
|
import random
|
||||||
random_state = random.choice(capi_authorizer.list_all_users())
|
list_users = capi_authorizer.list_all_users()
|
||||||
|
|
||||||
|
if len(list_users) == 0:
|
||||||
|
raise falcon.HTTPNotFound(description='No users in DB')
|
||||||
|
|
||||||
|
random_user = random.choice(list_users)
|
||||||
|
|
||||||
|
resp.text = json.dumps(capi_authorizer.get_token_by_state(random_user['state']))
|
||||||
|
|
||||||
|
|
||||||
application = falcon.App()
|
application = falcon.App()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user