admin loginitems, longinkickedout
This commit is contained in:
@@ -49,12 +49,12 @@ func (l *LoginItemsLogic) LoginItems(in *admin.AdminEmptyRequest) (*admin.Respon
|
||||
err = jsoniter.Unmarshal([]byte(json), &items)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.out(utils.Fail, "解析登录信息失败")
|
||||
return l.fail(utils.ErrorJsonDataError)
|
||||
}
|
||||
err = jsoniter.Unmarshal(items.Info, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.out(utils.Fail, "解析登录信息失败")
|
||||
return l.fail(utils.ErrorJsonDataError)
|
||||
}
|
||||
infos = append(infos, dao.JwtInfo{
|
||||
Id: info.Id,
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/validator"
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"admin/admin"
|
||||
"admin/internal/svc"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/redis"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type LoginKickedOutLogic struct {
|
||||
@@ -25,7 +30,40 @@ func NewLoginKickedOutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Lo
|
||||
}
|
||||
|
||||
func (l *LoginKickedOutLogic) LoginKickedOut(in *admin.LoginKickedOutRequest) (*admin.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var v validator.LoginKickedOutValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
return &admin.Response{}, nil
|
||||
infoKey := utils.GetLoginKeysKey(utils.LoginTypeAdmin, strconv.FormatInt(in.Id, utils.NumberTen))
|
||||
json, err := redis.Client.Get(l.ctx, infoKey).Result()
|
||||
if err != nil {
|
||||
return l.out(utils.Fail, "获取登录信息失败")
|
||||
}
|
||||
var info utils.LoginRedis
|
||||
err = jsoniter.Unmarshal([]byte(json), &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.ErrorJsonDataError)
|
||||
}
|
||||
refreshKey := utils.GetLoginRefreshKey(utils.LoginTypeAdmin, info.Refresh)
|
||||
tokenKey := utils.GetLoginKey(utils.LoginTypeAdmin, info.Token)
|
||||
_, err = redis.Client.Del(l.ctx, infoKey).Result()
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
_, err = redis.Client.Del(l.ctx, refreshKey).Result()
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
_, err = redis.Client.Del(l.ctx, tokenKey).Result()
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -120,3 +120,14 @@ func (p LoginRoutesValidator) GetMessage() validate.ValidatorMessages {
|
||||
"ServiceId.required": "服务ID不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
type LoginKickedOutValidator struct {
|
||||
Id int64 `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 提示消息
|
||||
func (p LoginKickedOutValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Id.required": "ID不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user