48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package tokenservicelogic
|
|
|
|
import (
|
|
"context"
|
|
|
|
ers "code.30cm.net/digimon/library-go/errors"
|
|
|
|
"app-cloudep-permission-server/gen_result/pb/permission"
|
|
"app-cloudep-permission-server/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CancelOneTimeTokenLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewCancelOneTimeTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelOneTimeTokenLogic {
|
|
return &CancelOneTimeTokenLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
type cancelOneTimeTokenReq struct {
|
|
Token []string `json:"token" validate:"required"`
|
|
}
|
|
|
|
// CancelOneTimeToken 取消一次性使用
|
|
func (l *CancelOneTimeTokenLogic) CancelOneTimeToken(in *permission.CancelOneTimeTokenReq) (*permission.OKResp, error) {
|
|
// 驗證所需
|
|
if err := l.svcCtx.Validate.ValidateAll(&cancelOneTimeTokenReq{
|
|
Token: in.GetToken(),
|
|
}); err != nil {
|
|
return nil, ers.InvalidFormat(err.Error())
|
|
}
|
|
|
|
err := l.svcCtx.TokenRedisRepo.DeleteOneTimeToken(l.ctx, in.GetToken(), nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &permission.OKResp{}, nil
|
|
}
|