ark-member/internal/logic/verify_refresh_code_logic.go

69 lines
1.6 KiB
Go
Raw Normal View History

2024-07-21 15:57:56 +00:00
package logic
import (
"context"
2024-07-25 14:01:22 +00:00
"fmt"
2024-08-02 02:10:25 +00:00
"member/gen_result/pb/member"
2024-07-25 14:01:22 +00:00
"member/internal/domain"
ers "member/internal/lib/error"
2024-07-21 15:57:56 +00:00
"member/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type VerifyRefreshCodeLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewVerifyRefreshCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VerifyRefreshCodeLogic {
return &VerifyRefreshCodeLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// VerifyRefreshCode 驗證忘記密碼 token
func (l *VerifyRefreshCodeLogic) VerifyRefreshCode(in *member.VerifyRefreshCodeReq) (*member.Response, error) {
2024-08-02 02:10:25 +00:00
// 驗證資料
if err := l.svcCtx.Validate.ValidateAll(&generateRefreshCodeReq{
2024-07-25 14:01:22 +00:00
Account: in.GetAccount(),
CodeType: in.GetCodeType(),
2024-08-02 02:10:25 +00:00
}); err != nil {
2024-07-25 14:01:22 +00:00
return nil, ers.InvalidFormat(err.Error())
}
checkType, status := getCodeNameByCode(in.GetCodeType())
if !status {
return nil, ers.InvalidFormat(fmt.Errorf("failed to get correct code type").Error())
}
rk := fmt.Sprintf("verify:%s:%s", checkType, in.GetAccount())
get, err := l.svcCtx.Redis.Get(rk)
if err != nil {
return nil, ers.DBError("failed to connect to redis", err.Error())
}
if get == "" {
return nil, ers.DBError("failed to get data from redis")
}
if get != fmt.Sprintf("%d", in.CodeType) {
return nil, ers.ArkInternal("Illegible Verify Code")
}
_, err = l.svcCtx.Redis.Del(rk)
if err != nil {
return nil, ers.DBError("failed to del redis key", rk)
}
2024-07-21 15:57:56 +00:00
2024-07-25 14:01:22 +00:00
return &member.Response{
Status: &member.BaseResp{
Code: domain.CodeOk.ToString(),
Message: "success",
Error: "",
},
}, nil
2024-07-21 15:57:56 +00:00
}