Example #1
0
        public IActionResult Index(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool login = Servico.ValidarLogin(model.Email, model.Senha);

                var usuario = Servico.RetornarDadosUsuario(model.Email, model.Senha);

                if (login)
                {
                    // colocar dados do usuario na sessão
                    httpContextAccessor.HttpContext.Session.SetString(Sessao.NOME_USUARIO, usuario.Nome);
                    httpContextAccessor.HttpContext.Session.SetString(Sessao.EMAIL_USUARIO, usuario.Email);
                    httpContextAccessor.HttpContext.Session.SetInt32(Sessao.CODIGO_USUARIO, (int)usuario.Codigo);
                    httpContextAccessor.HttpContext.Session.SetInt32(Sessao.LOGADO, 1);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewData["ErroLogin"] = "******";
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }
 public IActionResult Index(LoginViewModel model)
 {
     ViewData["ErroLogin"] = string.Empty;
     if (ModelState.IsValid)
     {
         var  Senha   = Criptografia.GetMd5Hash(model.Senha);
         bool login   = servicoAplicacaoUsuario.ValidarLogin(model.Email, Senha);
         var  usuario = servicoAplicacaoUsuario.RetornarDadosDoUsuario(model.Email, Senha);
         if (login)
         {
             httpContextAcessor.HttpContext.Session.SetString(Sessao.NOME_USUARIO, usuario.Nome);
             httpContextAcessor.HttpContext.Session.SetString(Sessao.EMAIL_USUARIO, usuario.Email);
             httpContextAcessor.HttpContext.Session.SetInt32(Sessao.CODIGO_USUARIO, (int)usuario.Codigo);
             httpContextAcessor.HttpContext.Session.SetInt32(Sessao.LOGADO_USUARIO, 1);
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ViewData["ErroLogin"] = "******";
             return(View(model));
         }
     }
     else
     {
         return(View());
     }
 }
Example #3
0
        public IActionResult Index(LoginViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                string senha = Criptografia.GetHash(viewModel.Senha);

                bool logou   = servicoAplicacaoUsuario.ValidarLogin(viewModel.Email, senha);
                var  usuario = servicoAplicacaoUsuario.RetornarDadosUsuario(viewModel.Email, senha);

                if (logou)
                {
                    httpContextAccessor.HttpContext.Session.SetString(Sessao.NOME_USUARIO, usuario.Nome);
                    httpContextAccessor.HttpContext.Session.SetString(Sessao.EMAIL_USUARIO, usuario.Email);
                    httpContextAccessor.HttpContext.Session.SetInt32(Sessao.CODIGO_USUARIO, (int)usuario.Codigo);
                    httpContextAccessor.HttpContext.Session.SetInt32(Sessao.LOGADO, 1);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewData["ErroLogin"] = "******";
                    return(View(viewModel));
                }
            }
            else
            {
                return(View(viewModel));
            }
        }
Example #4
0
 public IActionResult ValidaLogin(UsuarioViewModel viewModel)
 {
     //Verifica se o formulário está preenchido de forma correta
     if (ModelState.IsValid)
     {
         bool login = ServicoAplicacaoUsuario.ValidarLogin(viewModel.Email, cripto.Encrypt(viewModel.Senha.Trim()));
         if (!login)
         {
             ViewData["ErroLogin"] = "******";
             //return Ok(viewModel);
             return(RedirectToAction("Index"));
         }
         else
         {
             var usuario = ServicoAplicacaoUsuario.DadosUsuario(viewModel.Email, cripto.Encrypt(viewModel.Senha.Trim()));
             HttpContextAccesssor.HttpContext.Session.SetString(Sessao.NOME_USUARIO, usuario.Nome);
             HttpContextAccesssor.HttpContext.Session.SetString(Sessao.EMAIL_USUARIO, usuario.Email);
             HttpContextAccesssor.HttpContext.Session.SetInt32(Sessao.CODIGO_USUARIO, (int)usuario.Codigo);
             HttpContextAccesssor.HttpContext.Session.SetInt32(Sessao.LOGADO, 1);
             return(RedirectToAction("Index", "Home"));
         }
     }
     return(RedirectToAction("Index"));
 }