[Fusionforge-commits] r12872 - in trunk/src/plugins/authopenid: . db include www

Olivier Berger olberger at fusionforge.org
Mon Mar 21 19:13:33 CET 2011


Author: olberger
Date: 2011-03-21 19:13:33 +0100 (Mon, 21 Mar 2011)
New Revision: 12872

Added:
   trunk/src/plugins/authopenid/db/
   trunk/src/plugins/authopenid/db/authopenid.sql
Modified:
   trunk/src/plugins/authopenid/include/AuthOpenIDPlugin.class.php
   trunk/src/plugins/authopenid/www/post-login.php
Log:
Now, using the DB

Added: trunk/src/plugins/authopenid/db/authopenid.sql
===================================================================
--- trunk/src/plugins/authopenid/db/authopenid.sql	                        (rev 0)
+++ trunk/src/plugins/authopenid/db/authopenid.sql	2011-03-21 18:13:33 UTC (rev 12872)
@@ -0,0 +1,4 @@
+CREATE TABLE plugin_authopenid_user_identities (user_id INTEGER NOT NULL,
+	openid_identity text);
+CREATE UNIQUE INDEX idx_authopenid_user_identities_openid_identity on plugin_authopenid_user_identities(openid_identity);
+

Modified: trunk/src/plugins/authopenid/include/AuthOpenIDPlugin.class.php
===================================================================
--- trunk/src/plugins/authopenid/include/AuthOpenIDPlugin.class.php	2011-03-21 18:13:24 UTC (rev 12871)
+++ trunk/src/plugins/authopenid/include/AuthOpenIDPlugin.class.php	2011-03-21 18:13:33 UTC (rev 12872)
@@ -53,7 +53,6 @@
 		$this->saved_login = '';
 		$this->saved_user = NULL;
 
-		//$this->openid = new LightOpenID;
 		$this->openid = FALSE;
 		
 		$this->openid_identity = FALSE;
@@ -77,27 +76,6 @@
 		}
 	}
 	
-	/*
-	private static $init = false;
-
-	function initCAS() {
-		if (self::$init) {
-			return;
-		}
-
-		phpCAS::client(forge_get_config('cas_version', $this->name),
-			       forge_get_config('cas_server', $this->name),
-			       intval(forge_get_config('cas_port', $this->name)),
-			       '');
-		if (forge_get_config('validate_server_certificate', $this->name)) {
-			// TODO
-		} else {
-			phpCAS::setNoCasServerValidation();
-		}
-
-		self::$init = true;
-	}
-*/
 	/**
 	 * Display a form to input credentials
 	 * @param unknown_type $params
@@ -109,8 +87,6 @@
 		}
 		$return_to = $params['return_to'];
 
-		//$this->initCAS();
-
 		$result = '';
 
 		$result .= '<p>';
@@ -123,17 +99,9 @@
 Your OpenID identifier: <input type="text" name="openid_identifier" /> 
 <input type="submit" name="login" value="' . _('Login via OpenID') . '" />
 </form>';
-/*
-		$result .= '<form action="' . util_make_url('/plugins/authcas/post-login.php') . '" method="get">
-<input type="hidden" name="form_key" value="' . form_generate_key() . '"/>
-<input type="hidden" name="return_to" value="' . htmlspecialchars(stripslashes($return_to)) . '" />
-<p><input type="submit" name="login" value="' . _('Login via CAS') . '" />
-</p>
-</form>' ;
-*/
+
 		$params['html_snippets'][$this->name] = $result;
 
-		//$params['transparent_redirect_urls'][$this->name] = util_make_url('/plugins/authcas/post-login.php?return_to='.htmlspecialchars(stripslashes($return_to)).'&login=1');
 	}
 
     /**
@@ -142,8 +110,6 @@
 	 */
 	
 	function checkAuthSession(&$params) {
-		print_r('AuthOpenIDPlugincheckAuthSession');
-		print_r($params);
 		$this->saved_user = NULL;
 		$user = NULL;
 
@@ -153,7 +119,7 @@
 			$user_id = $this->checkSessionCookie();
 		}
 		if ($user_id) {
-			$this->saved_user = user_get_object($user_id);
+			$user = user_get_object($user_id);
 		} else {
 			if ($this->openid && $this->openid->identity) {
 				$user_id = $this->getUserIdFromOpenIDIdentity($this->openid->identity);
@@ -181,22 +147,22 @@
 	}
 
 	protected function getUserIdFromOpenIDIdentity($openid_identity) {
-		if ($openid_identity == 'http://www-public.it-sudparis.eu/~berger_o/') {
-			return 'admin';
-		} else {
-			return FALSE;
+		$user_id = FALSE;
+		$res = db_query_params('SELECT user_id FROM plugin_authopenid_user_identities WHERE openid_identity=$1',
+							    array($openid_identity));
+		if($res) {
+			$row = db_fetch_array_by_row($res, 0);
+			if($row) {
+				$user_id = $row['user_id'];
+			}
 		}
+		return $user_id;
 	}
 	/**
 	 * What GFUser is logged in?
 	 * @param unknown_type $params
 	 */
 	/*
-	function fetchAuthUser(&$params) {
-		if ($this->saved_user && $this->isSufficient()) {
-			$params['results'] = $this->saved_user;
-		}
-	}
 
 	function closeAuthSession($params) {
 		$this->initCAS();

Modified: trunk/src/plugins/authopenid/www/post-login.php
===================================================================
--- trunk/src/plugins/authopenid/www/post-login.php	2011-03-21 18:13:24 UTC (rev 12871)
+++ trunk/src/plugins/authopenid/www/post-login.php	2011-03-21 18:13:33 UTC (rev 12872)
@@ -53,7 +53,7 @@
 if (forge_get_config('use_ssl') && !session_issecure()) {
 	//force use of SSL for login
 	// redirect
-	header('Location: https://'.getStringFromServer('HTTP_HOST').getStringFromServer('REQUEST_URI'));
+	session_redirect_external('https://'.getStringFromServer('HTTP_HOST').getStringFromServer('REQUEST_URI'));
 }
 
 try {
@@ -66,7 +66,7 @@
 		// We're just called by the login form : redirect to the OpenID provider
         if(isset($_POST['openid_identifier'])) {
             $plugin->openid->identity = $_POST['openid_identifier'];
-            header('Location: ' . $plugin->openid->authUrl());
+            session_redirect_external($plugin->openid->authUrl());
         }
         
     // or we are called back by the OpenID provider
@@ -86,11 +86,9 @@
 			if ($return_to) {
 				validate_return_to($return_to);
 	
-				header ("Location: " . util_make_url($return_to));
-				exit;
+				session_redirect($return_to);
 			} else {
-				header ("Location: " . util_make_url("/my"));
-				exit;
+				session_redirect("/my");
 			}
 		}
     }




More information about the Fusionforge-commits mailing list