Ejemplo n.º 1
0
        public ActionResult UserResetPassword(UserPassResetModel model)
        {
            //判断提交模型数据是否正确
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            IUserBLL userBll = BLLFactory <IUserBLL> .GetBLL("UserBLL");

            var user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            if (user != null)
            {
                //如果重置密码激活码存在且未失效
                if (!string.IsNullOrEmpty(user.Activecode) && model.Activecode == user.Activecode &&
                    user.ActivecodeInvalidTime != null && DateTime.Now < user.ActivecodeInvalidTime.Value)
                {
                    user.Password = PropertyUtils.GetMD5Str(model.Password);
                    //密码重置链接失效
                    user.Activecode            = "";
                    user.ActivecodeInvalidTime = null;
                    //如果修改成功
                    if (userBll.Update(user))
                    {
                        return(RedirectToAction("ResetSuccess"));
                    }
                }
            }
            return(RedirectToAction("Error500"));
        }
Ejemplo n.º 2
0
        public ActionResult UserResetPassword(PassResetActiveModel model)
        {
            if (model.Body == null)
            {
                return(RedirectToAction("ResetUrlInvalid"));
            }
            //将用户ID解密
            int      UserId  = Int32.Parse(PropertyUtils.DecodeBase64(model.Body));
            IUserBLL userBll = BLLFactory <IUserBLL> .GetBLL("UserBLL");

            var user = userBll.GetEntity(u => u.Id == UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            if (user != null)
            {
                //如果重置密码激活码存在且未失效
                if (!string.IsNullOrEmpty(user.Activecode) && model.Activecode == user.Activecode &&
                    user.ActivecodeInvalidTime != null && DateTime.Now <= user.ActivecodeInvalidTime.Value)
                {
                    UserPassResetModel m = new UserPassResetModel();
                    m.UserId     = user.Id;
                    m.UserName   = user.UserName;
                    m.Activecode = user.Activecode;
                    return(View(m));
                }
                else
                {
                    return(RedirectToAction("ResetUrlInvalid"));
                }
            }
            else
            {
                return(RedirectToAction("ResetUrlInvalid"));
            }
        }