...
|
...
|
@@ -2,6 +2,8 @@ package auth |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"time"
|
|
|
|
...
|
...
|
@@ -50,12 +52,22 @@ func ValidJWTToken(tokenString string) (*MyToken, error) { |
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if claims, ok := token.Claims.(*MyToken); ok && token.Valid {
|
|
|
// 验证成功,返回信息
|
|
|
return claims, nil
|
|
|
claims, ok := token.Claims.(*MyToken)
|
|
|
if !(ok && token.Valid) {
|
|
|
// 验证失败,返回信息
|
|
|
return nil, fmt.Errorf("token Valid fail")
|
|
|
}
|
|
|
// 验证失败
|
|
|
return nil, fmt.Errorf("token Valid fail")
|
|
|
userCompanyData, err := models.GetUserCompanyById(claims.UserCompanyId)
|
|
|
if err != nil {
|
|
|
log.Error("获取userCompany数据失败,id=%d", claims.UserCompanyId)
|
|
|
return nil, fmt.Errorf("token Valid fail")
|
|
|
}
|
|
|
if userCompanyData.UserId != claims.UID {
|
|
|
log.Error("登录信息uid与用户数据不匹配, userCompanyData.UserId=%d, claims.UID=%d", userCompanyData.UserId, claims.UID)
|
|
|
return nil, fmt.Errorf("token Valid fail")
|
|
|
}
|
|
|
// 验证成功
|
|
|
return claims, nil
|
|
|
}
|
|
|
|
|
|
func IsJwtErrorExpired(err error) bool {
|
...
|
...
|
|