app-cloudep-permission-server/internal/logic/tokenservice/cancel_token_by_device_id_l...

45 lines
1.3 KiB
Go
Raw Normal View History

package tokenservicelogic
import (
2024-08-24 14:40:09 +00:00
ers "code.30cm.net/digimon/library-go/errors"
"context"
"app-cloudep-permission-server/gen_result/pb/permission"
"app-cloudep-permission-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CancelTokenByDeviceIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCancelTokenByDeviceIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelTokenByDeviceIdLogic {
return &CancelTokenByDeviceIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CancelTokenByDeviceId 取消 Token 從 Device 視角出發可以選登出這個Device 下所有 token 登出這個Device 下指定token
func (l *CancelTokenByDeviceIdLogic) CancelTokenByDeviceId(in *permission.DoTokenByDeviceIDReq) (*permission.OKResp, error) {
2024-08-24 14:40:09 +00:00
if err := l.svcCtx.Validate.ValidateAll(&getUserTokensByDeviceIdReq{
DeviceID: in.GetDeviceId(),
}); err != nil {
return nil, ers.InvalidFormat(err.Error())
}
2024-08-24 14:40:09 +00:00
err := l.svcCtx.TokenRedisRepo.DeleteAccessTokensByDeviceID(l.ctx, in.GetDeviceId())
if err != nil {
logx.WithCallerSkip(1).WithFields(
logx.Field("func", "TokenRedisRepo.DeleteAccessTokensByDeviceID"),
logx.Field("DeviceID", in.GetDeviceId()),
).Error(err.Error())
return nil, err
}
return &permission.OKResp{}, nil
}