/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task Consume(ConsumeContext <SendFotgotPwdEmailCapthcaCommand> context) { var data = context.Message; string captcha = this.captchaHelper.NewCaptcha(data.key, data.type, 6, data.timeout); EmailHepler.SendEmail(data.email, "Qing-找回密码验证码", $"忘记密码验证码[{captcha}],{ data.timeout / 60 }分钟内有效."); }
/// <summary> /// /// </summary> /// <param name="loginInfo"></param> /// <returns></returns> private DTOAPIRes_Login LoginUnionWay(DTOAPIReq_Login loginInfo) { var entity = this.accesser.db.Accounts; IQueryable <Account> query_union = this.accesser.db.Accounts.Where(x => 1 == 0); try { Int64 key = Int64.Parse(loginInfo.username); entity.Where(x => x.Id == key); query_union = query_union.Union(entity.Where(x => x.Id == key)); } catch (Exception ex) { } if (PhoneHelper.IsValid(loginInfo.username)) { var data = PhoneHelper.Split(loginInfo.username); var areacode = data.Item1; var phone = data.Item2; query_union = query_union.Union(entity.Where(x => x.PhoneAreaCode == areacode && x.Phone == phone)); } if (EmailHepler.IsValid(loginInfo.username)) { string email = loginInfo.username.ToLower(); query_union = query_union.Union(entity.Where(x => x.Email.Equals(email))); } query_union = query_union.Union(entity.Where(x => x.Username == loginInfo.username)); query_union = query_union.Union(entity.Where(x => x.Passport.Equals(loginInfo.username.ToLower()))); #if DEBUG #endif var arr = query_union.ToArray(); if (arr != null && arr.Length > 0) { var account = arr.Where(x => x.Password == loginInfo.password).SingleOrDefault(); return(GenLoginData(account, loginInfo.password)); } else { return(new DTOAPIRes_Login { accessToken = "", state = 3, msg = "UID/通行证/用户名/邮箱/手机号不存在" }); } //return account; }
/// <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="emailInfo"></param> /// <returns></returns> public async Task <bool> IsValidEmailCodeByRegister(DTOAPI_EmailVerifyCode emailInfo) { bool bSuccess = false; if (!EmailHepler.IsValid(emailInfo.email)) { throw new Exception("邮箱格式不正确"); } bSuccess = this.captchaHelper.IsValidCaptcha($"RegisterCaptcha_{emailInfo.email.ToLower()}", emailInfo.verifyCode); return(bSuccess); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="emailInfo"></param> /// <returns></returns> public async Task SendLoginVerifyCodeByEmail(DTOAPI_EmailVerifyCode emailInfo) { if (!EmailHepler.IsValid(emailInfo.email)) { throw new Exception("邮箱格式不正确"); } var account = this.accesser.Get(email: emailInfo.email).Item1; if (account == null) { throw new Exception("用户不存在"); } await this.publishEndpoint.Publish(new SendLoginEmailCapthcaCommand { key = $"LoginCaptcha_{emailInfo.email.ToLower()}", email = emailInfo.email }); }
/// <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 }); }