📄 vbb3userdataprovider.class.php
字号:
<?php
/*
* Name: vbb3userdataprovider (support read user info from vbb)
* Version: 1.0
* Author: Pan Ying(http://www.pactofshadow.com/lifetype/~nest)
* Contact: panying2000@gmail.com
* Release: 2006.10.5
* Download Link:http://www.pactofshadow.com/lifetype/2/articleperma/17.html
*
* Known Issue:
* Could not update user info in vbb.
* Could not delete user from vbb
* Do not support vbb user's Muti-user group , only support main group (todo in future)
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
include_once( PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" );
include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
/**
* Model representing the users in our application. Provides the methods such as
* authentication and querying for users.
*
* \ingroup User_Data_Providers
*/
class vbb3UserDataProvider extends BaseUserDataProvider
{
var $_dbc; //database connect
var $_vbb3prefix; //vbb database prefix
var $_usepasswordsalt; //vbb3 use password salt
var $_allowedusergroups; //which group in vbb will be active .
var $_disallowedusergroups; //which group in vbb will be not active , if you have block group , set it
var $_adminusergroups; //which group in vbb will have admin permission?
var $_adminusers; //special user in vbb to have admin permission.
/**
* Initializes the model
*/
function vbb3UserDataProvider( $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->_vbb3prefix = $config->getValue( "prefix" );
$this->_usepasswordsalt = $config->getValue( "usesalt" );
$this->_allowedusergroups = $config->getValue( "allowgroup" );
$this->_disallowedusergroups = $config->getValue( "denygroup" );
$this->_adminusergroups = $config->getValue( "admingroup");
$this->_adminusers = $config->getValue( "adminuser");
$this->_dbc =& Db::getNewDb( $host, $user, $pass, $db );
}
function vbbAllowed( $row )
{
//echo "vbbAllowed called".$row['usergroupid'];
if (!in_array($row['usergroupid'], $this->_disallowedusergroups))
if (in_array($row['usergroupid'], $this->_allowedusergroups))
return true;
// echo "vbbAllowed return false";
return false;
}
function vbbAdmin( $row )
{
//echo "vbbAdmin called";
if (in_array($row['usergroupid'], $this->_adminusergroups))
return true;
if (in_array($row['userid'], $this->_adminusers))
return true;
//echo "vbbAdmin return false";
return false;
}
function vbbCheckPassword( $pass , $row )
{
//echo "vbbCheckPassword called";
if ($this->_usepasswordsalt)
{
if(md5(md5($pass) . $row['salt']) == $row['password']) return true;
}
else
{
if(md5($pass) == $row['password']) return true;
}
return false;
}
/**
* Returns true if the user is in the database and the username
* and password match
*
* @param user Username of the user who we'd like to authenticate
* @param pass Password of the user
* @return true if user and password correct or false otherwise.
*/
function authenticateUser( $user, $pass )
{
$query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE username = '".Db::qstr( $user )."'";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$ret = ($result->RecordCount() == 1);
if ($ret) $row = $result->FetchRow();
$result->Close();
if($ret && $this->vbbCheckPassword($pass,$row) && $this->vbbAllowed($row))
return true;
else
return false;
}
/**
* Returns all the information associated to the user given
*
* @param user Username of the user from who we'd like to get the information
* @param pass Password of the user we'd like to get the information
* @return Returns a UserInfo object with the requested information, or false otherwise.
*/
function getUserInfo( $user, $pass )
{
$query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE username = '".Db::qstr( $user )."'";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$row = $result->FetchRow();
$result->Close();
if (!$this->vbbCheckPassword($pass,$row))
return false;
return( $this->_mapUserInfoObject( $row ));
}
/**
* Retrieves the user information but given only a username
*
* @param username The username of the user
* @return Returns a UserInfo object with the requested information, or false otherwise.
*/
function getUserInfoFromUsername( $username )
{
$query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE username = '".Db::qstr( $username )."'";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
if( $result->RowCount() == 0 ){
$result->Close();
return false;
}
$row = $result->FetchRow();
$result->Close();
return( $this->_mapUserInfoObject( $row ));
}
/**
* Retrieves the user infromation but given only a userid
*
* @param userId User ID of the user from whom we'd like to get the information
* @return Returns a UserInfo object with the requested information, or false otherwise.
*/
function getUserInfoFromId( $userid, $extendedInfo = false )
{
include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
$query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE userid = '".Db::qstr( $userid )."'";
//print("user__id = $userid");
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$row = $result->FetchRow();
$result->Close();
// fetch the user permissions
//$perms = new UserPermissions();
//$row["site_admin"] = $perms->isSiteAdmin( $userid );
return( $this->_mapUserInfoObject( $row ));
}
function vbb3AddBlog( $row )
{
// create a new blog
include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
$blogs = new Blogs();
$blog = new BlogInfo( $row["user"], // name of the new blog
$row["id"], // id of the owner
"", // no about
""); // no properties either
$newBlogId = $blogs->addBlog( $blog );
// add a default category and a default post
$articleCategories = new ArticleCategories();
$articleCategory = new ArticleCategory( "General", "", $newBlogId, true );
$catId = $articleCategories->addArticleCategory( $articleCategory );
$config =& Config::getConfig();
$locale =& Locales::getLocale( $config->getValue( "default_locale" ));
$articleTopic = $locale->tr( "register_default_article_topic" );
$articleText = $locale->tr( "register_default_article_text" );
$article = new Article( $articleTopic,
$articleText,
Array( $catId ),
$row["user_id"],
$newBlogId,
POST_STATUS_PUBLISHED,
0,
Array(),
"welcome" );
$t = new Timestamp();
$article->setDateObject( $t );
$articles = new Articles();
$articles->addArticle( $article );
}
function _mapUserInfoObject( $row, $extraInfo = false )
{
include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
$plogPhpBB2Data = $this->getpLogPHPBBUserData( $row["userid"] );
$row["user"] = $row["username"];
//$row["password"] = $row["password"]; //todo
$row["email"] = $row["email"];
$row["about"] = $plogPhpBB2Data["about"];
$row["full_name"] = $plogPhpBB2Data["full_name"];
$row["resource_picture_id"] = $plogPhpBB2Data["resource_picture_id"];
if( $row["resource_picture_id"] == "" )
$row["resource_picture_id"] = 0;
$row["properties"] = serialize(Array());
$row["id"] = $row["userid"];
$row["status"] = $this->vbbAllowed($row) ? USER_STATUS_ACTIVE : USER_STATUS_DISABLED;
$row["site_admin"] = $this->vbbAdmin($row)?1:0;
// does this vbb3 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 )) {
$this->vbb3AddBlog( $row );
$userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
}
}
else {
$userInfo = BaseUserDataProvider::mapRow( $row );
}
return( $userInfo );
}
/**
* Returns an array with all the users available in the database
*
* @param status
* @param includeExtraInfo
* @param page
* @param itemsPerPage
* @return An array containing all the users.
*/
function getAllUsers( $status = USER_STATUS_ALL, $searchTerms = "", $orderBy = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
{
$where = "";
switch ($status)
{
case user_status_all:
$where = "";
break;
case user_status_active:
$where = "usergroupid in (".implode(",", $this->_allowedusergroups).")";
break;
case user_status_unconfirmed:
case user_status_disabled:
$where = "not(usergroupid in (".implode(",", $this->_allowedusergroups)."))";
break;
}
if ($searchTerms != "")
{
if ($where != "")
$where = $where." AND ".($this->getSearchConditions($searchTerms));
else
$where = $this->getSearchConditions($searchTerms);
}
if ($where != "")
$where = " where ".$where;
$query = "SELECT * FROM ".$this->_vbb3prefix."user".$where." ORDER BY userid ASC";
$result = $this->_dbc->Execute( $query, $page, $itemsPerPage );
$users = Array();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -