[pLog-svn] r2187 - plog/trunk/class/dao/userdata

oscar at devel.plogworld.net oscar at devel.plogworld.net
Fri Jun 10 09:00:02 GMT 2005


Author: oscar
Date: 2005-06-10 09:00:01 +0000 (Fri, 10 Jun 2005)
New Revision: 2187

Modified:
   plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php
Log:
this is already *roughly* working. It will work with a phpbb installation
as long as the user ids in both databases match. You can authenticate against it,
but not add update or remove new users. User statuses won't work yet, either.


Modified: plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php	2005-06-09 14:09:09 UTC (rev 2186)
+++ plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php	2005-06-10 09:00:01 UTC (rev 2187)
@@ -1,10 +1,7 @@
 <?php
 
     include_once( PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/userstatus.class.php" );
+    include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
     
     /**
      * Model representing the users in our application. Provides the methods such as
@@ -14,6 +11,8 @@
      */
     class PhpBB2UserDataProvider extends BaseUserDataProvider
     {
+	    var $_db;
+	    var $_prefix;
 
         /**
          * Initializes the model
@@ -21,6 +20,18 @@
         function PhpBB2UserDataProvider( $providerConfig )
         {
             $this->BaseUserDataProvider( $providerConfig );
+            
+            // initialize the database connection based on our parameters
+            $config = $this->getProviderConfiguration();
+            $user = $config->getValue( "user" );
+            $pass = $config->getValue( "password" );
+            $host = $config->getValue( "host" );
+            $db = $config->getValue( "database" );
+            $this->_phpbbprefix = $config->getValue( "prefix" );
+            
+
+            
+            $this->_dbc =& Db::getNewDb( $host, $user, $pass, $db );                     
         }
 
         /**
@@ -32,7 +43,22 @@
          * @return true if user and password correct or false otherwise.
          */
         function authenticateUser( $user, $pass )
-        {        
+        {
+	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE username = '".Db::qstr( $user )."'
+	                  AND user_password = '".md5( $pass )."' AND user_active = 1";
+	                  
+	        $result = $this->_dbc->Execute( $query );
+	        
+	        if( !$result )
+	        	return false;
+	        	
+            if( $result == false )
+                return false;
+
+            if( $result->RecordCount() == 1 )
+                return true;
+            else
+                return false;    	
         }
 
         /**
@@ -44,6 +70,17 @@
          */
         function getUserInfo( $user, $pass )
         {
+	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE username = '".Db::qstr( $user )."'
+	                  AND user_password = '".md5( $pass )."'";
+	                  
+	        $result = $this->_dbc->Execute( $query );
+	        
+	        if( !$result )
+	        	return false;
+	        	
+	        $row = $result->FetchRow();
+	        
+	        return( $this->_mapUserInfoObject( $row ));	        
         }
 
         /**
@@ -54,6 +91,16 @@
          */
         function getUserInfoFromUsername( $username )
         {
+	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE username = '".Db::qstr( $username )."'";
+	                  
+	        $result = $this->_dbc->Execute( $query );
+	        
+	        if( !$result )
+	        	return false;
+	        	
+	        $row = $result->FetchRow();
+	        
+	        return( $this->_mapUserInfoObject( $row ));	        
         }
 
         /**
@@ -64,7 +111,29 @@
          */
         function getUserInfoFromId( $userid, $extendedInfo = false )
         {
+	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE user_id = '".Db::qstr( $userid )."'";
+	                  
+	        $result = $this->_dbc->Execute( $query );
+	        
+	        if( !$result )
+	        	return false;
+	        	
+	        $row = $result->FetchRow();
+	        
+	        return( $this->_mapUserInfoObject( $row ));
         }
+        
+        function _mapUserInfoObject( $row )
+        {
+	    	$user = new UserInfo( $row["username"], $row["user_password"], $row["user_email"],
+	    	                      "", // TODO: this is the 'about myself' field that should be got from somewhere!
+	    	                      "", // TODO: the user full name is not available in phpbb
+	    	                      0, // TODO: the resource picture id is not available in phpbb
+	    	                      Array(), // TODO: the user properties are not available in phpbb
+	    	                      $row["user_id"] );
+	    	                      
+	    	return( $user );
+        }
 
         /**
          * Returns an array with all the users available in the database
@@ -136,6 +205,7 @@
          */
         function userExists( $userName )
         {
+	        return( $this->getUserInfoFromUsername( $userName ));
         }
 
         /**




More information about the pLog-svn mailing list