Example #1
0
 public function autenticar()
 {
     try {
         if (empty($_POST['email'])) {
             throw new \Exception('Informe o e-mail.');
         }
         if (empty($_POST['senha'])) {
             throw new \Exception('Informe a senha.');
         }
         $email = trim($_POST['email']);
         $senha = trim($_POST['senha']);
         $usuario = new Usuario();
         $usuario->email = $email;
         $usuario->senha = $senha;
         if (!empty($_POST['lembrarEmail'])) {
             // Expira em 30 dias
             setcookie("email", $email, time() + 2592000, '/');
         } else {
             setcookie("email", null, time() - 2592000, '/');
         }
         $usuario = $this->fachada->autenticar($usuario);
         $_SESSION['usuario'] = serialize($usuario);
         echo new JSONResponse(true, self::PAGINA_INICIAL);
     } catch (\Exception $e) {
         echo new JSONResponse(false, $e->getMessage());
     }
 }