/// <summary> /// 发送验证码 - 找回密码 /// </summary> /// <param name="email"></param> /// <returns></returns> public async Task <ResponseModel <string> > SendEmailAsync(string email) { var response = new ResponseModel <string>(); if (!email.IsEmail()) { return(response.Fail("邮箱格式错误")); } var key = $"{CacheKeys.RETRIEVEPWDCAPTCHA}{email}"; var expireMinutes = 5; if (await FrequentlyGetCaptchaAsync(key, expireMinutes, 2)) { return(response.Fail("获取验证码过于频繁,请稍后再获取")); } if (!await ExistUserAsync(email)) { return(response.Fail("该邮箱尚未注册或无效")); } var captchaNumber = CaptchaHelper.CreateRandomNumber(6); var htmlEmail = SystemBll.GetMailContent("找回密码", captchaNumber, expireMinutes); var result = await SystemBll.SendSystemMailAsync("LionFrame-找回密码", htmlEmail, email); if (result.Contains("发送成功")) { await RedisClient.SetAsync(key, captchaNumber, new TimeSpan(0, expireMinutes, 0)); } return(response.Succeed("发送成功")); }
/// <summary> /// 得到验证码 /// </summary> /// <param name="emailTo"></param> /// <returns></returns> public async Task <string> GetRegisterCaptchaAsync(string emailTo) { if (await ExistUserAsync(emailTo)) { return("该邮箱已存在,请切换或找回密码"); } var key = $"{CacheKeys.REGISTERCAPTCHA}{emailTo}"; var expireMinutes = 5; if (await FrequentlyGetCaptchaAsync(key, expireMinutes, 2)) { return("获取验证码过于频繁,请稍后再获取"); } var captchaNumber = CaptchaHelper.CreateRandomNumber(6); var htmlEmail = SystemBll.GetMailContent("注册账号", captchaNumber, expireMinutes); var result = await SystemBll.SendSystemMailAsync("LionFrame-注册账号", htmlEmail, emailTo); if (result.Contains("发送成功")) { await RedisClient.SetAsync(key, captchaNumber, new TimeSpan(0, expireMinutes, 0)); } return(result); }