public async Task <IActionResult> Register(MoUserInfoSimple registerUser) { if (!ModelState.IsValid || registerUser == null) { this.MsgBox("验证失败,请稍后重试"); return(View(registerUser)); } var(result, userInfo) = await TryCreateUser(registerUser, RoleType.User); if (!result) { return(View()); } var timeOut = 5; var now = DateTime.Now.AddMinutes(timeOut).Ticks; // 设置过期时间 var expires = now.ToString(); var token = CryptHelper.GetMd5Value($"{expires}-{new Random().Next()}"); // 发送密码通知的URL var appUrl = $"http://{HttpRequest.UserHostName}"; var comfirmUrl = $"{appUrl}/member/activeemail/?expire={expires}&token={token}&email={userInfo.UserName}"; // 读取模板 var tpl = await HtmlTplHelper.GetHtmlTpl(EmailTpl.SettingEmail, _mapSetting.EmailTplPath); if (String.IsNullOrWhiteSpace(tpl)) { this.MsgBox("发送绑定邮件失败,请稍后重试。"); return(View()); } tpl = tpl.Replace("{name}", "尊敬的用户") .Replace("{content}", $"您正在使用<a href='{appUrl}'>GutsMvcBBS</a>邮件激活功能,请点击以下链接确认绑定邮箱<a href='{comfirmUrl}'>Click here</a>;注意该地址在{timeOut}分钟内有效。"); // 发送邮件 var isOk = EmailHelper.SendEmail( new Dictionary <string, string> { { "尊敬的用户", userInfo.UserName } }, "GutsMvcBBS - 邮箱激活", tpl); this.MsgBox(isOk ? "已给您邮箱发送了账号激活邮件,请收件后点击链接地址。" : "发送绑定邮件失败,请稍后重试!"); return(View()); }
public async Task <IActionResult> ForgetPassword(string email) { if (String.IsNullOrWhiteSpace(email)) { this.MsgBox("邮箱必填!"); return(View()); } email = email.Trim().ToLower(); if (email.Length >= 50 || email.Length <= 3) { this.MsgBox("邮箱长度不符!"); return(View()); } else if (new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").IsMatch(email) == false) { this.MsgBox("邮箱不合法,请重新输入"); return(View()); } var user = await _uf.UserRepository.GetAsync(x => x.Email.ToLower() == email); if (user == null) { this.MsgBox("不存在该绑定邮箱的账号!"); return(View()); } else if (user.UserStatus == UserStatus.禁用) { this.MsgBox("该绑定邮箱的账号已被禁用,可以通过发送邮件至:[email protected]联系客服!"); return(View()); } var timeOut = 5; var now = DateTime.Now.AddMinutes(timeOut); // 设置过期时间 var expires = now.Ticks; var token = CryptHelper.GetMd5Value($"{expires}-{email}"); // 发送密码通知的URL var appUrl = $"http://{HttpRequest.UserHostName}"; var comfirmUrl = $"{appUrl}/member/confirmpassword/?expire={expires}&token={token}&email={email}"; // 读取模板 var tpl = await HtmlTplHelper.GetHtmlTpl(EmailTpl.MsgBox, _mapSetting.EmailTplPath); if (String.IsNullOrWhiteSpace(tpl)) { this.MsgBox("发送邮件失败,请稍后重试。"); return(View()); } tpl = tpl.Replace("{name}", "尊敬的用户") .Replace("{content}", $"您正在使用<a href='{appUrl}'>GutsMvcBBS</a>邮件重置密码功能,请点击以下链接确认绑定邮箱<a href='{comfirmUrl}'>{comfirmUrl}</a>;注意该地址在{timeOut}分钟内有效。"); // 发送邮件 var isOk = EmailHelper.SendEmail( new Dictionary <string, string> { { "尊敬的用户", email } }, "GutsMvcBBS - 重置密码", tpl); this.MsgBox(isOk ? "已给您邮箱发送了重置密码邮件,请收件后点击重置密码链接地址。" : "发送绑定邮件失败,请稍后重试!"); return(View()); }
public async Task <IActionResult> SettingEmail(MoSetEmail moEmail) { if (!HttpContext.TryGetUserInfo(out var userInfo)) { this.MsgBox("登录过期,请重新登录"); return(View()); } ViewData["HeadPhoto"] = userInfo.HeadPhoto; ViewData["UserName"] = userInfo.UserName; ViewData["Role"] = userInfo.Roles.ToLower(); if (!ModelState.IsValid) { this.MsgBox("邮箱或密码错误!"); return(View()); } if (String.IsNullOrWhiteSpace(moEmail.Email)) { this.MsgBox("邮箱必填!"); return(View()); } if (String.IsNullOrWhiteSpace(moEmail.Password)) { this.MsgBox("密码必填"); return(View()); } var password = moEmail.Password.Trim(); var user = await _uf.UserRepository.GetByIdAsync(userInfo.Id); if (user == null) { this.MsgBox("出现错误,请稍后再试!"); return(View()); } if (user.Password != CryptHelper.GetMd5Value(password)) { this.MsgBox("密码错误,请重新输入!"); return(View(moEmail)); } var email = moEmail.Email.Trim(); var timeOut = 30; var now = DateTime.Now.AddMinutes(timeOut); var expires = now.Ticks; var token = CryptHelper.GetMd5Value($"{expires}-{email}"); var appUrl = $"http://{HttpRequest.UserHostName}"; var comfirmUrl = $"{appUrl}/usercenter/confirmsettingemail/?expire={expires}&token={token}&email={email}"; // 读取模板 var tpl = await HtmlTplHelper.GetHtmlTpl(EmailTpl.SettingEmail, _mapSetting.EmailTplPath); if (String.IsNullOrWhiteSpace(tpl)) { this.MsgBox("发送绑定邮件失败,请稍后重试"); return(View()); } tpl = tpl.Replace("{name}", userInfo.UserName) .Replace("{content}", $"您正在使用GutsMvcBBS邮件绑定功能,请点击以下链接取人绑定邮箱<a href='{comfirmUrl}'>{comfirmUrl}</a><br />注意该地址有效时间为{timeOut}分钟"); // 发送 var isOk = EmailHelper.SendEmail( new Dictionary <string, string> { { userInfo.UserName, email } }, "GutsMvcBBS - 绑定邮箱", tpl ); this.MsgBox(isOk ? "已给您邮箱发送了绑定确认邮件,请收件后点击确认绑定链接地址。" : "发送绑定邮件失败,请稍后重试!"); return(View()); }