Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Vanilla Forum Helper Functions
- */
- class appForum {
- function __construct(){
- define('APPLICATION', 'Vanilla');
- define('APPLICATION_VERSION', '2.0.18.4');
- define('DS', '/');
- define('PATH_ROOT', 'forum');
- }
- /*
- * Set the vanilla session as logged in with this user object.
- */
- public static function setLoggedIn($bLoggedIn, $cUser, $iVanillaUserID = -1) {
- ob_start();
- require_once(PATH_ROOT.DS.'bootstrap.php');
- ob_end_clean();
- $cAuthenticator = new Gdn_PasswordAuthenticator();
- //Get the vanilla ID:
- if ($iVanillaUserID == -1) {
- $cUserAuth = appDB::query("SELECT * FROM GDN_UserAuthentication WHERE ForeignUserKey = ? LIMIT 1", array($cUser['id']));
- $iVanillaUserID = $cUserAuth['userid']; //UserID
- }
- //Set cookie: persist login for a month
- $cAuthenticator->SetIdentity($iVanillaUserID, true);
- Gdn::Authenticator()->Trigger(Gdn_Authenticator::AUTH_SUCCESS);
- }
- /*
- * Check if user is logged in, if so return user model.
- */
- public static function loggedIn() {
- ob_start();
- require_once(PATH_ROOT.DS.'bootstrap.php');
- ob_end_clean();
- $Session = Gdn::Session();
- $Authenticator = Gdn::Authenticator();
- if ($Session->IsValid()) {
- return true;
- } else {
- return false;
- }
- }
- /*
- * Log out of the user's account:
- */
- public static function logout($sCookiePath = '/', $sCookieDomain = '.mydomain.com') {
- $iPastTime = time() - 24 * 60 * 60;
- setcookie('Vanilla', ' ', $iPastTime, $sCookiePath, $sCookieDomain);
- setcookie('VanillaSessionID', ' ', $iPastTime, $sCookiePath, $sCookieDomain);
- setcookie('Vanilla-Volatile', ' ', $iPastTime, $sCookiePath, $sCookieDomain);
- unset($_COOKIE['Vanilla']);
- unset($_COOKIE['Vanilla-Volatile']);
- unset($_COOKIE['VanillaSessionID']);
- session_destroy();
- $_COOKIE = null;
- }
- /*
- * Manually insert a user into the vanilla tables:
- */
- public static function createUser($iUserID, $sName, $sEmail, $sPassword, $sProviderKey = "my provider key here") {
- define('APPLICATION', 'Vanilla');
- define('APPLICATION_VERSION', '2.0.18.4');
- define('DS', '/');
- define('PATH_ROOT', 'forum');
- ob_start();
- require_once(PATH_ROOT.DS.'bootstrap.php');
- ob_end_clean(); // clear any header output from vanila
- $User = new UserModel();
- $iVanillaUserID = $User->InsertForBasic(
- array('Email'=>$sEmail, 'Name'=>$sName, 'ShowEmail'=>'0', 'Gender'=>'m', 'Password'=>$sPassword, 'Preferences'=>'a:1:{s:13:"Authenticator";s:5:"proxy";}'),
- FALSE,
- array('ValidateEmail' => FALSE, 'NoConfirmEmail' => TRUE)
- );
- if ($iVanillaUserID) {
- // Save the authentication - different array keys to the database...igits.
- $User->SaveAuthentication(array(
- 'UniqueID' => $iUserID,
- 'Provider' => $sProviderKey,
- 'UserID' => $iVanillaUserID
- ));
- //Set user logged in:
- appForum::setLoggedIn(true, null, $iVanillaUserID);
- }
- //Save the vanilla ID to your own user database to call for setLogin later.
- return $iVanillaUserID;
- }
- /*
- * Vanilla User Is logged iN
- */
- public static function VanillaAuth() {
- ob_start();
- require_once(PATH_ROOT.DS.'bootstrap.php');
- ob_end_clean(); // clear any header output from vanila
- $Session = Gdn::Session();
- $Authenticator = Gdn::Authenticator();
- if ($Session->IsValid()) {
- return $Session->User;
- } else {
- $Authenticator = Gdn::Authenticator()->GetAuthenticator('proxy');
- $Authenticator->Authenticate();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement