コード例 #1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (WebSecurity.IsAccountLockedOut(model.DisplayName, 3, 300))
            {
                ModelState.AddModelError("", "Your account has been locked due to excessive log in failures. Please try again in 5 minutes.");
                return View(model);
            }

            //else if (WebSecurity.GetPasswordFailuresSinceLastSuccess(model.DisplayName) == 2)
            //{
            //    ModelState.AddModelError("", "Warning! One more unsuccessful login attempt and your account will be locked.");
            //    return View(model);
            //}
            else if (ModelState.IsValid && WebSecurity.Login(model.DisplayName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
コード例 #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (WebSecurity.IsAccountLockedOut(model.DisplayName, 3, 300))
                {
                    ModelState.AddModelError("", "Your account has been locked due to excessive log in failures. Please try again in 5 minutes.");
                    return View(model);
                }

                if (Membership.ValidateUser(model.DisplayName, model.Password))
                {

                    if (Roles.GetRolesForUser(model.DisplayName).Contains("Administrator"))
                    {
                        ViewBag.toast = "<script> $(function () {" +
                               "toastr.options = { 'positionClass': 'toast-bottom-right' };" +
                               "toastr.error('You have to be a member to login to the member's site.');});</script>";

                        return View(model);
                    }

                    MigrateShoppingCart(model.DisplayName);
                    MigrateWishList(model.DisplayName);

                    FormsAuthentication.SetAuthCookie(model.DisplayName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }