Block suspended users from wiki session auth and login

This commit is contained in:
brutsalvadi
2026-05-08 10:45:14 +02:00
parent 05a4d94459
commit c217674472
+7 -2
View File
@@ -191,6 +191,7 @@ class User:
is_admin: bool is_admin: bool
wiki_access: bool wiki_access: bool
activity_access: bool activity_access: bool
suspended: bool = False
@contextmanager @contextmanager
@@ -213,7 +214,7 @@ def _get_session_user(token: str) -> Optional[User]:
with _db() as con: with _db() as con:
row = con.execute( row = con.execute(
"SELECT s.handle, s.expires_at, u.display_name, u.is_admin, " "SELECT s.handle, s.expires_at, u.display_name, u.is_admin, "
"u.wiki_access, u.activity_access " "u.wiki_access, u.activity_access, u.suspended "
"FROM sessions s JOIN users u ON s.handle = u.handle " "FROM sessions s JOIN users u ON s.handle = u.handle "
"WHERE s.token = ?", "WHERE s.token = ?",
(token,), (token,),
@@ -228,6 +229,8 @@ def _get_session_user(token: str) -> Optional[User]:
return None return None
if not row["wiki_access"]: if not row["wiki_access"]:
return None return None
if row["suspended"]:
return None
return User( return User(
handle=row["handle"], handle=row["handle"],
display_name=row["display_name"], display_name=row["display_name"],
@@ -306,7 +309,7 @@ async def login(body: LoginBody) -> JSONResponse:
with _db() as con: with _db() as con:
row = con.execute( row = con.execute(
"SELECT handle, display_name, password_hash, is_admin, " "SELECT handle, display_name, password_hash, is_admin, "
"wiki_access, activity_access FROM users WHERE handle = ?", "wiki_access, activity_access, suspended FROM users WHERE handle = ?",
(body.handle.strip().lower(),), (body.handle.strip().lower(),),
).fetchone() ).fetchone()
except HTTPException: except HTTPException:
@@ -315,6 +318,8 @@ async def login(body: LoginBody) -> JSONResponse:
raise HTTPException(401, "Credenziali non valide") raise HTTPException(401, "Credenziali non valide")
if not row["wiki_access"]: if not row["wiki_access"]:
raise HTTPException(403, "Accesso al wiki non autorizzato") raise HTTPException(403, "Accesso al wiki non autorizzato")
if row["suspended"]:
raise HTTPException(403, "Account sospeso")
token = secrets.token_hex(32) token = secrets.token_hex(32)
expires = int(time.time()) + _SESSION_TTL expires = int(time.time()) + _SESSION_TTL