security: 补全剩余端点鉴权 + 移除硬编码管理员后门
1. 鉴权补全 - orders.py: create_order 补全 Depends(get_current_user) - print.py: print_execute 和 update_printer_config 补全鉴权 - records.py: update_record 和 delete_record 补全鉴权 2. 安全加固 - auth_service.py: 移除硬编码超级管理员(IRIS/123321)后门 - 所有用户统一通过MOM sys_user scrypt密码验证登录
This commit is contained in:
@ -23,21 +23,7 @@ def login(username: str, password: str) -> LoginResponse:
|
||||
"""登录 — 签发双 Token(Access + Refresh)"""
|
||||
db = MomSessionLocal()
|
||||
try:
|
||||
# 1. 超级管理员硬编码(和 MOM 系统一致)
|
||||
if username == "IRIS" and password == "123321":
|
||||
token_data = {"sub": "0", "role": "SUPER_ADMIN", "username": "IRIS", "display_name": "超级管理员"}
|
||||
return LoginResponse(
|
||||
access_token=create_access_token(data=token_data),
|
||||
refresh_token=create_refresh_token(data=token_data),
|
||||
user=UserResponse(
|
||||
id="0",
|
||||
username="IRIS",
|
||||
display_name="超级管理员",
|
||||
role="SUPER_ADMIN",
|
||||
),
|
||||
)
|
||||
|
||||
# 2. 普通用户:LIKE '%/username' 模糊匹配 MOM sys_user 表
|
||||
# 1. 普通用户:LIKE '%/username' 模糊匹配 MOM sys_user 表
|
||||
from sqlalchemy import text
|
||||
result = db.execute(
|
||||
text(
|
||||
@ -57,14 +43,14 @@ def login(username: str, password: str) -> LoginResponse:
|
||||
|
||||
user_id, full_username, department, role, password_hash = row
|
||||
|
||||
# 3. Werkzeug scrypt 密码验证
|
||||
# 2. Werkzeug scrypt 密码验证
|
||||
if not check_password_hash(password_hash, password):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="用户名或密码错误",
|
||||
)
|
||||
|
||||
# 4. 解析 display_name("张三/zhangsan01" → "张三")
|
||||
# 3. 解析 display_name("张三/zhangsan01" → "张三")
|
||||
display_name = full_username.split("/")[0] if "/" in full_username else full_username
|
||||
|
||||
token_data = {
|
||||
|
||||
Reference in New Issue
Block a user