| | |
| | | def get_current_user(token: str = Depends(oauth2_scheme)): |
| | | try: |
| | | payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) |
| | | expired_time = payload.get("lex") |
| | | if not expired_time: |
| | | raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="令牌无效或已过期", |
| | | headers={"WWW-Authenticate": "Bearer"}) |
| | | if datetime.strptime(expired_time, "%Y-%m-%d %H:%M:%S") < datetime.now(): |
| | | raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="系统授权已过期!", |
| | | headers={"WWW-Authenticate": "Bearer"}) |
| | | |
| | | username: str = payload.get("sub") |
| | | if username is None: |
| | | raise HTTPException( |