Пример #1
0
        /// <summary>
        /// 激活密码找回
        /// </summary>
        /// <returns></returns>
        public ActionResult VerifyPassword()
        {
            string SecretKey = ViewBag.SecretKey = Request.QueryString["SecretKey"];

            if (!string.IsNullOrEmpty(SecretKey))
            {
                YSWL.MALL.BLL.SysManage.VerifyMail bll = new YSWL.MALL.BLL.SysManage.VerifyMail();
                if (bll.Exists(SecretKey))
                {
                    YSWL.MALL.Model.SysManage.VerifyMail model = bll.GetModel(SecretKey);
                    if (model != null && model.ValidityType.HasValue)
                    {
                        if (model.ValidityType.Value == 1)
                        {
                            // 0:邮箱验证未通过1:邮箱验证通过2:已过期
                            if (model.Status == 0)
                            {
                                TimeSpan ts = DateTime.Now - model.CreatedDate;
                                if (ts.TotalHours > 24)
                                {
                                    model.Status = 2;// 0:邮箱验证未通过1:邮箱验证通过2:已过期
                                    bll.Update(model);
                                    ViewBag.Msg = "找回密码的验证码已过期!";
                                    ModelState.AddModelError("Error", "找回密码的验证码已过期!");
                                }

                                User user = new User(model.UserName);
                                if (user != null)
                                {
                                    ViewBag.Email = user.Email;
                                }
                                model.Status = 1;// 0:邮箱验证未通过1:邮箱验证通过2:已过期
                                bll.Update(model);
                                ViewBag.Msg = "Success";
                            }
                            else if (model.Status == 1)
                            {
                                model.Status = 2;
                                bll.Update(model);
                                ViewBag.Msg = "找回密码的验证码已通过邮箱验证!";
                                ModelState.AddModelError("Error", "找回密码的验证码已通过邮箱验证!");
                            }
                            else if (model.Status == 2)
                            {
                                ViewBag.Msg = "找回密码的验证码已过期!";
                                ModelState.AddModelError("Error", "找回密码的验证码已过期!");
                            }
                            else
                            {
                                ViewBag.Msg = "无效的邮箱验证码!";
                                ModelState.AddModelError("Error", "无效的邮箱验证码!");
                            }
                        }
                    }
                }
            }
            return(View());
        }
Пример #2
0
        public ActionResult VerifyPassword(FormCollection collection)
        {
            if (!String.IsNullOrWhiteSpace(collection["Email"]) && !String.IsNullOrWhiteSpace(collection["NewPwd"]))
            {
                string secretKey = collection["SecretKey"];
                string username  = collection["Email"].Trim();
                string password  = collection["NewPwd"];

                YSWL.MALL.BLL.SysManage.VerifyMail bll = new YSWL.MALL.BLL.SysManage.VerifyMail();

                YSWL.MALL.Model.SysManage.VerifyMail model = bll.GetModel(secretKey);
                if (model == null || !model.ValidityType.HasValue || model.ValidityType.Value != 1 ||
                    model.UserName != username)
                {
                    //非法修改密码
                    LogHelp.AddInvadeLog("Areas.SNS.Controllers-HttpPost-VerifyPassword", System.Web.HttpContext.Current.Request);
                    return(HttpNotFound());
                }

                User currentUser = new User(username);
                if (String.IsNullOrWhiteSpace(password))
                {
                    ModelState.AddModelError("Error", "该用户不存在!");
                    return(View());
                }
                currentUser.Password = AccountsPrincipal.EncryptPassword(YSWL.Common.PageValidate.InputText(password, 30));
                if (!currentUser.Update())
                {
                    ModelState.AddModelError("Error", "密码重置失败,请检查输入的信息是否正确或者联系管理员!");
                    return(View());
                }
                else
                {
                    AccountsPrincipal newUser = AccountsPrincipal.ValidateLogin(username, password);
                    FormsAuthentication.SetAuthCookie(username, false);
                    Session[Globals.SESSIONKEY_USER] = currentUser;
                    Session["Style"] = currentUser.Style;
                    YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                    pointBll.AddPoints(1, currentUser.UserID, "登录操作");
                    BLL.Members.RankDetail.AddScore(1, currentUser.UserID, "登录操作");
                    if (Session["returnPage"] != null)
                    {
                        string returnpage = Session["returnPage"].ToString();
                        Session["returnPage"] = null;
                        return(Redirect(returnpage));
                    }
                    else
                    {
                        return(RedirectToAction("Posts", "Profile"));
                    }
                }
            }
            return(View());
        }