public void Login_InvalidCredentialsRedisplaysLoginScreen()
        {
            string returnUrl = "/Home/Index";
            string userName = "******";
            string password = "******";

            WebSecurity.Setup(s => s.Login(userName, password, false)).Returns(false);
            var model = new LoginModel
            {
                UserName = userName,
                Password = password
            };

            var result = Controller.Login(model, returnUrl) as ViewResult;
            Assert.IsNotNull(result);
        }
        public void Login_UserCanLogin()
        {
            string returnUrl = "/Home/Index";
            string userName = "******";
            string password = "******";

            WebSecurity.Setup(s => s.Login(userName, password, false)).Returns(true);
            var model = new LoginModel
            {
                UserName = userName,
                Password = password
            };

            var result = Controller.Login(model, returnUrl) as RedirectResult;
            Assert.IsNotNull(result);
            Assert.AreEqual(returnUrl, result.Url);
        }
Ejemplo n.º 3
0
        public ActionResult Login(LoginModel model, String returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, 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);
        }