public ActionResult Login(LogOnViewModel model)
 {
     var user =
         _userRepository.Users.FirstOrDefault(
             x => x.EmailAddress == model.UserName && x.PasswordSalt == model.Password);
     if (user != null)
     {
         Helpers.AuthHelper.LogInUser(HttpContext, user.rowguid.ToString());
     }
     return RedirectToAction("List", "Product");
 }
Beispiel #2
0
 public ActionResult LogOn(LogOnViewModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         if (authProvider.Authenticate(model.UserName, model.Password))
         {
             if (System.Web.HttpContext.Current.User.IsInRole("admin"))
             {
                 return Redirect(returnUrl ?? Url.Action("Index", "Admin"));
             }
             return Redirect(returnUrl ?? Url.Action("List", "Product"));
         }
         ModelState.AddModelError("","User name or Password where incorrect.");
     }
     return View();
 }
Beispiel #3
0
        public ActionResult LogOn(LogOnViewModel model,string returnUrl)
        {
            if(ModelState.IsValid)
            {
                if(authProvider.Authenticate(model.UserName, model.Password))
                {
                    var red = Redirect(returnUrl ?? Url.Action("Index", "Admin"));
                    return red;
                }
                else
                {
                    ModelState.AddModelError("", "Неправильное имя или пароль");
                    return View();
                }

            }
            else
            {
                return View();
            }
        }
Beispiel #4
0
        public void Can_Login_With_Valid_Credentials()
        {
            var mock = new Mock<IAuthProvider>();
            mock.Setup(m => m.Authenticate("admin", "secret")).Returns(true);

            var model = new LogOnViewModel
                {
                    UserName = "******",
                    Password = "******"
                };

            var target = new AccountController(mock.Object);
            // аутентификация с использованием правильных учетных данных
            var result = target.LogOn(model, "/MyURL");

            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            Assert.AreEqual("/MyURL", ((RedirectResult)result).Url);
        }