Example #1
0
 /**
  * Attempt to automatically create a user on login. Only succeeds if there
  * is an external authentication method which allows it.
  *
  * @param $user User
  *
  * @return integer Status code
  */
 function attemptAutoCreate($user)
 {
     global $wgAuth, $wgAutocreatePolicy;
     if ($this->getUser()->isBlockedFromCreateAccount()) {
         wfDebug(__METHOD__ . ": user is blocked from account creation\n");
         return self::CREATE_BLOCKED;
     }
     /**
      * If the external authentication plugin allows it, automatically cre-
      * ate a new account for users that are externally defined but have not
      * yet logged in.
      */
     if ($this->mExtUser) {
         # mExtUser is neither null nor false, so use the new ExternalAuth
         # system.
         if ($wgAutocreatePolicy == 'never') {
             return self::NOT_EXISTS;
         }
         if (!$this->mExtUser->authenticate($this->mPassword)) {
             return self::WRONG_PLUGIN_PASS;
         }
     } else {
         # Old AuthPlugin.
         if (!$wgAuth->autoCreate()) {
             return self::NOT_EXISTS;
         }
         if (!$wgAuth->userExists($user->getName())) {
             wfDebug(__METHOD__ . ": user does not exist\n");
             return self::NOT_EXISTS;
         }
         if (!$wgAuth->authenticate($user->getName(), $this->mPassword)) {
             wfDebug(__METHOD__ . ": \$wgAuth->authenticate() returned false, aborting\n");
             return self::WRONG_PLUGIN_PASS;
         }
     }
     $abortError = '';
     if (!wfRunHooks('AbortAutoAccount', array($user, &$abortError))) {
         // Hook point to add extra creation throttles and blocks
         wfDebug("LoginForm::attemptAutoCreate: a hook blocked creation: {$abortError}\n");
         $this->mAbortLoginErrorMsg = $abortError;
         return self::ABORTED;
     }
     wfDebug(__METHOD__ . ": creating account\n");
     $this->initUser($user, true);
     return self::SUCCESS;
 }
 /**
  * Do the whole dirty job of renaming user
  *
  * @return bool True if the process succeded
  */
 private function doRun()
 {
     global $wgMemc, $wgAuth;
     wfProfileIn(__METHOD__);
     $this->addLog("User rename global task start." . (!empty($this->mFakeUserId) ? ' Process is being repeated.' : null));
     $this->addLog("Renaming user {$this->mOldUsername} (ID {$this->mUserId}) to {$this->mNewUsername}");
     $hookName = 'RenameUser::Abort';
     $this->addLog("Broadcasting hook: {$hookName}");
     // Give other affected extensions a chance to validate or abort
     if (!wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername, &$this->mErrors))) {
         $this->addLog("Aborting procedure as requested by hook.");
         $this->addError(wfMessage('userrenametool-error-extension-abort')->inContentLanguage()->text());
         wfProfileOut(__METHOD__);
         return false;
     }
     //enumerate IDs for wikis the user has been active in
     $this->addLog("Searching for user activity on wikis.");
     $wikiIDs = RenameUserHelper::lookupRegisteredUserActivity($this->mUserId);
     $this->addLog("Found " . count($wikiIDs) . " wikis: " . implode(', ', $wikiIDs));
     $hookName = 'UserRename::BeforeAccountRename';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername));
     // delete the record from all the secondary clusters
     if (class_exists('ExternalUser_Wikia')) {
         ExternalUser_Wikia::removeFromSecondaryClusters($this->mUserId);
     }
     // rename the user on the shared cluster
     if (!$this->renameAccount()) {
         $this->addLog("Failed to rename the user on the primary cluster. Report the problem to the engineers.");
         $this->addError(wfMessage('userrenametool-error-cannot-rename-account')->inContentLanguage()->text());
         wfProfileOut(__METHOD__);
         return false;
     }
     $this->invalidateUser($this->mNewUsername);
     /*if not repeating the process
     		create a new account storing the old username and some extra information in the realname field
     		this avoids creating new accounts with the old name and let's resume/repeat the process in case is needed*/
     $this->addLog("Creating fake user account");
     $fakeUser = null;
     if (empty($this->mFakeUserId)) {
         global $wgAuth, $wgExternalAuthType;
         $fakeUser = User::newFromName($this->mOldUsername, 'creatable');
         if (!is_object($fakeUser)) {
             $this->addLog("Cannot create fake user: {$this->mOldUsername}");
             wfProfileOut(__METHOD__);
             return false;
         }
         $fakeUser->setPassword(null);
         $fakeUser->setEmail(null);
         $fakeUser->setRealName('');
         $fakeUser->setName($this->mOldUsername);
         if ($wgExternalAuthType) {
             ExternalUser_Wikia::addUser($fakeUser, '', '', '');
         } else {
             $fakeUser->addToDatabase();
         }
         $fakeUser->setGlobalAttribute('renameData', self::RENAME_TAG . '=' . $this->mNewUsername . ';' . self::PROCESS_TAG . '=' . '1');
         $fakeUser->setGlobalFlag('disabled', 1);
         $fakeUser->saveSettings();
         $this->mFakeUserId = $fakeUser->getId();
         $this->addLog("Created fake user account for {$fakeUser->getName()} with ID {$this->mFakeUserId} and renameData '{$fakeUser->getGlobalAttribute('renameData', '')}'");
     } else {
         $fakeUser = User::newFromId($this->mFakeUserId);
         $this->addLog("Fake user account already exists: {$this->mFakeUserId}");
     }
     $this->invalidateUser($this->mOldUsername);
     $hookName = 'UserRename::AfterAccountRename';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername));
     //process global tables
     $this->addLog("Initializing update of global shared DB's.");
     $this->updateGlobal();
     $callParams = array('requestor_id' => $this->mRequestorId, 'requestor_name' => $this->mRequestorName, 'rename_user_id' => $this->mUserId, 'rename_old_name' => $this->mOldUsername, 'rename_new_name' => $this->mNewUsername, 'rename_fake_user_id' => $this->mFakeUserId, 'phalanx_block_id' => $this->mPhalanxBlockId, 'reason' => $this->mReason);
     $task = (new UserRenameTask())->setPriority(\Wikia\Tasks\Queues\PriorityQueue::NAME);
     $task->call('renameUser', $wikiIDs, $callParams);
     $this->mUserRenameTaskId = $task->queue();
     wfProfileOut(__METHOD__);
     return true;
 }
Example #3
0
 /**
  * @param $user User
  */
 public static function invalidateUser($user, $disabled = false, $keepEmail = true, $ajax = false)
 {
     global $wgExternalAuthType;
     if ($disabled) {
         $userEmail = $user->getEmail();
         // Optionally keep email in user property
         if ($keepEmail && !empty($userEmail)) {
             $user->setGlobalAttribute('disabled-user-email', $userEmail);
         } elseif (!$keepEmail) {
             // Make sure user property is removed
             $user->setGlobalAttribute('disabled-user-email', null);
         }
         $user->setEmail('');
         $user->setPassword(null);
         $user->setGlobalFlag('disabled', 1);
         $user->setGlobalAttribute('disabled_date', wfTimestamp(TS_DB));
         $user->mToken = null;
         $user->invalidateEmail();
         if ($ajax) {
             global $wgRequest;
             $wgRequest->setVal('action', 'ajax');
         }
         $user->saveSettings();
     }
     $id = $user->getId();
     // delete the record from all the secondary clusters
     if ($wgExternalAuthType == 'ExternalUser_Wikia') {
         ExternalUser_Wikia::removeFromSecondaryClusters($id);
     }
     $user->invalidateCache();
     return true;
 }
 /**
  * Clears the magic unsub bit
  *
  * @return Boolean: true
  */
 function clearUnsubscribe()
 {
     global $wgExternalAuthType;
     $this->mUser->setGlobalPreference('unsubscribed', null);
     $this->mUser->saveSettings();
     // delete the record from all the secondary clusters
     if ($wgExternalAuthType == 'ExternalUser_Wikia') {
         $userId = $this->mUser->getId();
         ExternalUser_Wikia::removeFromSecondaryClusters($userId);
     }
     $this->mStatusMsg = wfMsg('editaccount-success-unsub', $this->mUser->mName);
     return true;
 }
Example #5
0
$user = User::newFromName($username);
if (!is_object($user)) {
    echo "invalid username.\n";
    die(1);
} elseif (0 != $user->idForName()) {
    echo "account exists.\n";
    die(1);
}
# Insert the account into the database
$user->addToDatabase();
$user->setEmail($email);
$user->setPassword($password);
$user->confirmEmail();
UserLoginHelper::removeNotConfirmedFlag($user);
// this calls saveSettings();
if (!ExternalUser_Wikia::addUser($user, $password, $email, $username)) {
    echo "error creating external user\n";
    die(1);
}
# Increment site_stats.ss_users
$ssu = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssu->doUpdate();
echo "done.\n";
function showHelp()
{
    echo <<<EOT
Create a new user account
USAGE: php createUser.php [--help] <username> <password> <email>

\t--help
\t\tShow this help information