public ActionResult Login(LoginViewModel viewModel)
        {
            var apresentador = new LoginApresentador();
            var requisicao = new LoginRequisicao
            {
                Email = viewModel.Email,
                Senha = viewModel.Senha
            };

            this.loginExecutor.Apresentador = apresentador;
            this.loginExecutor.Executar(requisicao);

            if (apresentador.UsuarioExiste)
            {
                //create the authentication ticket
                var authTicket = new FormsAuthenticationTicket(
                  1,
                  viewModel.Email,  //user id
                  DateTime.Now,
                  DateTime.Now.AddMinutes(20),  // expiry
                  true,  //true to remember
                  "", //roles
                  "/"
                );

                //encrypt the ticket and add it to a cookie
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
                Response.Cookies.Add(cookie);
                return RedirectToAction("Index", "Blog");
            }

            return View();
        }
Esempio n. 2
0
 public void SetUp()
 {
     executor = new LoginExecutor(new UsuarioRepositorioMock(), new GeradorDeHashComSaltMock());
     apresentador = new LoginApresentadorSpy();
     executor.Apresentador = apresentador;
     requisicao = new LoginRequisicao();
 }