20 lines
698 B
Python
20 lines
698 B
Python
import hmac
|
|
|
|
from fastapi import HTTPException, Request, status
|
|
|
|
|
|
def password_matches(submitted: str, configured: str) -> bool:
|
|
return hmac.compare_digest(submitted.encode("utf-8"), configured.encode("utf-8"))
|
|
|
|
|
|
def require_admin(request: Request) -> None:
|
|
if request.session.get("admin_authenticated") is not True:
|
|
raise HTTPException(status_code=status.HTTP_303_SEE_OTHER, headers={"Location": "/login"})
|
|
|
|
|
|
def require_self_service(request: Request) -> int:
|
|
user_id = request.session.get("self_service_user_id")
|
|
if not isinstance(user_id, int):
|
|
raise HTTPException(status_code=status.HTTP_303_SEE_OTHER, headers={"Location": "/account-login"})
|
|
return user_id
|