public ActionResult ForgetPassword(string email, string vercode) { if (string.IsNullOrEmpty(email)) { return(Json(new JsonResultModel { Message = "请输入您的邮箱地址!" })); } if (string.IsNullOrEmpty(vercode)) { return(Json(new JsonResultModel { Message = "请输入验证码!" })); } if (!VerCode.CheckVerifyCode(vercode)) { return(Json(new JsonResultModel { Message = "验证码错误,请重新输入!" })); } UserVModel user; if (UserIsLogin) { //已登陆 user = Users.GetUserById(CurrentUserInfo.Id); if (user == null || user.IsNull) { return(Json(new JsonResultModel { Message = "您的信息有误,操作失败!" })); } if (user.Email.ToLower() != email.ToLower()) { return(Json(new JsonResultModel { Message = "您的邮箱有误,请确认您个人信息中的邮箱!" })); } } else { //未登陆 //先查出用户id user = Users.GetUserByEmail(email); if (user == null || user.IsNull) { return(Json(new JsonResultModel { Message = "您的邮箱地址不存在,请您确认!" })); } } #region 发送邮件限制检测 string msg; bool checkResult = SendMailLogsPublic.CheckUserEmailAvailable(user.Id, UserConfig.SendEmailInterval, UserConfig.SendEmailIntervalMaxNum, UserConfig.SendEmailToDayMaxNum, out msg); if (!checkResult) { return(Json(new JsonResultModel { Message = msg })); } #endregion #region 写入令牌信息 IToken token = new EmailActivateToken(user.Id, user.Email); string tokenCode = token.GetToken(); var tokeninfo = new UserActivateTokenVModel() { UserId = user.Id, Email = user.Email, Token = tokenCode }; long id = UserActivateTokensPublic.Add(tokeninfo); if (id <= 0) { return(Json(new JsonResultModel { Message = "写入令牌信息失败,请重试!" })); } #endregion #region 发送激活邮件 string title = WebSysConfig.WebName + "找回密码邮件"; var values = new Dictionary <string, object> { { "$Title", title }, { "$Url", "http://" + Request.Url.Host + Url.Action("forgetpassword", "user", new{ token = tokenCode }) }, { "$WebName", WebSysConfig.WebName }, { "$TimeDsc", WebSysConfig.RetrievePasswordTokenExpireTime + "分钟内" } }; bool status = UserPublic.SendMail(user.Id, user.Id, Common.Fetch.Ip, user.Email, EmailTemplateConfig.RetrievePasswordEmailTemplate, values, "UTF-8", true); if (status) { return(Json(new JsonResultModel { ResultState = true, Message = "邮件发送成功,请进入邮箱进行操作!" })); } #endregion return(Json(new JsonResultModel { Message = "邮件发送失败!" })); }
public ActionResult Activate(int?ig) { var user = Users.GetUserById(CurrentUserInfo.Id); if (user == null || user.IsNull) { return(Json(new JsonResultModel { Message = "用户信息有误,发送激活邮件失败!" })); } if (user.EmailStatus) { return(Json(new JsonResultModel { Message = "您的邮箱已经激活,无需再次激活!" })); } #region 发送邮件限制检测 string msg; bool checkResult = SendMailLogsPublic.CheckUserEmailAvailable(user.Id, UserConfig.SendEmailInterval, UserConfig.SendEmailIntervalMaxNum, UserConfig.SendEmailToDayMaxNum, out msg); if (!checkResult) { return(Json(new JsonResultModel { Message = msg })); } #endregion #region 写入激活信息 IToken token = new EmailActivateToken(user.Id, user.Email); string tokenCode = token.GetToken(); var tokeninfo = new UserActivateTokenVModel() { UserId = CurrentUserInfo.Id, Email = user.Email, Token = tokenCode }; long id = UserActivateTokensPublic.Add(tokeninfo); if (id <= 0) { return(Json(new JsonResultModel { Message = "写入激活信息失败,请重试!" })); } #endregion #region 发送激活邮件 string title = WebSysConfig.WebName + "激活邮件"; var values = new Dictionary <string, object> { { "$Title", title }, { "$UserName", user.NickName ?? user.Name }, { "$Url", "http://" + Request.Url.Host + Url.Action("activateemail", "user", new{ token = tokenCode }) }, { "$WebName", WebSysConfig.WebName }, { "$TimeDsc", WebSysConfig.ActivateTokenExpireTime + "分钟内" } }; bool status = UserPublic.SendMail(CurrentUserInfo.Id, CurrentUserInfo.Id, Common.Fetch.Ip, user.Email, EmailTemplateConfig.EmailActivateTemplate, values, "UTF-8", true); if (status) { return(Json(new JsonResultModel { ResultState = true, Message = "激活邮件发生成功,请进入邮箱进行激活!" })); } #endregion return(Json(new JsonResultModel { Message = "邮件发送失败!" })); }