This commit is contained in:
suyl
2021-07-20 15:13:48 +08:00
parent bca946aadc
commit 2b6966f93d
2 changed files with 8 additions and 5 deletions

View File

@@ -43,7 +43,7 @@ func checkToken(c *gin.Context) (tokenInfo *model.TokenInfo) {
tokenInfo.Token = cookie.Value
}
globals.SugarLogger.Debugf("checkToken token1: %v", tokenInfo.Token)
if token = utils.GetKey(tokenInfo.Token); token == "" {
if token = utils.GetKey(tokenInfo.Token).(string); token == "" {
err = fmt.Errorf("token过期或无效请重新登录")
c.JSON(http.StatusOK, &CallBack{
Desc: err.Error(),
@@ -104,7 +104,7 @@ func callFunc(c *gin.Context, worker func() (retVal interface{}, errCode string,
func captchaVerify(c *gin.Context, code string) bool {
//session := sessions.Default(c)
if captchaId := utils.GetKey(c.ClientIP() + model.SessionKey); captchaId != "" {
if captchaId := utils.GetKey(c.ClientIP() + model.SessionKey).(string); captchaId != "" {
utils.DelKey(c.ClientIP() + model.SessionKey)
if captcha.VerifyString(captchaId, code) {
return true

View File

@@ -34,10 +34,13 @@ func DelKey(key string) error {
return client.Del(key).Err()
}
func GetKey(key string) string {
func GetKey(key string) interface{} {
result, err := client.Get(key).Result()
if err == nil {
return result
var retVal interface{}
if err = utils.UnmarshalUseNumber([]byte(result), &retVal); err == nil {
return retVal
}
}
return ""
return nil
}