2024-08-24 07:14:58 +00:00
|
|
|
package tokenservicelogic
|
|
|
|
|
|
|
|
import (
|
2024-08-24 14:40:09 +00:00
|
|
|
ers "code.30cm.net/digimon/library-go/errors"
|
2024-08-24 07:14:58 +00:00
|
|
|
"context"
|
|
|
|
|
|
|
|
"app-cloudep-permission-server/gen_result/pb/permission"
|
|
|
|
"app-cloudep-permission-server/internal/svc"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CancelTokensLogic struct {
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
logx.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCancelTokensLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelTokensLogic {
|
|
|
|
return &CancelTokensLogic{
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CancelTokens 取消 Token 從UID 視角,以及 token id 視角出發, UID 登出,底下所有 Device ID 也要登出, Token ID 登出, 所有 UID + Device 都要登出
|
|
|
|
func (l *CancelTokensLogic) CancelTokens(in *permission.DoTokenByUIDReq) (*permission.OKResp, error) {
|
2024-08-24 14:40:09 +00:00
|
|
|
if in.GetUid() != "" {
|
|
|
|
err := l.svcCtx.TokenRedisRepo.DeleteAccessTokensByUID(l.ctx, in.GetUid())
|
|
|
|
if err != nil {
|
|
|
|
logx.WithCallerSkip(1).WithFields(
|
|
|
|
logx.Field("func", "TokenRedisRepo.DeleteAccessTokensByUID"),
|
|
|
|
logx.Field("uid", in.GetUid()),
|
|
|
|
).Error(err.Error())
|
|
|
|
return nil, ers.ResourceInsufficient(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(in.GetIds()) > 0 {
|
|
|
|
err := l.svcCtx.TokenRedisRepo.DeleteAccessTokenByID(l.ctx, in.GetIds())
|
|
|
|
if err != nil {
|
|
|
|
logx.WithCallerSkip(1).WithFields(
|
|
|
|
logx.Field("func", "TokenRedisRepo.DeleteAccessTokenByID"),
|
|
|
|
logx.Field("ids", in.GetIds()),
|
|
|
|
).Error(err.Error())
|
|
|
|
return nil, ers.ResourceInsufficient(err.Error())
|
|
|
|
}
|
|
|
|
}
|
2024-08-24 07:14:58 +00:00
|
|
|
|
|
|
|
return &permission.OKResp{}, nil
|
|
|
|
}
|