public ActionResult VerifyPassword() { string str = base.Request.QueryString["SecretKey"]; if (!string.IsNullOrEmpty(str)) { Maticsoft.BLL.SysManage.VerifyMail mail = new Maticsoft.BLL.SysManage.VerifyMail(); if (mail.Exists(str)) { Maticsoft.Model.SysManage.VerifyMail model = mail.GetModel(str); if (((model != null) && model.ValidityType.HasValue) && (model.ValidityType.Value == 1)) { if (model.Status == 0) { TimeSpan span = (TimeSpan) (DateTime.Now - model.CreatedDate); if (span.TotalHours > 24.0) { model.Status = 2; mail.Update(model); ((dynamic) base.ViewBag).Msg = "找回密码的验证码已过期!"; base.ModelState.AddModelError("Error", "找回密码的验证码已过期!"); } User user = new User(model.UserName); if (user != null) { ((dynamic) base.ViewBag).Email = user.Email; } model.Status = 1; mail.Update(model); ((dynamic) base.ViewBag).Msg = "Success"; } else if (model.Status == 1) { model.Status = 2; mail.Update(model); ((dynamic) base.ViewBag).Msg = "找回密码的验证码已通过邮箱验证!"; base.ModelState.AddModelError("Error", "找回密码的验证码已通过邮箱验证!"); } else if (model.Status == 2) { ((dynamic) base.ViewBag).Msg = "找回密码的验证码已过期!"; base.ModelState.AddModelError("Error", "找回密码的验证码已过期!"); } else { ((dynamic) base.ViewBag).Msg = "无效的邮箱验证码!"; base.ModelState.AddModelError("Error", "无效的邮箱验证码!"); } } } } return base.View(); }
public bool SendRegisterEmail(string username, string EmailUrl) { string str = Guid.NewGuid().ToString().Replace("-", ""); Maticsoft.BLL.SysManage.VerifyMail mail = new Maticsoft.BLL.SysManage.VerifyMail(); Maticsoft.Model.SysManage.VerifyMail model = new Maticsoft.Model.SysManage.VerifyMail { UserName = username, KeyValue = str, CreatedDate = DateTime.Now, Status = 0, ValidityType = 0 }; mail.Add(model); int templetId = Globals.SafeInt(ConfigSystem.GetValueByCache("EmailTemplet_Register"), 0); Maticsoft.Model.Ms.EmailTemplet modelByCache = this.GetModelByCache(templetId); if (modelByCache != null) { string body = this.ReplaceTag(modelByCache.EmailBody, new string[][] { new string[] { "{Domain}", HttpContext.Current.Request.Url.Authority }, new string[] { "{CreatedDate}", DateTime.Now.ToString("yyyy-MM-dd") }, new string[] { "{SecretKey}", str }, new string[] { "{UserName}", username } }); try { Maticsoft.Model.MailConfig config = this.config.GetModel(); if ((model != null) && !string.IsNullOrWhiteSpace(config.Mailaddress)) { MailSender.Send(config.SMTPServer, config.Username, DESEncrypt.Decrypt(config.Password), config.Mailaddress, EmailUrl, "", "", modelByCache.EmailSubject, body, true, Encoding.UTF8, true, config.SMTPSSL, null); return true; } return true; } catch (Exception exception) { Maticsoft.Model.SysManage.ErrorLog log = new Maticsoft.Model.SysManage.ErrorLog { Loginfo = "邮件发送失败!错误信息为:" + exception.StackTrace, OPTime = DateTime.Now, Url = "", StackTrace = exception.StackTrace }; Maticsoft.BLL.SysManage.ErrorLog.Add(log); return false; } } return false; }