diff --git a/go.mod b/go.mod index 1098d51..549522e 100644 --- a/go.mod +++ b/go.mod @@ -6,5 +6,5 @@ require ( github.com/gogf/gf/v2 v2.0.0-rc3 github.com/mojocn/base64Captcha v1.3.5 github.com/mssola/user_agent v0.5.3 - github.com/tiger1103/gfast-token v0.0.3 + github.com/tiger1103/gfast-token v0.0.4 ) diff --git a/go.sum b/go.sum index eaf82e2..3cc52c0 100644 --- a/go.sum +++ b/go.sum @@ -77,10 +77,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tiger1103/gfast-token v0.0.2 h1:z2WfVAQV4ocKJeAL90pMVW2ryHVv2pijFG1GZffQ/EI= -github.com/tiger1103/gfast-token v0.0.2/go.mod h1:RnVRqmWD3h4qfTU1vJNXNhQjh2L5ht1vxLnjwShwGuY= github.com/tiger1103/gfast-token v0.0.3 h1:uXZMeNXSb5j/GNLHAgkhwzhG/1M3eL3Ho0RNfl5LUpw= github.com/tiger1103/gfast-token v0.0.3/go.mod h1:RnVRqmWD3h4qfTU1vJNXNhQjh2L5ht1vxLnjwShwGuY= +github.com/tiger1103/gfast-token v0.0.4 h1:h59pbFd/VyORNunsDdzIdqJkZIHYHsYCzdmPbcqGkZs= +github.com/tiger1103/gfast-token v0.0.4/go.mod h1:RnVRqmWD3h4qfTU1vJNXNhQjh2L5ht1vxLnjwShwGuY= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= diff --git a/internal/app/common/service/token.go b/internal/app/common/service/token.go index 97c8c6b..247f417 100644 --- a/internal/app/common/service/token.go +++ b/internal/app/common/service/token.go @@ -29,23 +29,19 @@ var gT = gfTokenImpl{ } func GfToken(options *model.TokenOptions) IGfToken { + var fun gftoken.OptionFunc if options.CacheModel == model.CacheModelRedis { - gT.GfToken = gftoken.NewGfToken( - gftoken.WithCacheKey(options.CacheKey), - gftoken.WithTimeout(options.Timeout), - gftoken.WithMaxRefresh(options.MaxRefresh), - gftoken.WithMultiLogin(options.MultiLogin), - gftoken.WithExcludePaths(options.ExcludePaths), - gftoken.WithGRedis(), - ) + fun = gftoken.WithGRedis() } else { - gT.GfToken = gftoken.NewGfToken( - gftoken.WithCacheKey(options.CacheKey), - gftoken.WithTimeout(options.Timeout), - gftoken.WithMaxRefresh(options.MaxRefresh), - gftoken.WithMultiLogin(options.MultiLogin), - gftoken.WithExcludePaths(options.ExcludePaths), - ) + fun = gftoken.WithGCache() } + gT.GfToken = gftoken.NewGfToken( + gftoken.WithCacheKey(options.CacheKey), + gftoken.WithTimeout(options.Timeout), + gftoken.WithMaxRefresh(options.MaxRefresh), + gftoken.WithMultiLogin(options.MultiLogin), + gftoken.WithExcludePaths(options.ExcludePaths), + fun, + ) return IGfToken(&gT) } diff --git a/internal/app/system/controller/user.go b/internal/app/system/controller/user.go index 6b21916..f37a131 100644 --- a/internal/app/system/controller/user.go +++ b/internal/app/system/controller/user.go @@ -4,6 +4,7 @@ import ( "context" "github.com/gogf/gf/v2/crypto/gmd5" "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/genv" "github.com/gogf/gf/v2/util/gconv" "github.com/tiger1103/gfast/v3/apiv1/system" @@ -62,11 +63,11 @@ func (c *UserController) Login(ctx context.Context, req *system.UserLoginReq) (r Msg: "登录成功", Module: "系统后台", }) - token, err = service.GfToken(ctx).GenerateToken( - ctx, - gconv.String(user.Id)+"-"+gmd5.MustEncryptString(user.UserName)+gmd5.MustEncryptString(user.UserPassword), - user, - ) + key := gconv.String(user.Id) + "-" + gmd5.MustEncryptString(user.UserName) + gmd5.MustEncryptString(user.UserPassword) + if g.Cfg().MustGet(ctx, "gfToken.multiLogin").Bool() { + key = gconv.String(user.Id) + "-" + gmd5.MustEncryptString(user.UserName) + gmd5.MustEncryptString(user.UserPassword+ip+userAgent) + } + token, err = service.GfToken(ctx).GenerateToken(ctx, key, user) if err != nil { return } diff --git a/manifest/config/config.yaml b/manifest/config/config.yaml index a02666e..70639be 100644 --- a/manifest/config/config.yaml +++ b/manifest/config/config.yaml @@ -47,6 +47,17 @@ gfToken: encryptKey: "49c54195e750b04e74a8429b17896586" cacheModel: "redis" +# Redis 配置示例 +redis: + # 单实例配置示例1 + default: + address: 127.0.0.1:6379 + db: 1 + idleTimeout: 600 + maxActive: 100 + + + # CLI. gfcli: gen: