fix: 统一重置密码验证码的 scene 常量

This commit is contained in:
zetaloop
2026-04-23 14:58:25 +08:00
parent 86f3490fc2
commit d596d41e1a
3 changed files with 5 additions and 3 deletions
@@ -8,6 +8,7 @@ import (
"juwan-backend/app/email/api/internal/svc"
"juwan-backend/app/email/api/internal/types"
"juwan-backend/common/redisx"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -30,6 +31,6 @@ func NewForgotPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Fo
func (l *ForgotPasswordLogic) ForgotPassword(req *types.ForgotPasswordReq) (resp *types.SendVerificationCodeResp, err error) {
return NewSendVerificationCodeLogic(l.ctx, l.svcCtx).SendVerificationCode(&types.SendVerificationCodeReq{
Email: req.Email,
Scene: "reset_password",
Scene: redisx.SCENE_RESET_PWD,
})
}
@@ -29,7 +29,7 @@ func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Res
func (l *ResetPasswordLogic) ResetPassword(in *pb.ResetPasswordReq) (*pb.ResetPasswordResp, error) {
// todo: add your logic here and delete this line
redisKey := fmt.Sprintf(redisx.VCODE_KEY_PREFIX, in.RequestId, redisx.SCENE_REG, in.Email)
redisKey := fmt.Sprintf(redisx.VCODE_KEY_PREFIX, in.RequestId, redisx.SCENE_RESET_PWD, in.Email)
vcode, err := l.svcCtx.RedisCluster.Get(l.ctx, redisKey).Result()
if err != nil {
logx.Errorf("get reset password vcode from redis failed, err:%v.", err)
@@ -38,6 +38,7 @@ func (l *ResetPasswordLogic) ResetPassword(in *pb.ResetPasswordReq) (*pb.ResetPa
if vcode != in.Vcode {
return nil, errors.New(fmt.Sprintf("user %v reset password failed, invalid vcode.", in.Email))
}
// in.NewPassword is already bcrypt-hashed by the API layer
err = l.svcCtx.UsersModelRW.Users.Update().Where(users.EmailEQ(in.Email)).
SetPasswordHash(in.NewPassword).
Exec(l.ctx)
+1 -1
View File
@@ -3,7 +3,7 @@ package redisx
const (
VCODE_KEY_PREFIX = "vcode:%s:%s:%s" // vocde:<request id>:<Scene>:<account>
SCENE_LOGIN = "login"
SCENE_RESET_PWD = "reset_pwd"
SCENE_RESET_PWD = "reset_password"
SCENE_BIND = "bind"
SCENE_REG = "register"
)