feat:增加权限控制

This commit is contained in:
2025-09-23 15:01:34 +08:00
parent f07b23b825
commit 6977463918
11 changed files with 227 additions and 6 deletions

View File

@@ -0,0 +1,23 @@
from sqlalchemy.orm import Session
from schemas.session import SessionResponse
from config.auth import create_token, create_payload
from middleware.exceptions import AppException
def create(db: Session, username: str, password: str) -> SessionResponse:
# 1. 校验账户是否存在
if username != "admin":
raise AppException(f"该账户{username}不存在")
# 2. 校验密码是否正确
if password != "19940822Cxx":
raise AppException("密码错误")
return SessionResponse(
access_token=create_token(create_payload(username)),
token_type="Bearer"
)