优化鉴权

This commit is contained in:
xh
2025-09-19 03:33:02 +08:00
parent 1c1d27681e
commit 5bc7d9dffd
20 changed files with 182 additions and 261 deletions
@@ -20,23 +20,25 @@ import (
func AdminRoute(rg *gin.RouterGroup) {
handle := AdminHandler{}
notAuth := rg.Group("/system", middleware.LoginAuth())
notAuth.GET("/admin/self", handle.Self)
notAuth.POST("/admin/upInfo", middleware.RecordLog("管理员更新"), handle.UpInfo)
rg = rg.Group("/system", middleware.TokenAuth())
auth := rg.Group("/system", middleware.TokenAuth())
rg.GET("/admin/self", handle.Self)
rg.GET("/admin/list", handle.List)
rg.GET("/admin/listAll", handle.ListAll)
rg.GET("/admin/ListByDeptId", handle.ListByDeptId)
rg.GET("/admin/detail", handle.Detail)
rg.POST("/admin/add", middleware.RecordLog("管理员新增"), handle.Add)
rg.POST("/admin/edit", middleware.RecordLog("管理员编辑"), handle.Edit)
rg.POST("/admin/upInfo", middleware.RecordLog("管理员更新"), handle.UpInfo)
rg.POST("/admin/del", middleware.RecordLog("管理员删除"), handle.Del)
rg.POST("/admin/disable", middleware.RecordLog("管理员状态切换"), handle.Disable)
auth.GET("/admin/list", handle.List)
auth.GET("/admin/listAll", handle.ListAll)
auth.GET("/admin/ListByDeptId", handle.ListByDeptId)
auth.GET("/admin/detail", handle.Detail)
auth.POST("/admin/add", middleware.RecordLog("管理员新增"), handle.Add)
auth.POST("/admin/edit", middleware.RecordLog("管理员编辑"), handle.Edit)
rg.GET("/admin/ExportFile", middleware.RecordLog("管理员导出"), handle.ExportFile)
auth.POST("/admin/del", middleware.RecordLog("管理员删除"), handle.Del)
auth.POST("/admin/disable", middleware.RecordLog("管理员状态切换"), handle.Disable)
rg.POST("/admin/ImportFile", handle.ImportFile)
auth.GET("/admin/ExportFile", middleware.RecordLog("管理员导出"), handle.ExportFile)
auth.POST("/admin/ImportFile", handle.ImportFile)
}
@@ -182,7 +184,7 @@ func (ah AdminHandler) Disable(c *gin.Context) {
// @Router /system/admin/ListByDeptId/{deptId} [get]
func (ah AdminHandler) ListByDeptId(c *gin.Context) {
deptIdStr, bool := c.GetQuery("deptId")
if bool == false {
if !bool {
response.FailWithMsg(c, response.Failed, "deptId不能为空")
return
}
@@ -19,10 +19,13 @@ func DeptRoute(rg *gin.RouterGroup) {
// authSrv := system.NewSystemAuthMenuService(db, permSrv)
handle := deptHandler{}
notAuth := rg.Group("/system", middleware.LoginAuth())
// notAuth.GET("/dept/all", handle.All)
notAuth.GET("/dept/list", handle.List)
rg = rg.Group("/system", middleware.TokenAuth())
rg.GET("/dept/all", handle.All)
rg.GET("/dept/list", handle.List)
// rg.GET("/dept/list", handle.List)
rg.GET("/dept/detail", handle.Detail)
rg.POST("/dept/add", handle.Add)
rg.POST("/dept/edit", handle.Edit)
@@ -6,7 +6,6 @@ import (
"x_admin/app/service/commonService"
"x_admin/app/service/systemService"
"x_admin/core/response"
"x_admin/middleware"
"x_admin/util"
"github.com/gin-gonic/gin"
@@ -16,7 +15,7 @@ func LoginRoute(rg *gin.RouterGroup) {
handle := loginHandler{}
rg = rg.Group("/system", middleware.TokenAuth())
rg = rg.Group("/system")
rg.POST("/login", handle.login)
rg.POST("/logout", handle.logout)
}
@@ -14,9 +14,11 @@ import (
func MenuRoute(rg *gin.RouterGroup) {
handle := menuHandler{}
notAuth := rg.Group("/system", middleware.LoginAuth())
notAuth.GET("/menu/route", handle.route)
rg = rg.Group("/system", middleware.TokenAuth())
rg.GET("/menu/route", handle.route)
// rg.GET("/menu/route", handle.route)
rg.GET("/menu/list", handle.List)
rg.GET("/menu/detail", handle.Detail)
rg.POST("/menu/add", handle.Add)
@@ -13,9 +13,11 @@ import (
func PostRoute(rg *gin.RouterGroup) {
handle := postHandler{}
notAuth := rg.Group("/system", middleware.LoginAuth())
notAuth.GET("/post/all", handle.All)
rg = rg.Group("/system", middleware.TokenAuth())
rg.GET("/post/all", handle.All)
// rg.GET("/post/all", handle.All)
rg.GET("/post/list", handle.List)
rg.GET("/post/detail", handle.Detail)
rg.POST("/post/add", handle.Add)
@@ -14,9 +14,11 @@ import (
func RoleRoute(rg *gin.RouterGroup) {
handle := RoleHandler{}
notAuth := rg.Group("/system", middleware.LoginAuth())
notAuth.GET("/role/all", handle.All)
rg = rg.Group("/system", middleware.TokenAuth())
rg.GET("/role/all", handle.All)
// rg.GET("/role/all", handle.All)
rg.GET("/role/list", middleware.RecordLog("角色列表"), handle.List)
rg.GET("/role/detail", middleware.RecordLog("角色详情"), handle.Detail)
rg.POST("/role/add", middleware.RecordLog("角色新增"), handle.Add)