Slide 18
Slide 18 text
@self.dora_router.get("/reset")
async def reset_vote_count(request: Request):
try:
token = request.cookies.get("access_token")
if token_str is None:
raise HTTPException(status_code=400, detail="Bad Request")
# 中略
payload = decode(token, SECRET_KEY, algorithms=[ALGORITHM])
github_id: str = payload.get("github_name")
if github_id != "notchman8600":
raise HTTPException(status_code=403, detail="君にその権限はない")
except ExpiredSignatureError:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Access token is expired",
headers={"WWW-Authenticate": "Bearer"},
)
except PyJWTError:
raise HTTPException(status_code=401, detail="Unauthorized")
err = self.dora_controller.reset_count()
if err is not None:
raise HTTPException(status_code=500, detail="Internal Server Error")
return RedirectResponse(url="/vote", status_code=303)