feat(auth): 实现用户会话数限制功能
Build docker and publish / build (20.15.1) (push) Successful in 7m32s

添加用户会话数限制功能,当超过最大会话数时自动移除最旧的会话
- 在config中添加UserSessionsKeyPrefix常量
- 在JwtAuth配置中新增MaxSessionsPerUser字段
- 在ServiceContext中实现EnforceUserSessionLimit方法
- 在所有登录逻辑中调用会话限制检查
This commit is contained in:
2025-11-26 17:52:12 -08:00
parent 4ad384b01a
commit 1d5d361ae8
8 changed files with 167 additions and 29 deletions
+3
View File
@@ -42,6 +42,9 @@ const SessionIdKey = "auth:session_id"
// DeviceCacheKeyKey cache session key
const DeviceCacheKeyKey = "auth:device_identifier"
// UserSessionsKeyPrefix per-user sessions zset key prefix
const UserSessionsKeyPrefix = "auth:user_sessions:"
// GlobalConfigKey Global Config Key
const GlobalConfigKey = "system:global_config"
+3 -2
View File
@@ -42,8 +42,9 @@ type RedisConfig struct {
}
type JwtAuth struct {
AccessSecret string `yaml:"AccessSecret"`
AccessExpire int64 `yaml:"AccessExpire" default:"604800"`
AccessSecret string `yaml:"AccessSecret"`
AccessExpire int64 `yaml:"AccessExpire" default:"604800"`
MaxSessionsPerUser int64 `yaml:"MaxSessionsPerUser" default:"3"`
}
type Verify struct {