Partial rewrite of auth.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 25 May 2008 22:13:20 +0000 (00:13 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 25 May 2008 22:13:20 +0000 (00:13 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
_public.php
class.xorg.auth.php

index 2b00670..84d05da 100644 (file)
@@ -15,14 +15,16 @@ class xorgAuthWidget {
 
 class xorgAuthentifier extends dcUrlHandlers {
   static public function doAuth($args) {
-    @session_start();
     global $core;
     switch ($args) {
      case 'exit':
       $core->auth->killSession();
       break;
      case 'Xorg':
-      $core->auth->callXorg();
+      if ($core->auth->callXorg($_GET['path'])) {
+        header('Location: http://murphy.m4x.org' . $_GET['path']);
+        exit;
+      }
       break;
      case 'XorgReturn':
       $core->auth->returnXorg();
index 4d47927..0b00ae4 100644 (file)
@@ -7,9 +7,17 @@ class xorgAuth extends dcAuth {
                              'prenom' => null,
                              'nom' => null);
 
-  public function __construct() {
-    @session_start();
-    if (@$_SESSION['auth-xorg']) {
+  public function __construct(&$core) {
+    parent::__construct($core);
+  }
+
+  private function buildFromSession() {
+    global $core;
+    if (!isset($core) || !isset($core->session)) {
+      return;
+    }
+    $core->session->start();
+    if (@$_SESSION['auth-xorg'] && is_null($this->xorg_infos['forlife'])) {
       foreach ($this->xorg_infos as $key => $val) {
         $this->xorg_infos[$key] = $_SESSION['auth-xorg-' . $key];
       }
@@ -17,19 +25,24 @@ class xorgAuth extends dcAuth {
   }
 
   public function checkUser($user_id, $pwd = null, $user_key = null) {
+    return $this->callXorg();
 //    echo "checking auth for " . $user_id;
     return parent::checkUser($user_id, $pwd, $user_key);
   }
 
   public function check($permissions, $blog_id) {
+     $this->buildFromSession();
 //    echo "Checking right to view $permissions on $blog_id";
     return parent::check($permissions, $blog_id);
   }
 
-  public function callXorg() {
+  public function callXorg($path = null) {
+    if (is_null($path)) {
+      $path = $_SERVER['REQUEST_URI'];
+    }
+    $this->buildFromSession();
     if (@$_SESSION['auth-xorg']) {
-      header("Location: http://murphy.m4x.org" . $_GET['path']);
-      return;
+      return true;
     }
     $_SESSION["auth-x-challenge"] = md5(uniqid(rand(), 1));
     $url = "https://www.polytechnique.org/auth-groupex/utf8";
@@ -47,27 +60,31 @@ class xorgAuth extends dcAuth {
       return false;
     }
     $params = '';
+    global $core;
+    $core->session->start();
     foreach($this->xorg_infos as $key => $val) {
       if(!isset($_GET[$key])) {
         return false;
       }
       $_SESSION['auth-xorg-' . $key] = $_GET[$key];
-      $this->xorg_infos[$key] = $_GET[$key];
       $params .= $_GET[$key];
     }
     if (md5('1' . $_SESSION['auth-x-challenge'] . XORG_AUTH_KEY . $params . '1') == $_GET['auth']) {
       unset($_GET['auth']);
       $_SESSION['auth-xorg'] = $_GET['forlife'];
       header("Location: http://murphy.m4x.org" . $_GET['path']);
-      return true;
+      exit;
     }
     $_SESSION['auth-xorg'] = null;
     unset($_GET['auth']);
+    echo "Failed !!!";
     return false;
   }
 
   public function killSession() {
-    @session_destroy();
+    global $core;
+    $core->session->start();
+    $core->session->destroy();
     header('Location: http://murphy.m4x.org/~x2003bruneau/dotclear/');
     exit;
   }