📄 simplepostnukeuserdataprovider.class.php
字号:
<?php lt_include( PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" ); lt_include( PLOG_CLASS_PATH."class/database/db.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/userstatus.class.php" ); /** * Model representing the users in our application. Provides the methods such as * authentication and querying for users. * * \ingroup User_Data_Providers */ class SimplePostNukeUserDataProvider extends BaseUserDataProvider { var $_dbc; var $_postnukedbprefix; var $_blogtitle_postfix; /** * Initializes the model */ function SimplePostNukeUserDataProvider( $providerConfig ) { $this->BaseUserDataProvider( $providerConfig ); $this->table = $this->getPrefix()."users"; // 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->_postnukedbprefix = $config->getValue( "prefix" ); $this->_dbc =& Db::getNewDb( $host, $user, $pass, $db ); $this->_blogtitle_postfix = $config->getValue( "blogtitle_postfix" ); } /** * Returns true if the user is in the database and the username * and password match * * First, we check if the user exists as a standard lt user. If not, we check if he * has an PostNuke account, validate username/password and open a lt account for him. * This is the only time we interact with the postnuke db. Password changes, user removal and * and everything else possible within LifeType does not affect the PostNuke database in any way. * * @param username 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( $username, $pass ) { // Check if we find the user in the LifeType DB $user = $this->getUserInfoFromUsername( $username ); if( $user ) { return( $user->getPassword() == md5($pass)); } // Check if the user is available in the PostNuke database... else { $query = "SELECT * FROM ".$this->_postnukedbprefix."users WHERE pn_uname = '".Db::qstr( $username )."' AND pn_pass = '".md5( $pass )."'"; $result = $this->_dbc->Execute( $query ); if( (!$result) || ($result == false) ) { return false; } // let's add the user to the lt userbase elseif ( $result->RecordCount() == 1 ) { $result->Close(); $pnUserdata = $this->getUserInfoFromPostNukeUser( $username ); $user = new UserInfo( $pnUserdata["pn_uname"], $pnUserdata["pn_pass"], $pnUserdata["pn_email"], "", $pnUserdata["pn_name"], 0, serialize(Array()) ); $user->setStatus( USER_STATUS_ACTIVE ); $newUserId = $this->addUser( $user ); if( !$newUserId ) { return false; } //add Blog $this->_PostNukeAddBlog($username, $newUserId); return true; } else{ // TODO: shouldn't ever happen? $result->Close(); } // return false if user authentication failed on both databases return false; } } // authenticateUser /** * * @param username Username of the user who we'd like to get all info from the PN DB * @return Returns an array with all userinformation */ function getUserInfoFromPostNukeUser( $username ) { $query = "SELECT * FROM ".$this->_postnukedbprefix."users WHERE pn_uname = '".Db::qstr( $username )."'"; $result = $this->_dbc->Execute( $query ); if( !$result ) return false; $row = $result->FetchRow(); $result->Close(); return( $row ); } /** * * @param username Username for having a meaningful Blogname * @param userid UserID to link the blog to the new created user * @return Returns true if blog is created successfully and false otherwise */ function _PostNukeAddBlog( &$username, &$userid ) { 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" ); $config =& Config::getConfig(); $locale =& Locales::getLocale( $config->getValue( "default_locale" )); // create a new blog $blogs = new Blogs(); $blog = new BlogInfo( $username.$this->_blogtitle_postfix, // name of the new blog $userid, // id of the owner "", // no about Array()); // no properties either $newBlogId = $blogs->addBlog( $blog ); // add a default category and a default post $articleCategories = new ArticleCategories(); $articleCategory = new ArticleCategory( $locale->tr( "register_default_category" ), "", $newBlogId, true ); $catId = $articleCategories->addArticleCategory( $articleCategory ); $articleTopic = $locale->tr( "register_default_article_topic" ); $articleText = $locale->tr( "register_default_article_text" ); $article = new Article( $articleTopic, $articleText, Array( $catId ), $userid, $newBlogId, POST_STATUS_PUBLISHED, 0, Array(), "welcome" ); // slug $t = new Timestamp(); $article->setDateObject( $t ); $article->setInSummary( false ); $articles = new Articles(); $articles->addArticle( $article ); } //------------ // NOTE: Everything below is copy&paste from LifeTypeUserdataprovider.class.php //------------ /** * 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 ) { return( $this->get( "user", $username, CACHE_USERIDBYNAME, Array( CACHE_USERINFO => "getId" ))); } /** * 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 ) { return( $this->get( "id", $userid, CACHE_USERINFO, Array( CACHE_USERIDBYNAME => "getUsername" ))); } /** * Returns an array with all the users available in the database * * @param status * @param includeExtraInfo * @param searchTerms * @param page * @param itemsPerPage * @return An array containing all the users. */ function getAllUsers( $status = USER_STATUS_ALL, $searchTerms = "", $orderBy = "", $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE ) { $where = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -