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 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 07:14:58 +00:00
|
|
|
|
|
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
|
|
|
|
|
}
|
2024-08-24 07:14:58 +00:00
|
|
|
|
return &permission.OKResp{}, nil
|
|
|
|
|
}
|