浏览代码

优化登录时长

hsun 1 年之前
父节点
当前提交
215ed58336
共有 3 个文件被更改,包括 7 次插入5 次删除
  1. 2 2
      controllers/base_auth.go
  2. 3 3
      controllers/user_login.go
  3. 2 0
      utils/constants.go

+ 2 - 2
controllers/base_auth.go

@@ -174,10 +174,10 @@ func (this *BaseAuthController) Prepare() {
 					this.StopRun()
 					return
 				}
-				utils.Rc.Put(loginKey, "1", 30*time.Minute)
+				utils.Rc.Put(loginKey, "1", utils.LoginCacheTime*time.Minute)
 				// 不信任名单也同步更新
 				noTrustLoginKey := fmt.Sprint(utils.CACHE_ACCESS_TOKEN_LOGIN_NO_TRUST, admin.AdminId)
-				utils.Rc.Put(noTrustLoginKey, session.Id, 30*time.Minute)
+				utils.Rc.Put(noTrustLoginKey, session.Id, utils.LoginCacheTime*time.Minute)
 			}
 
 			admin.RoleTypeCode = GetSysUserRoleTypeCode(admin.RoleTypeCode)

+ 3 - 3
controllers/user_login.go

@@ -535,13 +535,13 @@ func (this *UserLoginController) Login() {
 		noTrustLoginId, _ := utils.Rc.RedisString(noTrustLoginKey)
 		if noTrustLoginId != `` { // 如果存在不可信设备,那么将其下架
 			oldNoTrustLoginKey := fmt.Sprint(utils.CACHE_ACCESS_TOKEN_LOGIN, noTrustLoginId)
-			_ = utils.Rc.Put(oldNoTrustLoginKey, "0", 30*time.Minute)
+			_ = utils.Rc.Put(oldNoTrustLoginKey, "0", utils.LoginCacheTime*time.Minute)
 		}
 
 		// 如果当前是不可信设备,那么将其加入到不可信名单
 		loginKey := fmt.Sprint(utils.CACHE_ACCESS_TOKEN_LOGIN, sysSession.Id)
-		_ = utils.Rc.Put(loginKey, "1", 30*time.Minute)
-		_ = utils.Rc.Put(noTrustLoginKey, sysSession.Id, 30*time.Minute)
+		_ = utils.Rc.Put(loginKey, "1", utils.LoginCacheTime*time.Minute)
+		_ = utils.Rc.Put(noTrustLoginKey, sysSession.Id, utils.LoginCacheTime*time.Minute)
 	}
 
 	// 新增登录记录

+ 2 - 0
utils/constants.go

@@ -352,3 +352,5 @@ var (
 	JhGnAppKey = "4c8504c49dd335e99cfd7b6a3a9e2415" //聚合国内AppKey
 	JhGjAppKey = "3326ad2c1047a4cd92ace153e6044ca3" //聚合国内AppKey
 )
+
+const LoginCacheTime = 60 // 登录缓存时长, 分钟