- 新增滑动续签功能:人工触屏触发本地心跳 + 30秒节流刷新JWT,避免作业中令牌过期 - 拆分质量检验权限:过程检/完工检使用不同权限码,细化权限粒度 - 新增操作人用户ID字段:报工、拧紧记录落库时携带可信用户ID,解决身份追溯问题 - 移除编译期默认密钥,启动期校验所有必要密钥非空,防止密钥泄露风险 - 修复WMS附件越权遍历问题:使用UUID文件名替代顺序ID访问附件 - 实现登录态过期数据隔离:仅返回当前操作人的待同步数据,避免身份混淆
48 lines
2.3 KiB
Go
48 lines
2.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"bj_power_mes/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/rest"
|
|
)
|
|
|
|
// RegisterRoutes 注册鉴权 + 系统管理(用户/角色/权限)路由
|
|
func RegisterRoutes(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|
// 免鉴权
|
|
server.AddRoutes([]rest.Route{
|
|
{Method: http.MethodPost, Path: "/login", Handler: LoginHandler(serverCtx)},
|
|
}, rest.WithPrefix("/api/v1"), rest.WithMaxBytes(serverCtx.Config.Upload.MaxMB<<20))
|
|
|
|
// JWT 保护:用户信息 + 用户/角色/权限 管理
|
|
jwtAdmin := []rest.Route{
|
|
{Method: http.MethodGet, Path: "/userinfo", Handler: UserInfoHandler(serverCtx)},
|
|
// /seed 已从对外路由摘除:seed 是运维/初始化工具接口,非业务接口,
|
|
// 仅通过 CLI 子命令 `bj_power_mes.exe seed`(带管理员密码门 adminGate)执行,避免任意登录用户提权。
|
|
{Method: http.MethodPost, Path: "/user/change-password", Handler: ChangePasswordHandler(serverCtx)},
|
|
{Method: http.MethodPost, Path: "/logout", Handler: LogoutHandler(serverCtx)},
|
|
|
|
{Method: http.MethodGet, Path: "/users", Handler: ListUsersHandler(serverCtx)},
|
|
{Method: http.MethodPost, Path: "/users", Handler: CreateUserHandler(serverCtx)},
|
|
{Method: http.MethodPut, Path: "/users", Handler: UpdateUserHandler(serverCtx)},
|
|
{Method: http.MethodDelete, Path: "/users/:id", Handler: DeleteUserHandler(serverCtx)},
|
|
|
|
{Method: http.MethodGet, Path: "/roles", Handler: ListRolesHandler(serverCtx)},
|
|
{Method: http.MethodPost, Path: "/roles", Handler: CreateRoleHandler(serverCtx)},
|
|
{Method: http.MethodPut, Path: "/roles", Handler: UpdateRoleHandler(serverCtx)},
|
|
{Method: http.MethodDelete, Path: "/roles/:id", Handler: DeleteRoleHandler(serverCtx)},
|
|
|
|
{Method: http.MethodGet, Path: "/permissions", Handler: ListPermissionsHandler(serverCtx)},
|
|
{Method: http.MethodPost, Path: "/permissions", Handler: CreatePermissionHandler(serverCtx)},
|
|
{Method: http.MethodPut, Path: "/permissions", Handler: UpdatePermissionHandler(serverCtx)},
|
|
{Method: http.MethodDelete, Path: "/permissions/:id", Handler: DeletePermissionHandler(serverCtx)},
|
|
}
|
|
server.AddRoutes(
|
|
rest.WithMiddlewares([]rest.Middleware{permissionGuard(serverCtx)}, jwtAdmin...),
|
|
rest.WithPrefix("/api/v1"),
|
|
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
|
rest.WithMaxBytes(serverCtx.Config.Upload.MaxMB<<20),
|
|
)
|
|
}
|