public async Task <IActionResult> RegisterByEmailVerifyCode([FromBody] DTOAPI_RegisterByEmailVerifyCode registerInfo) { try { var data = await this.services.RegisterByEmailVerifyCode(registerInfo).ConfigureAwait(false); return(OkEx(data)); } catch (Exception ex) { return(this.JsonToCamelCase(ex.Message, 50000, 50000, ex.Message)); } }
/// <summary> /// /// </summary> /// <param name="registerInfo"></param> /// <returns></returns> public async Task <long> RegisterByEmailVerifyCode(DTOAPI_RegisterByEmailVerifyCode registerInfo) { if (!EmailHepler.IsValid(registerInfo.email)) { throw new Exception("邮箱格式不正确"); } if (!AccountValidator.bValidPassword(registerInfo.pwd)) { throw new Exception("密码格式错误"); } string key_captcha = $"RegisterCaptcha_{registerInfo.email.ToLower()}"; string captcha = this.captchaHelper.GetCaptcha(key_captcha); if (String.IsNullOrEmpty(captcha) || !String.Equals(captcha, registerInfo.verifyCode, StringComparison.CurrentCultureIgnoreCase)) { throw new Exception("验证码错误"); } var account = this.accesser.Get(email: registerInfo.email).Item1; if (account != null) { throw new Exception("用户已存在"); } var newId = this.IDGenerator.GetNewID <Account>(); await this.publishEndpoint.Publish(new RegisterAccountByEmailCommand { id = newId, email = registerInfo.email.ToLower(), password = registerInfo.pwd }); await this.publishEndpoint.Publish(new DeleteAccountCaptchaCommand { key = key_captcha }); return(newId); }