jiangshuai
2024-02-06 d4b62e5dcaf10b85600c13de232bb5173a11d4fc
拦截器
1个文件已添加
3个文件已修改
36 ■■■■ 已修改文件
middleware/reset_pwd.go 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/jwt.go 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
middleware/reset_pwd.go
New file
@@ -0,0 +1,25 @@
package middleware
import (
    "github.com/gin-gonic/gin"
    "wms/pkg/contextx"
    "wms/pkg/ecode"
    "wms/request"
)
func VerifyResetPwd() gin.HandlerFunc {
    return func(c *gin.Context) {
        ctx := new(contextx.Context).SetCtx(c)
        params, ok := c.Get("claims")
        if !ok {
            c.Abort()
            return
        }
        claims := params.(*request.CustomClaims)
        if !claims.ModifiedPwd {
            ctx.Fail(ecode.ResetPwd)
            c.Abort()
            return
        }
    }
}
pkg/ecode/code.go
@@ -18,4 +18,5 @@
    JWTEmpty              = 2013 // JWT为空
    JWTExpire             = 2014 // JWT过期
    JWTParseErr           = 2015 // JWT解析失败
    ResetPwd              = 2036 //账号设置密码
)
request/jwt.go
@@ -13,8 +13,9 @@
}
type BaseClaims struct {
    UserId   string
    Username string
    ParentId string
    UserType constvar.UserType
    UserId      string
    Username    string
    ParentId    string
    UserType    constvar.UserType
    ModifiedPwd bool
}
router/router.go
@@ -21,6 +21,7 @@
    urlPrefix := "/api-wms/v1"
    r.Use(middleware.JWTAuth())
    r.Use(middleware.VerifyResetPwd())
    // 组织管理
    departmentController := new(controllers.DepartmentController)