Пример #1
0
        public ActionResult LogIn(LogInModel model)
        {
            //try
            //{
                if (_userService.ValidateUserPassword(model.UserName, model.Password))
                {
                    var user = _userService.GetOneUser(model.UserName);

                    if (HttpContext.Session != null)
                    {
                        HttpContext.Session["currentUserID"] = model.UserName;
                        HttpContext.Session["accessGroups"] = _accessGroupService.GetAccessGroupsForUser(user);
                    }

                    if (user.MustChangePassword)
                    {
                        return RedirectToAction("ChangePassword", "LogIn");
                    }

                    return RedirectToAction("Index", "Home");
                }
                TempData["Message"] = "Feil i brukernavn eller passord";
                return RedirectToAction("LogIn", "LogIn");
            //}
            //catch (Exception)
            //{
            //    TempData["Message"] = "Ukjent feil har oppstått";
            //    return RedirectToAction("LogIn", "LogIn");
            //}
        }
Пример #2
0
 public void HttpPostLogInShouldReturnReightViewWhenSuccessfullLogIn()
 {
     var model = new LogInModel {UserName = "******", Password = "******"};
     _userService.Setup(x => x.ValidateUserPassword(model.UserName, model.Password)).Returns(true);
     var result = (RedirectToRouteResult) _subject.LogIn(model);
     Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
     Assert.That(result.RouteValues["controller"], Is.EqualTo("Home"));
 }
Пример #3
0
        public void HttpPostShouldReturnRightViewWithMessageWhenFailedLogin()
        {
            var model = new LogInModel { UserName = "******", Password = "******" };
            _userService.Setup(x => x.ValidateUserPassword(model.UserName, model.Password)).Returns(false);
            var result = (RedirectToRouteResult)_subject.LogIn(model);

            Assert.That(_subject.TempData["Message"], Is.EqualTo("Feil i brukernavn eller passord"));
            Assert.That(result.RouteValues["action"], Is.EqualTo("LogIn"));
            Assert.That(result.RouteValues["controller"], Is.EqualTo("LogIn"));
        }