public ActionResult ResetPassWord(LoginViewModel model, string returnUrl)
        {
            //return RedirectToAction("Login", "Account", new { msg = "forget" });
            var checkCode = "";

            if (ModelState.IsValid)
            {
                try
                {
                    var cutTM = DateTime.Now;

                    checkCode = HostContext.AppHost.Resolve <ICacheClient>().Get <string>("checkCode");

                    var SendTime = Request.Form["SendTime"].Trim().ToLower();
                    var sendTime = !string.IsNullOrEmpty(SendTime) ? DateTime.Parse(SendTime) : cutTM.AddMonths(-1);
                    if (!string.IsNullOrEmpty(checkCode))
                    {
                        #region 校验码正常

                        var MessgaeValidTimeConfig = AppConfigUtil.getValue("MessgaeValidTime");
                        var MessgaeValidTime       = !string.IsNullOrEmpty(MessgaeValidTimeConfig)
                            ? double.Parse(MessgaeValidTimeConfig)
                            : 5;
                        if (string.IsNullOrEmpty(model.Code) || model.Code != checkCode)
                        {
                            ModelState.AddModelError("", "验证失败,校验码错误。"); // +e.Message
                        }
                        else if (!string.IsNullOrEmpty(model.Code) && (cutTM - sendTime).TotalMinutes > MessgaeValidTime)
                        {
                            ModelState.AddModelError("", "验证失败,校验码无效,请重新获取校验码。"); // +e.Message
                        }
                        else
                        {
                            using (var service = HostContext.AppHost.Resolve <LoginService>())
                            {
                                #region 修改密码

                                if (service.Post(new forgetPassword()
                                {
                                    UserName = model.UserName, Password = model.Password
                                }))
                                {
                                    return(RedirectToAction("Login", "Account", new { msg = "forget" }));
                                }

                                #endregion
                            }
                        }

                        #endregion
                    }
                    else
                    {
                        ModelState.AddModelError("", "验证失败,校验码异常,请重新获取校验码。"); // +e.Message
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "验证失败。"); // +e.Message
                }
            }
            if (!string.IsNullOrEmpty(checkCode))
            {
                HostContext.AppHost.Resolve <ICacheClient>().Remove("checkCode");
            }
            return(View(model));
        }
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var cutTM     = DateTime.Now;
                    var checkCode = HostContext.AppHost.Resolve <ICacheClient>().Get <string>("checkCode");
                    var isCheck   = Request.Form["isCheck"].Trim().ToLower();
                    var SendTime  = Request.Form["SendTime"].Trim().ToLower();
                    var sendTime  = !string.IsNullOrEmpty(SendTime) ? DateTime.Parse(SendTime) : cutTM.AddMonths(-1);
                    if (isCheck == "true" || !string.IsNullOrEmpty(checkCode))
                    {
                        var MessgaeValidTimeConfig = AppConfigUtil.getValue("MessgaeValidTime");
                        var MessgaeValidTime       = !string.IsNullOrEmpty(MessgaeValidTimeConfig)
                            ? double.Parse(MessgaeValidTimeConfig) :5;
                        if (model.Code == null || model.Code != checkCode)
                        {
                            ModelState.AddModelError("", "验证失败,校验码错误。"); // +e.Message
                            HostContext.AppHost.Resolve <ICacheClient>().Remove("checkCode");
                            return(View(model));
                        }
                        else if (!string.IsNullOrEmpty(model.Code) && (cutTM - sendTime).TotalMinutes > MessgaeValidTime)
                        {
                            ModelState.AddModelError("", "验证失败,校验码无效,请重新获取校验码。"); // +e.Message
                            HostContext.AppHost.Resolve <ICacheClient>().Remove("checkCode");
                            return(View(model));
                        }
                        else
                        {
                        }
                    }
                    using (var authService = HostContext.ResolveService <AuthenticateService>(base.HttpContext))
                    {
                        #region 登陆
                        var response = authService.Authenticate(new Authenticate
                        {
                            UserName   = model.UserName,
                            Password   = model.Password,
                            RememberMe = true
                        });

                        //SchemaManager.CreateNewTableIfNotExists(typeof (LogInfo),
                        //"log_info_" + DateTime.Now.ToString("yyyyMM"), "id", true);

                        var authTicket = new FormsAuthenticationTicket(model.UserName, model.RememberMe, 120);
                        var cookie     = new HttpCookie(FormsAuthentication.FormsCookieName,
                                                        FormsAuthentication.Encrypt(authTicket));
                        cookie.HttpOnly = true;
                        cookie.Expires  = model.RememberMe ? DateTime.Now.AddDays(2d) : DateTime.Now.AddMinutes(120);
                        Response.Cookies.Add(cookie);

                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return(Redirect(Dy.Common.UrlHelper.Decode(returnUrl)));
                        }
                        else if (model.Password != ((int)GrassrootsFloodCtrlEnums.InitialPasswordEnums.初始密码).ToString() || model.UserName == "dxz")
                        {
                            var userrole = HostContext.Resolve <SysService>().GET(new GetUserByIdOrUserName()
                            {
                                UserName = model.UserName
                            });
                            if (null != userrole && userrole.RoleID == (int)GrassrootsFloodCtrlEnums.RoleEnums.县级用户)
                            {
                                return(RedirectToAction("CountyIndex", "Audit"));
                            }
                            else if (null != userrole && userrole.RoleID == (int)GrassrootsFloodCtrlEnums.RoleEnums.市级用户)
                            {
                                return(RedirectToAction("CityIndex", "Audit"));
                            }
                            else if (null != userrole && userrole.RoleID == (int)GrassrootsFloodCtrlEnums.RoleEnums.省级用户)
                            {
                                return(RedirectToAction("Index", "ComprehensiveApp"));
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Home"));
                            }
                        }
                        else
                        {
                            return(RedirectToAction("ModificationPsaaword", "Home"));
                        }
                        #endregion
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "验证失败,用户名或密码错误。"); // +e.Message
                }
            }

            return(View(model));
        }