public async Task <IActionResult> IsValidEmailCodeByForgotPwd([FromBody] DTOAPI_ForgotPwdByEmailCaptcha pwdInfo) { try { bool bSuccess = await this.services.IsValidEmailCodeByForgotPwd(pwdInfo).ConfigureAwait(false); return(OkEx(new { success = bSuccess })); } catch (Exception ex) { return(JsonToCamelCase(ex.Message, 50000, 50000, _desc: ex.Message)); } }
/// <summary> /// /// </summary> /// <param name="pwdInfo"></param> /// <returns></returns> public async Task <bool> IsValidEmailCodeByForgotPwd(DTOAPI_ForgotPwdByEmailCaptcha pwdInfo) { bool bSuccess = false; if (!EmailHepler.IsValid(pwdInfo.email)) { throw new Exception("邮箱格式不正确"); } bSuccess = this.captchaHelper.IsValidCaptcha($"ForgotPwdCaptcha_{pwdInfo.email.ToLower()}", pwdInfo.verifyCode); return(bSuccess); }
/// <summary> /// /// </summary> /// <param name="pwdInfo"></param> /// <returns></returns> public async Task ForgotPwdCodeByEmail(DTOAPI_ForgotPwdByEmailCaptcha pwdInfo) { if (!EmailHepler.IsValid(pwdInfo.email)) { throw new Exception("邮箱格式不正确"); } if (!AccountValidator.bValidPassword(pwdInfo.newpwd)) { throw new Exception("密码格式不正确"); } var account = this.accesser.Get(email: pwdInfo.email).Item1; if (account == null) { throw new Exception("用户不存在"); } string key_captcha = $"ForgotPwdCaptcha_{pwdInfo.email.ToLower()}"; if (!this.captchaHelper.GetCaptcha(key_captcha).Equals(pwdInfo.verifyCode, StringComparison.CurrentCultureIgnoreCase)) { throw new Exception("验证码错误"); } await this.publishEndpoint.Publish(new ChangePasswordCommand { key = account.Id, newPassword = pwdInfo.newpwd }); await this.publishEndpoint.Publish(new DeleteAccountCaptchaCommand { key = key_captcha }); }