Refine
This commit is contained in:
22
main.py
22
main.py
@@ -33,8 +33,6 @@ import time
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
from fastapi import FastAPI, APIRouter, Depends, HTTPException, status, Request
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from jose import jwt
|
||||
from passlib.context import CryptContext
|
||||
|
||||
JUNCTION = 0
|
||||
RESERVOIR = 1
|
||||
@@ -87,28 +85,10 @@ def generate_access_token(username: str, password: str) -> str:
|
||||
if username != "tjwater" or password != "tjwater@123":
|
||||
raise ValueError("用户名或密码错误")
|
||||
|
||||
# 安全配置
|
||||
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
|
||||
ALGORITHM = "HS256"
|
||||
TOKEN_EXPIRE = 120 # 分钟
|
||||
|
||||
# 创建密码上下文
|
||||
pwd_ctx = CryptContext(schemes=["bcrypt"])
|
||||
|
||||
# 创建token载荷
|
||||
payload = {
|
||||
"sub": username, # 用户标识
|
||||
"exp": datetime.utcnow() + timedelta(minutes=TOKEN_EXPIRE) # 过期时间
|
||||
}
|
||||
|
||||
# 生成并返回JWT token
|
||||
token = jwt.encode(payload, SECRET_KEY, algorithm=ALGORITHM)
|
||||
access_tokens.append(token)
|
||||
|
||||
token = "567e33c876a2"
|
||||
return token
|
||||
|
||||
|
||||
|
||||
# 将 Query的信息 序列号到 redis/json, 默认不支持datetime,需要自定义
|
||||
# 自定义序列化函数
|
||||
# 序列化处理器
|
||||
|
||||
Reference in New Issue
Block a user