src/Controller/CustomController.php line 67

Open in your IDE?
  1. <?php 
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use phpCAS;
  8. class CustomController extends AbstractController {
  9.     protected $isAuth false;
  10.     protected $userEmail '';
  11.     protected function selectFromWhere($table$opt_where ''$order_by " D_MODIFICATION desc " $DBG false):array {
  12.         $out = array();
  13.     if (!empty($table)) {
  14.         $RAW_QUERY "select * from ".$table
  15.             . (!empty($opt_where) ? ' where '.$opt_where '')
  16.             . (!empty($order_by) ? ' order by '.$order_by '')
  17.             ;
  18.         // echo(__METHOD__.' RAW_QUERY: '.$RAW_QUERY);
  19.         if ($DBG != false) {
  20.             echo(__METHOD__
  21.             ': RAW_QUERY: '.$RAW_QUERY
  22.             );
  23.         }
  24.         $found $this->selectRaw($RAW_QUERY$DBG);
  25.         /*
  26.         if (count($found) == 1) {
  27.             $out = $found[0];
  28.         } else 
  29.         // */
  30.         // {
  31.             $out $found;
  32.         // }
  33.     }
  34.     if ($DBG != false) {
  35.         echo(__METHOD__
  36.             // . ': RAW_QUERY: '.$RAW_QUERY
  37.             .': out: '.var_export($outtrue));
  38.     }
  39.     return $out;
  40.     }
  41.    protected function selectRaw($RAW_QUERY$DBG false) : array {
  42.         $out = array();
  43.         if (!empty($RAW_QUERY)) {
  44.             $em $this->getDoctrine()->getManager();
  45.             $statement $em->getConnection()->prepare($RAW_QUERY);
  46.             // Set parameters 
  47.             // $statement->bindValue('status', 1);
  48.             $res $statement->execute();
  49.             $results $res->fetchAllAssociative();
  50.             if (count($results) > 0) {
  51.                 $out $results;
  52.             }
  53.         }
  54.     if ($DBG) {
  55.         echo(__METHOD__
  56.             ': SQL: '.$RAW_QUERY
  57.             .':   out: 'var_export($outtrue));
  58.     }
  59.     return $out;
  60.     }
  61.     public function testConnection($connection) {
  62.     // $conf = $connection->getConfiguration()->get('DATABASE_URL');
  63.     // echo(__METHOD__.' conf: '.var_export($conf, true)); exit();
  64.     $databaseUrl $_ENV['DATABASE_URL'];
  65.     echo(var_export($databaseUrl));
  66. $conn oci_connect($connection->getUsername(), $connection->getPassword(), $connection->getHost().'/GRHV4'); // ('EASYID', '******', 'am-oracle-4/GRHV4');
  67. if (!$conn) {
  68.     $e oci_error();
  69.     trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  70. }
  71. $stid oci_parse($conn'SELECT * FROM VCARD');
  72. oci_execute($stid);
  73. echo "<table border='1'>\n";
  74. while ($row oci_fetch_array($stidOCI_ASSOC+OCI_RETURN_NULLS)) {
  75.     echo "<tr>\n";
  76.     foreach ($row as $item) {
  77.         echo "    <td>" . ($item !== null htmlentities($itemENT_QUOTES) : "") . "</td>\n";
  78.     }
  79.     echo "</tr>\n";
  80. }
  81. echo "</table>\n";
  82. echo(__METHOD__.': '
  83.     .'Connection: 'var_export($connection->getPassword(), true)
  84.     .'User: 'var_export($connection->getUsername(), true)
  85.     .'Host: 'var_export($connection->getHost(), true)
  86.     // .'Host: '. var_export($connection->getTnsname(), true)
  87. ); 
  88. exit();
  89.     }
  90.     protected function redirectToAuth($current_route null) {
  91.         $args = array();
  92.         if (!empty($current_route)) {
  93.             $args['referer'] = $current_route;
  94.         }
  95.         $this->redirectToRoute('app_v_card_auth'$argsResponse::HTTP_SEE_OTHER);
  96.         exit();
  97.     }
  98.     protected function getAuthCAS($request) : string {
  99.     $out '';
  100.     // Load the settings from the central config file
  101. require_once 'config_CAS.php';
  102. // Load the CAS lib
  103.     // echo(__METHOD__.': phpcas_path: '.$phpcas_path); exit();
  104. require_once $phpcas_path '/CAS.php';
  105. // Enable debugging
  106. phpCAS::setLogger();
  107. // Enable verbose error messages. Disable in production!
  108. phpCAS::setVerbose(true);
  109. // Initialize phpCAS
  110. phpCAS::client(CAS_VERSION_2_0$cas_host$cas_port$cas_context$client_service_name);
  111. // For production use set the CA certificate that is the issuer of the cert
  112. // on the CAS server and uncomment the line below
  113. // phpCAS::setCasServerCACert($cas_server_ca_cert_path);
  114. // For quick testing you can disable SSL validation of the CAS server.
  115. // THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION.
  116. // VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL!
  117. phpCAS::setNoCasServerValidation();
  118.         // force CAS authentication
  119.         phpCAS::forceAuthentication();
  120. // at this step, the user has been authenticated by the CAS server
  121. // and the user's login name can be read with phpCAS::getUser().
  122. //    echo(__METHOD__.': authenticated!'); exit();
  123. // logout if desired
  124. if (isset($_REQUEST['logout'])) {
  125.     phpCAS::logout();
  126. } else {
  127.     $session $request->getSession();
  128.     $this->isAuth true;
  129.     $out =  $this->userEmail phpCAS::getUser();
  130.     $session->set('is_auth'$this->isAuth);
  131.     $session->set('user_email'$this->userEmail);
  132. }
  133.     // echo(__METHOD__.': Hello '.phpCAS::getUser());
  134.     return $out;
  135.     }
  136. }