[pLog-svn] r5357 - in plog/branches/lifetype-1.2/class/dao: . userdata

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sat Apr 28 10:07:08 EDT 2007


Author: oscar
Date: 2007-04-28 10:07:08 -0400 (Sat, 28 Apr 2007)
New Revision: 5357

Modified:
   plog/branches/lifetype-1.2/class/dao/userdata/baseuserdataprovider.class.php
   plog/branches/lifetype-1.2/class/dao/userdata/joomlauserdataprovider.class.php
   plog/branches/lifetype-1.2/class/dao/userdata/lifetypeuserdataprovider.class.php
   plog/branches/lifetype-1.2/class/dao/userdata/phpbb2userdataprovider.class.php
   plog/branches/lifetype-1.2/class/dao/userdata/simplepostnukeuserdataprovider.class.php
   plog/branches/lifetype-1.2/class/dao/userdata/vbb3userdataprovider.class.php
   plog/branches/lifetype-1.2/class/dao/userdata/wbbuserdataprovider.class.php
   plog/branches/lifetype-1.2/class/dao/userpermissions.class.php
Log:
This should fix the first one of the issues related to user data providers (the second one being wizard.php) Now new users will be granted the login_perm the first time they attempt to log in so that they can log in. I've only been able to test the phpbb2 integration and it seemed to work fine, so I copied the same code to the other user data provider classes. If you have a chance to test other integrations, please do so and let us know if there is any problem with them.


Modified: plog/branches/lifetype-1.2/class/dao/userdata/baseuserdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userdata/baseuserdataprovider.class.php	2007-04-28 12:58:07 UTC (rev 5356)
+++ plog/branches/lifetype-1.2/class/dao/userdata/baseuserdataprovider.class.php	2007-04-28 14:07:08 UTC (rev 5357)
@@ -207,11 +207,36 @@
          *
          * @param blogId The blog identifier.
          * @param includeOwner Wether to include the owner of the blog or not.
+         * @param status
+         * @param searchTerms
          * @return An array with the information about the users who belong in
          * one way or another to that blog.
          */
-        function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL )
+        function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL, $searchTerms = "" )
         {
+            $users = Array();
+	        $prefix = $this->getPrefix();
+
+            // get the information about the owner, if requested so
+            if( $includeOwner ) {
+				lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+				$blogs = new Blogs();
+				$blogInfo = $blogs->getBlogInfo( $blogId );				
+                array_push( $users, $this->getUserInfoFromId( $blogInfo->getOwnerId()));
+            }
+
+            // now get the other users who have permission for that blog.
+            $query2 = "SELECT DISTINCT user_id FROM {$prefix}users_permissions WHERE blog_id = '".Db::qstr( $blogId )."'";
+            $result2 = $this->Execute( $query2 );
+            if( !$result2 ) // if error, return what we have so far...
+                return $users;
+
+            while( $row = $result2->FetchRow()) {
+                array_push( $users, $this->getUserInfoFromId( $row["user_id"] ));
+            }
+            $result2->Close();
+
+            return $users;
         }
         
         /**
@@ -241,5 +266,31 @@
         function emailExists($email)
         {
         }
+
+		/**
+		 * @final
+		 * Grants the given user is the login_perm. This is something that all integrations
+		 * must use or else users won't be allowed to log in.
+		 *
+		 * @param userInfo A UserInfo object
+		 * @return True if successful or false otherwise
+		 */
+		function grantLoginPermission( $userInfo )
+		{
+			print( "granting permission to user: ".$userInfo->getUsername()." - id = ".$userInfo->getId()."<br/>" );
+			
+			lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );
+			lt_include( PLOG_CLASS_PATH."class/dao/userpermission.class.php" );
+			lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
+			
+			$perms = new Permissions();
+			$loginPerm = $perms->getPermissionByName( "login_perm" );
+			$perm = new UserPermission( $userInfo->getId(),    // user id
+			                            0,   // it's a global permission, no blog id needed
+			                            $loginPerm->getId()  // id of the permission
+			);
+			$userPerms = new UserPermissions();
+			$userPerms->grantPermission( $perm, true );
+		}		
 	}
 ?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/class/dao/userdata/joomlauserdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userdata/joomlauserdataprovider.class.php	2007-04-28 12:58:07 UTC (rev 5356)
+++ plog/branches/lifetype-1.2/class/dao/userdata/joomlauserdataprovider.class.php	2007-04-28 14:07:08 UTC (rev 5357)
@@ -175,6 +175,7 @@
         function JoomlaAddBlog( $row )
         {
 		    // create a new blog
+		    lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );				
 		    lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
@@ -260,6 +261,9 @@
 		        // check if this user is assigned to any blog
 		        $userBlogs = $userInfo->getBlogs();
 		        if( empty($userBlogs )) {
+					// assign the login_perm permission
+					$this->grantLoginPermission( $userInfo );
+								
 			        $this->JoomlaAddBlog( $row );
 			        $userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
      			}

Modified: plog/branches/lifetype-1.2/class/dao/userdata/lifetypeuserdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userdata/lifetypeuserdataprovider.class.php	2007-04-28 12:58:07 UTC (rev 5356)
+++ plog/branches/lifetype-1.2/class/dao/userdata/lifetypeuserdataprovider.class.php	2007-04-28 14:07:08 UTC (rev 5357)
@@ -204,50 +204,6 @@
         }
 
         /**
-         * Returns an array with all the users that belong to the given
-         * blog.
-         *
-         * @param blogId The blog identifier.
-         * @param includeOwner Wether to include the owner of the blog or not.
-         * @param status
-         * @param searchTerms
-         * @return An array with the information about the users who belong in
-         * one way or another to that blog.
-         */
-        function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL, $searchTerms = "" )
-        {
-            $users = Array();
-	        $prefix = $this->getPrefix();
-
-            // get the information about the owner, if requested so
-            if( $includeOwner ) {
-                $query = "SELECT {$prefix}users.* FROM {$prefix}users, {$prefix}blogs 
-                          WHERE {$prefix}users.id = {$prefix}blogs.owner_id AND {$prefix}blogs.id = '".Db::qstr($blogId)."';";
-                $result = $this->Execute( $query );
-
-                if( !$result )
-                    return false;
-
-                $row = $result->FetchRow();
-                $result->Close();
-                array_push( $users, $this->mapRow( $row ));
-            }
-
-            // now get the other users who have permission for that blog.
-            $query2 = "SELECT DISTINCT user_id FROM {$prefix}users_permissions WHERE blog_id = '".Db::qstr( $blogId )."'";
-            $result2 = $this->Execute( $query2 );
-            if( !$result2 ) // if error, return what we have so far...
-                return $users;
-
-            while( $row = $result2->FetchRow()) {
-                array_push( $users, $this->getUserInfoFromId( $row["user_id"] ));
-            }
-            $result2->Close();
-
-            return $users;
-        }
-        
-        /**
          * Removes users from the database
          *
          * @param userId The identifier of the user we are trying to remove

Modified: plog/branches/lifetype-1.2/class/dao/userdata/phpbb2userdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userdata/phpbb2userdataprovider.class.php	2007-04-28 12:58:07 UTC (rev 5356)
+++ plog/branches/lifetype-1.2/class/dao/userdata/phpbb2userdataprovider.class.php	2007-04-28 14:07:08 UTC (rev 5357)
@@ -42,6 +42,8 @@
          */
         function authenticateUser( $user, $pass )
         {
+			print("authenticating: $user<br/>");
+	
 	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE username = '".Db::qstr( $user )."'
 	                  AND user_password = '".md5( $pass )."' AND user_active > 0";
 	                  
@@ -120,8 +122,6 @@
 	        
 	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE user_id = '".Db::qstr( $userid )."'";
 
-//print("user__id = $userid");
-	                  
 	        $result = $this->_dbc->Execute( $query );
 	        
 	        if( !$result )
@@ -130,16 +130,13 @@
 	        $row = $result->FetchRow();
             $result->Close();
 	        
-	        // fetch the user permissions
-	        //$perms = new UserPermissions();
-	        //$row["site_admin"] = $perms->isSiteAdmin( $userid );
-	        
 	        return( $this->_mapUserInfoObject( $row ));
         }
         
         function phpBB2AddBlog( $row )
         {
 		    // create a new blog
+		    lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );		
 		    lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
@@ -191,23 +188,28 @@
 	        $row["properties"] = serialize(Array());
 	        $row["id"] = $row["user_id"];   
 	        $row["status"] = ($row["user_active"] > 0) ? USER_STATUS_ACTIVE : USER_STATUS_DISABLED;
-			$row["site_admin"] = $row["user_level"];	        
+			$row["site_admin"] = $row["user_level"];	     
 	        	        
 	       	// does this phpbb user have a blog yet? If so, create one if the configuration
 	        // of the user data provider says so
 	        $providerConfig = $this->getProviderConfiguration();
 	        if( $providerConfig->getValue( "createBlogIfNotExisting" )) {
+		
+		
 		        $userInfo = BaseUserDataProvider::mapRow( $row, true );
 		        // check if this user is assigned to any blog
 		        $userBlogs = $userInfo->getBlogs();
 		        if( empty($userBlogs )) {
+					// assign the login_perm permission
+					$this->grantLoginPermission( $userInfo );
+								
 			        $this->phpBB2AddBlog( $row );
 			        $userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
-     			}
+     			}				
 	        }
 	        else {
 		        $userInfo = BaseUserDataProvider::mapRow( $row );
-	        }	        
+	        }
 	        
 	        return( $userInfo );
         }
@@ -332,7 +334,7 @@
 		    	          WHERE phpbb_id = '".Db::qstr( $user->getId())."'";    
 	    	}
 	    	else {
-		    	// we need to run an INSERT query...	
+		    	// we need to run an INSERT query...
 		    	$query = "INSERT INTO ".$this->getPrefix()."phpbb2_users
 		    	          (full_name, about, properties, resource_picture_id,phpbb_id,status)
 		    	          VALUES ('".Db::qstr( $user->getFullName())."', '".
@@ -341,6 +343,8 @@
 		    	          Db::qstr($user->getPictureId())."','".
 		    	          Db::qstr($user->getId())."','".
 		    	          Db::qstr($user->getStatus())."');";
+				// we also need to grant this user login access at least
+				$this->grantLoginAccess( $user->getId());
 	    	}
 	    	
 	    	$result = $this->Execute( $query );
@@ -360,11 +364,11 @@
 	        $query = "SELECT * FROM ".$this->getPrefix()."phpbb2_users WHERE phpbb_id = '".Db::qstr($userId)."'";
 	        
 	        $result = $this->Execute( $query );
-	        
-	        if( !$result )
+	
+	        if( !$result ) 
 	        	return false;
 	        	
-	        if( $result->RowCount() == 0 ){
+	        if( $result->RowCount() == 0 ) {
                 $result->Close();
                 return false;
             }

Modified: plog/branches/lifetype-1.2/class/dao/userdata/simplepostnukeuserdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userdata/simplepostnukeuserdataprovider.class.php	2007-04-28 12:58:07 UTC (rev 5356)
+++ plog/branches/lifetype-1.2/class/dao/userdata/simplepostnukeuserdataprovider.class.php	2007-04-28 14:07:08 UTC (rev 5357)
@@ -90,6 +90,9 @@
                     //add Blog
                     $this->_PostNukeAddBlog($username, $newUserId);
 
+					// assign the login_perm permission
+					$this->grantLoginPermission( $userInfo );
+
                     return true;
                 }
                 else{
@@ -131,6 +134,7 @@
         */
         function _PostNukeAddBlog( &$username, &$userid )
         {
+		    lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );			
 		    lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );

Modified: plog/branches/lifetype-1.2/class/dao/userdata/vbb3userdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userdata/vbb3userdataprovider.class.php	2007-04-28 12:58:07 UTC (rev 5356)
+++ plog/branches/lifetype-1.2/class/dao/userdata/vbb3userdataprovider.class.php	2007-04-28 14:07:08 UTC (rev 5357)
@@ -223,7 +223,8 @@
         
         function vbb3AddBlog( $row )
         {
-		        // create a new blog
+		    // create a new blog
+		    lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
@@ -285,6 +286,9 @@
 		        // check if this user is assigned to any blog
 		        $userBlogs = $userInfo->getBlogs();
 		        if( empty($userBlogs )) {
+					// assign the login_perm permission
+					$this->grantLoginPermission( $userInfo );			
+			
 			        $this->vbb3AddBlog( $row );
 			        $userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
      			}

Modified: plog/branches/lifetype-1.2/class/dao/userdata/wbbuserdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userdata/wbbuserdataprovider.class.php	2007-04-28 12:58:07 UTC (rev 5356)
+++ plog/branches/lifetype-1.2/class/dao/userdata/wbbuserdataprovider.class.php	2007-04-28 14:07:08 UTC (rev 5357)
@@ -143,6 +143,7 @@
         function WBB2AddBlog( $row )
         {
 		    // create a new blog
+		    lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );				
 		    lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
             lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
@@ -205,6 +206,9 @@
 		        // check if this user is assigned to any blog
 		        $userBlogs = $userInfo->getBlogs();
 		        if( empty($userBlogs )) {
+					// assign the login_perm permission
+					$this->grantLoginPermission( $userInfo );			
+			
 			        $this->WBB2AddBlog( $row );
 			        $userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
      			}

Modified: plog/branches/lifetype-1.2/class/dao/userpermissions.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userpermissions.class.php	2007-04-28 12:58:07 UTC (rev 5356)
+++ plog/branches/lifetype-1.2/class/dao/userpermissions.class.php	2007-04-28 14:07:08 UTC (rev 5357)
@@ -53,13 +53,14 @@
          * Grants a permission to a user, for a given blog.
          * Any permission can be granted, as long as it exists.
          *
-         * @param userId The user which will receive the permission
-         * @param blogId The blog to which this permission will be given for this user
-         * @param permissionId The identifier of the permission that will be granted
+		 * @param perm A UserPermission object containing information abotu the permissions
+		 * and user that we'd like to grant
+		 * @param doNotCleanCache Whether we should ignore the code that triggers the cache. You should
+		 * probably not use this parameter if in doubt.
          * @return Returns true if the permission was set or already existed, or false
          * if there was any problem.
          */
-        function grantPermission( &$perm )
+        function grantPermission( &$perm, $doNotCleanCache = false )
         {
             // check if the permission has already been granted
 			$userPerms = $this->getUserPermissions( $perm->getUserId(), $perm->getUserId());
@@ -76,10 +77,12 @@
 				
 			// if not, grant it now
 			if(( $result = $this->add( $perm ))) {
-				$this->_cache->removeData( $perm->getUserId(), CACHE_USER_PERMISSIONS );
-				$this->_cache->removeData( $perm->getUserId(), CACHE_USERINFO );
-				$userInfo = $perm->getUserInfo();
-				$this->_cache->removeData( $userInfo->getUserName(), CACHE_USERIDBYNAME );
+				if( !$doNotCleanCache ) {
+					$this->_cache->removeData( $perm->getUserId(), CACHE_USER_PERMISSIONS );
+					$this->_cache->removeData( $perm->getUserId(), CACHE_USERINFO );
+					$userInfo = $perm->getUserInfo();
+					$this->_cache->removeData( $userInfo->getUserName(), CACHE_USERIDBYNAME );
+				}
 			}
 			
 			return( $result );



More information about the pLog-svn mailing list