修复绑定相同邮箱时的错误提示问题,允许重复绑定相同邮箱 重构设备绑定逻辑,增加详细注释和日志记录 移除无用的WebSocket测试端点 更新测试脚本中的默认配置和测试用例
This commit is contained in:
@@ -61,8 +61,17 @@ func (l *BindEmailWithPasswordLogic) BindEmailWithPassword(req *types.BindEmailW
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "FindUserAuthMethodByUserId error")
|
||||
}
|
||||
|
||||
// 如果当前用户已经绑定了邮箱,不允许重复绑定
|
||||
// 如果当前用户已经绑定了邮箱,检查是否是同一个邮箱
|
||||
if currentEmailMethod.Id > 0 {
|
||||
// 如果绑定的是同一个邮箱,直接返回成功
|
||||
if currentEmailMethod.AuthIdentifier == req.Email {
|
||||
l.Infow("user is binding the same email that is already bound",
|
||||
logger.Field("user_id", currentUser.Id),
|
||||
logger.Field("email", req.Email),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
// 如果是不同的邮箱,不允许重复绑定
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.UserExist), "current user already has email bound")
|
||||
}
|
||||
|
||||
@@ -76,13 +85,13 @@ func (l *BindEmailWithPasswordLogic) BindEmailWithPassword(req *types.BindEmailW
|
||||
if existingEmailMethod.Id > 0 && existingEmailMethod.UserId != currentUser.Id {
|
||||
// 调用设备绑定逻辑,这会触发数据迁移
|
||||
bindLogic := auth.NewBindDeviceLogic(l.ctx, l.svcCtx)
|
||||
|
||||
|
||||
// 获取当前用户的设备标识符
|
||||
deviceMethod, err := l.svcCtx.UserModel.FindUserAuthMethodByUserId(l.ctx, "device", currentUser.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "FindUserAuthMethodByUserId device error")
|
||||
}
|
||||
|
||||
|
||||
if deviceMethod.Id == 0 {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "current user has no device identifier")
|
||||
}
|
||||
@@ -111,7 +120,7 @@ func (l *BindEmailWithPasswordLogic) BindEmailWithPassword(req *types.BindEmailW
|
||||
AuthIdentifier: req.Email,
|
||||
Verified: true, // 通过密码验证,直接设为已验证
|
||||
}
|
||||
|
||||
|
||||
if err := l.svcCtx.UserModel.InsertUserAuthMethods(l.ctx, emailMethod); err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "InsertUserAuthMethods error")
|
||||
}
|
||||
@@ -123,4 +132,4 @@ func (l *BindEmailWithPasswordLogic) BindEmailWithPassword(req *types.BindEmailW
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user