|
@@ -148,6 +148,7 @@ type GinJWTMiddleware struct {
|
|
|
// 保存token的key
|
|
|
SaveNewestToken func(c *gin.Context, userId int64, token string, expire int64) error
|
|
|
GetNewestToken func(c *gin.Context, userId int64) (string, error)
|
|
|
+ SetEnterDeptId func(c *gin.Context, newTToken string,userId int64) error
|
|
|
}
|
|
|
|
|
|
var (
|
|
@@ -166,7 +167,7 @@ var (
|
|
|
// ErrFailedAuthentication indicates authentication failed, could be faulty username or password
|
|
|
//ErrFailedAuthentication = errors.New("incorrect Username or Password")
|
|
|
ErrFailedAuthentication = errors.New("用户名或密码不正确")
|
|
|
- ErrFailedSmsVerifyCode = errors.New("短信验证码错误")
|
|
|
+ ErrFailedSmsVerifyCode = errors.New("短信验证码错误")
|
|
|
|
|
|
ErrAccountDeactivated = errors.New("账号已停用")
|
|
|
|
|
@@ -237,6 +238,7 @@ var (
|
|
|
// DeptIdKey 部门 Old
|
|
|
DeptIdKey = "deptId"
|
|
|
DeptNameKey = "deptName"
|
|
|
+ RandomKey = "randomName"
|
|
|
)
|
|
|
|
|
|
// New for check error with GinJWTMiddleware
|
|
@@ -496,13 +498,16 @@ func (mw *GinJWTMiddleware) LoginHandler(c *gin.Context) {
|
|
|
expire := mw.TimeFunc().Add(mw.Timeout)
|
|
|
|
|
|
// 登录类型 手机登录
|
|
|
- if t,ok := claims["mobile"];ok{
|
|
|
- if t.(bool) {
|
|
|
- expire = mw.TimeFunc().Add(time.Duration(876000) * time.Hour)
|
|
|
-
|
|
|
+ if v, ok := data.(map[string]interface{}); ok {
|
|
|
+ if t, ok2 := v["mobile"].(bool); ok2 {
|
|
|
+ if t {
|
|
|
+ expire = mw.TimeFunc().Add(time.Duration(876000/2) * time.Hour)
|
|
|
+ //mw.Timeout = time.Duration(876000) * time.Hour
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
claims["exp"] = expire.Unix()
|
|
|
claims["orig_iat"] = mw.TimeFunc().Unix()
|
|
|
tokenString, err := mw.signedString(token)
|
|
@@ -589,6 +594,9 @@ func (mw *GinJWTMiddleware) RefreshToken(c *gin.Context) (string, time.Time, err
|
|
|
mw.CookieHTTPOnly,
|
|
|
)
|
|
|
}
|
|
|
+ if mw.SetEnterDeptId != nil {
|
|
|
+ mw.SetEnterDeptId(c,tokenString,int64(claims["identity"].(float64)))
|
|
|
+ }
|
|
|
|
|
|
if claims["single"].(bool) {
|
|
|
_ = mw.SaveNewestToken(c, int64(claims["identity"].(float64)), tokenString, int64(mw.Timeout)/3600)
|