コード例 #1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            ModelState.AddModelError("", "提供的用户名或密码不正确。");
            return View(model);
        }
コード例 #4
0
 public ActionResult Login(LoginModel model, string returnUrl)
 {
     var myAuthenticator = new Web.Models.Authenticate();
     if (ModelState.IsValid && myAuthenticator.IsAuthenticated(model.UserName,model.Password))
     {
         Session["User"] = model.UserName.Split('@')[0];
         return RedirectToLocal(returnUrl);
     }
     ModelState.AddModelError("", "The user name or password provided is incorrect.");
     return View(model);
 }
コード例 #5
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if(ModelState.IsValid) 
            {
                if (_auth.Authenticate(model.Email, model.Password))
                {
                    return returnUrl == null ? _redirect.ToDashboard(model.Email) : _redirect.ToUrl(returnUrl);
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            return View("Index", model);
        }
コード例 #6
0
        public void Login_Post_Success_With_ReturnUrl()
        {
            // arrange
            var service = new Mock<IAuthenticationService>();
            var redirect = new RedirectService();
            var controller = new LoginController(service.Object, redirect);
            var model = new LoginModel() { Email = "*****@*****.**", Password = "******" };

            service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(true);

            //act
            var result = controller.Login(model, "somewhere") as RedirectResult;

            //assert
            Assert.That(result.Url, Is.EqualTo("somewhere"));
        }
コード例 #7
0
        public void Login_Post_Success()
        {
            // arrange
            var service = new Mock<IAuthenticationService>();
            var redirect = new RedirectService();
            var controller = new LoginController(service.Object, redirect);
            var model = new LoginModel() { Email = "*****@*****.**", Password = "******" };

            service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(true);
            
            //act
            var result = controller.Login(model, null) as RedirectResult;

            //assert
            result.Url.Should().Be("~/user/[email protected]");
        }
コード例 #8
0
        public JsonResult JsonLogin(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    return Json(new {success = true, redirect = returnUrl});
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed
            return Json(new {errors = GetErrorsFromModelState()});
        }
コード例 #9
0
ファイル: AuthController.cs プロジェクト: thunderbird84/VCms
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            try
            {

                Boolean authenticated = false;
                authenticated = Auth.Authenticate(model.UserName, model.Password, null, true);

                if (authenticated)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    return RedirectToAction("Index", "Home");
                }
            }
            catch (Exception exception)
            {
                ViewBag.HasError = true;
                ModelState.AddModelError("", exception.Message);
            }
            return View(model);
        }
コード例 #10
0
        public ActionResult Index(LoginModel loginModel)
        {
            if (!ModelState.IsValid) {
                return View(loginModel);
            }

            if (!authenticator.Authenticate(loginModel.EmailAddress, loginModel.Password)) {
                return View(loginModel);
            }

            return Json(true);
        }
コード例 #11
0
        public void Login_Post_Fail()
        {
            // arrange
            var service = new Mock<IAuthenticationService>();
            var redirect = new RedirectService();
            var controller = new LoginController(service.Object, redirect);
            var model = new LoginModel() { Email = "*****@*****.**", Password = "******" };

            service.Setup(s => s.Authenticate("*****@*****.**", "xxx")).Returns(false);

            //act
            var result = controller.Login(model, "somewhere") as ViewResult;

            //assert
            Assert.That(controller.ModelState[""].Errors[0].ErrorMessage, Is.EqualTo("The user name or password provided is incorrect."));
        }