feat: multi-login(disable) fixed
This commit is contained in:
@ -23,6 +23,7 @@ type userController interface {
|
||||
GetUserByToken(ctx context.Context, token string) (*model.User, error)
|
||||
CacheUser(ctx context.Context, user *model.User) error
|
||||
CacheToken(ctx context.Context, token string, user *model.User) error
|
||||
RmToken(ctx context.Context, token string) error
|
||||
RmUserCache(ctx context.Context, id uint64) error
|
||||
DeleteUser(ctx context.Context, id uint64) error
|
||||
}
|
||||
@ -118,6 +119,17 @@ func (u uc) CacheToken(ctx context.Context, token string, user *model.User) erro
|
||||
key := fmt.Sprintf("%s:user:token:%s", opt.CachePrefix, strs[2])
|
||||
return cache.Client.SetEx(tool.Timeout(3), key, user.Id, opt.TokenTimeout)
|
||||
}
|
||||
|
||||
func (u uc) RmToken(ctx context.Context, token string) error {
|
||||
strs := strings.Split(token, ".")
|
||||
if len(strs) != 3 {
|
||||
return fmt.Errorf("controller.CacheToken: jwt token invalid")
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%s:user:token:%s", opt.CachePrefix, strs[2])
|
||||
return cache.Client.Del(tool.Timeout(3), key)
|
||||
}
|
||||
|
||||
func (u uc) RmUserCache(ctx context.Context, id uint64) error {
|
||||
key := fmt.Sprintf("%s:user:id:%d", opt.CachePrefix, id)
|
||||
return cache.Client.Del(tool.Timeout(3), key)
|
||||
|
Reference in New Issue
Block a user