feat: add local admin authentication
This commit is contained in:
12
app/auth/admin.py
Normal file
12
app/auth/admin.py
Normal file
@@ -0,0 +1,12 @@
|
||||
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"})
|
||||
Reference in New Issue
Block a user