Allow anonymous creation properly
All checks were successful
Build and Publish / build_and_publish (push) Successful in 1m6s

This commit is contained in:
Nexus 2024-07-25 23:54:07 +01:00
parent 7eee976692
commit 918c797df4
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -66,9 +66,11 @@ async def lifespan(_app: FastAPI):
yield yield
async def has_account(req: Request, credentials: HTTPBasicCredentials = Depends(HTTPBasic())) -> db.Account: async def has_account(req: Request, credentials: HTTPBasicCredentials = Depends(HTTPBasic())) -> db.Account | None:
account = await db.Account.get_or_none(username=credentials.username) account = await db.Account.get_or_none(username=credentials.username)
if account is None: if account is None:
if os.getenv("ALLOW_ANONYMOUS", "true") == "true":
return
raise HTTPException(status_code=401, detail="Invalid credentials", headers={"WWW-Authenticate": "Basic"}) raise HTTPException(status_code=401, detail="Invalid credentials", headers={"WWW-Authenticate": "Basic"})
ph = PasswordHasher() ph = PasswordHasher()
try: try: