Esempio n. 1
0
        public virtual ActionResult Ajax(LoginModel loginModel, int redirect)
        {
            var data = new JsonResultData(ModelState);
            if (ModelState.IsValid)
            {
                data.RunWithTry((resultData) =>
                {
                    if (UserServices.ValidateUser(loginModel.UserName, loginModel.Password) != null)
                    {
                        System.Web.Security.FormsAuthentication.SetAuthCookie(loginModel.UserName, loginModel.RememberMe);
                        if (redirect == 0)
                        {
                            resultData.RedirectUrl = Request.UrlReferrer.ToString();
                        }
                        else
                        {
                            resultData.RedirectUrl = System.Web.Security.FormsAuthentication.DefaultUrl;
                        }

                    }
                    else
                    {
                        resultData.AddFieldError("UserName", "Username and/or password are incorrect.".Localize());
                    }
                });
            }
            return Json(data);
        }
Esempio n. 2
0
        public virtual ActionResult Index(LoginModel loginModel, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var isLockout = false;
                if (UserManager.ValidateUser(loginModel.UserName, loginModel.Password, out isLockout) != null)
                {
                    System.Web.Security.FormsAuthentication.SetAuthCookie(loginModel.UserName, loginModel.RememberMe);

                    if (loginModel.RedirectToHome)
                    {
                        return Redirect(Url.Content("~/"));
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(returnUrl))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return Redirect(System.Web.Security.FormsAuthentication.DefaultUrl);
                        }
                    }
                }
                else
                {
                    if (isLockout)
                    {
                        ModelState.AddModelError("", "Your account has been locked for security reasons, please contact the admin.".Localize());
                    }
                    else
                    {
                        ModelState.AddModelError("", "Username and/or password are incorrect.".Localize());
                    }

                }
            }
            return View();
        }