Skip to content

Commit

Permalink
shorten code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Coelho committed May 20, 2024
1 parent 177aff6 commit 9974a61
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions tests/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@

# authentication with randomly-generated passwords
PASSDB: dict[str, str] = {login: app.hash_password(pwd) for login, pwd in secret.PASSES.items()}

app.get_user_pass(lambda login: PASSDB.get(login, None)) # set hook
app.get_user_pass(PASSDB.get)

# admin group authorization
ADMINS: set[str] = {"calvin", "susie"}

@app.group_check("ADMIN")
def user_is_admin(login: str) -> bool:
return login in ADMINS
app.group_check("ADMIN", ADMINS.__contains__)

# login routes
@app.get("/login", authorize="AUTH", auth="basic")
Expand All @@ -30,7 +26,7 @@ def post_login(user: fsa.CurrentUser):
# identity routes
@app.get("/who-am-i", authorize="AUTH")
def get_who_am_i(user: fsa.CurrentUser, lang: fsa.Cookie = None):
return {"user": user, "isadmin": user_is_admin(user), "lang": lang}, 200
return {"user": user, "isadmin": user in ADMINS, "lang": lang}, 200

@app.get("/admin", authorize="ADMIN")
def get_admin(user: fsa.CurrentUser):
Expand Down

0 comments on commit 9974a61

Please sign in to comment.