function GForgeAuthenticationHook()
{
    global $wgUser;
    global $wgRequest;
    global $_REQUEST;
    global $_SERVER;
    global $G_USERNAME;
    global $wgCacheEpoch;
    //echo $_SERVER["HTTP_REFERER"];
    $wgCacheEpoch = 'date +%Y%m%d%H%M%S';
    // For a few special pages, don't do anything.
    $title = $wgRequest->getVal('title');
    if ($title == 'Special:Userlogout' || $title == 'Special:Userlogin') {
        return;
    }
    // Do nothing if session is valid
    $wgUser = User::loadFromSession();
    if ($wgUser->isLoggedIn()) {
        return;
    }
    // Do little if user already exists
    //  (set the _REQUEST variable so that Login knows we're authenticated)
    $username = $G_USERNAME;
    $u = User::newFromName($username);
    if (is_null($u)) {
        # Invalid username or some other error -- force login, just return
        return;
    }
    $wgUser = $u;
    if ($u->getId() != 0) {
        $_REQUEST['wpName'] = $username;
        # also return, but user is know. set Cookies, et al
        $wgUser->setCookies();
        $wgUser->saveSettings();
        return;
    }
    // Ok, now we need to create a user.
    include 'includes/SpecialUserlogin.php';
    $form = new LoginForm($wgRequest);
    $form->initUser($wgUser);
    $wgUser->saveSettings();
    // if it worked: refer to login page, otherwise, exit
    header("Location: http" . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on" ? "s" : "") . "://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/" . (isset($_SERVER['URL']) ? $_SERVER['PATH_INFO'] . ($_SERVER['QUERY_STRING'] ? "?" . $_SERVER['QUERY_STRING'] : "") : ""));
    // Now redirect to referred page
    // print("Done");
    return;
}
 public function initUser($u, $autocreate, $createTempUser = true)
 {
     global $wgAuth, $wgExternalAuthType;
     // for FBconnect we don't want to create temp users
     if ($createTempUser === false) {
         return parent::initUser($u, $autocreate);
     }
     // add TempUser, update User object, set TempUser session
     $tempUser = TempUser::createNewFromUser($u, $this->mReturnTo);
     if ($wgExternalAuthType) {
         $u = ExternalUser::addUser($u, "", "", "");
         if (is_object($u)) {
             $this->mExtUser = ExternalUser::newFromName($this->mUsername);
         }
     } else {
         $u->addToDatabase();
     }
     $u->setToken();
     $wgAuth->initUser($u, $autocreate);
     if (is_object($this->mExtUser)) {
         $this->mExtUser->linkToLocal($u->getId());
     }
     $u->setOption('rememberpassword', $this->mRemember ? 1 : 0);
     $u->setOption('marketingallowed', $this->mMarketingOptIn ? 1 : 0);
     if ($this->mLanguage) {
         $u->setOption('language', $this->mLanguage);
     }
     $u->setOption('skinoverwrite', 1);
     $u->setPassword($this->mPassword);
     $tempUser->setPassword($u->mPassword);
     $tempUser->setId($u->getId());
     $tempUser->addToDatabase();
     wfRunHooks('AddNewAccountTempUser', array($u, false));
     $tempUser->saveSettingsTempUserToUser($u);
     $tempUser->setTempUserSession();
     return $u;
 }
Beispiel #3
0
/**
 * Does the SSL authentication piece of the LDAP plugin.
 *
 * @access public
 */
function SSLAuth(&$user)
{
    global $LDAPSSLUsername;
    global $User;
    global $Auth;
    $Auth->printDebug("Entering SSLAuth.", 1);
    //Give us a user, see if we're around
    $tmpuser = User::LoadFromSession();
    //They already with us?  If so, quit this function.
    if ($tmpuser->isLoggedIn()) {
        $Auth->printDebug("User is already logged in.", 1);
        return;
    }
    //Let regular authentication plugins configure themselves for auto
    //authentication chaining
    $Auth->autoAuthSetup();
    //The user hasn't already been authenticated, let's check them
    $Auth->printDebug("User is not logged in, we need to authenticate", 1);
    $authenticated = $Auth->authenticate($LDAPSSLUsername);
    if (!$authenticated) {
        //If the user doesn't exist in LDAP, there isn't much reason to
        //go any further.
        $Auth->printDebug("User wasn't found in LDAP, exiting.", 1);
        return;
    }
    //We need the username that MediaWiki will always use, *not* the one we
    //get from LDAP.
    $mungedUsername = $Auth->getCanonicalName($LDAPSSLUsername);
    $Auth->printDebug("User exists in LDAP; finding the user by name in MediaWiki.", 1);
    //Is the user already in the database?
    $tmpuser = User::newFromName($mungedUsername);
    if ($tmpuser == null) {
        $Auth->printDebug("Username is not a valid MediaWiki username.", 1);
        return;
    }
    //If exists, log them in
    if ($tmpuser->getID() != 0) {
        $Auth->printDebug("User exists in local database, logging in.", 1);
        $User =& $tmpuser;
        $Auth->updateUser($User);
        $User->setCookies();
        $User->setupSession();
        return;
    }
    $Auth->printDebug("User does not exist in local database; creating.", 1);
    //Require SpecialUserlogin so that we can get a loginForm
    require_once 'SpecialUserlogin.php';
    //This section contains a silly hack for MW
    global $Lang;
    global $ContLang;
    global $Request;
    if (!isset($Lang)) {
        $Lang = $ContLang;
        $LangUnset = true;
    }
    $Auth->printDebug("Creating LoginForm.", 1);
    //This creates our form that'll let us create a new user in the database
    $lf = new LoginForm($Request);
    //The user we'll be creating...
    $User =& $tmpuser;
    $User->setName($ContLang->ucfirst($mungedUsername));
    $Auth->printDebug("Creating User.", 1);
    //Create the user
    $lf->initUser($User);
    //Initialize the user
    $User->setupSession();
    $User->setCookies();
}
 public function initUser(User &$u, $autocreate, $skipConfirm = false)
 {
     global $wgCityId;
     if (!parent::initUser($u, $autocreate)) {
         return false;
     }
     /*
      * Remove when SOC-217 ABTest is finished
      */
     $isAllowRegisterUnconfirmed = $this->isAllowedRegisterUnconfirmed();
     /*
      * end remove
      */
     if ($skipConfirm === false) {
         /*
          * Remove when SOC-217 ABTest is finished
          */
         $u->setGlobalAttribute(UserLoginSpecialController::NOT_CONFIRMED_LOGIN_OPTION_NAME, $isAllowRegisterUnconfirmed ? UserLoginSpecialController::NOT_CONFIRMED_LOGIN_ALLOWED : UserLoginSpecialController::NOT_CONFIRMED_LOGIN_NOT_ALLOWED);
         /*
          * end remove
          */
         // Set properties that will require user to confirm email after signup
         $u->setGlobalAttribute(UserLoginSpecialController::SIGNUP_REDIRECT_OPTION_NAME, $this->mReturnTo);
         $u->setGlobalFlag(UserLoginSpecialController::NOT_CONFIRMED_SIGNUP_OPTION_NAME, true);
         $u->setGlobalFlag(UserLoginSpecialController::SIGNED_UP_ON_WIKI_OPTION_NAME, $wgCityId);
         $u->saveSettings();
         UserLoginHelper::setNotConfirmedUserSession($u->getId());
     }
     wfRunHooks('AddNewAccount', array($u, false));
     /*
      * Remove when SOC-217 ABTest is finished
      */
     if ($isAllowRegisterUnconfirmed) {
         $u->setCookies();
     }
     /*
      * end remove
      */
     return true;
 }