public void AuthenticationController_TrySignInUsingUnexistingUser_ReturnSearchPage()
        {
            string login    = "******";
            string password = "******";
            AuthenticationUserVM authUser = new AuthenticationUserVM()
            {
                Login = login, Password = password
            };

            Mock <IAuthenticationUserLogic> authLogic = new Mock <IAuthenticationUserLogic>();

            authLogic.Setup(t => t.TryAuthentication(login, password)).Verifiable();

            AuthenticationUserController authController = new AuthenticationUserController(authLogic.Object, Mock.Of <ICustomLogger>());
            ActionResult result = authController.SignIn(authUser);

            Assert.IsAssignableFrom <ViewResult>(result);
            authLogic.VerifyAll();
        }
Ejemplo n.º 2
0
        public ActionResult SignIn(AuthenticationUserVM authUserVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    User user = _authUserLogic.TryAuthentication(authUserVM.Login, authUserVM.Password);
                    if (user != null)
                    {
                        CookieUser cookieUser = PLAutomapper.Mapper.Map <CookieUser>(user);

                        var encTicket = FormsAuthentication.Encrypt(
                            new FormsAuthenticationTicket(
                                1,
                                "name",
                                DateTime.Now,
                                DateTime.Now.Add(FormsAuthentication.Timeout),
                                false,
                                JsonConvert.SerializeObject(cookieUser))
                            );
                        HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                        Response.Cookies.Add(faCookie);

                        return(RedirectToAction("Search", "Report"));
                    }

                    ModelState.AddModelError("Login", "You entered incorrect passord or login doesn't exist");
                }

                return(View(authUserVM));
            }
            catch (Exception e)
            {
                _customLogger.RecordError(e);
                return(new HttpStatusCodeResult(500));
            }
        }