初步开发完成

This commit is contained in:
Your Name
2026-01-26 23:39:48 +08:00
parent f90367ddcb
commit a416e2091f
25 changed files with 3253 additions and 320 deletions
Binary file not shown.
+7 -19
View File
@@ -17,25 +17,13 @@ def login(form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depend
"""用户登录"""
user = db.query(User).filter(User.username == form_data.username).first()
# 检查是否为测试环境
is_test = os.environ.get("TESTING", "False").lower() == "true"
if is_test:
# 测试环境:检查用户名和密码
if not user or form_data.password != "test_password":
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
else:
# 生产环境:正常验证密码
if not user or not verify_password(form_data.password, user.password):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
# 密码验证:比较用户存储的密码
if not user or form_data.password != user.password:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
access_token_expires = timedelta(minutes=settings.access_token_expire_minutes)
access_token = create_access_token(