/** * Abort a successful login through Facebook Connect if the user has * requested an account closure. * * @param User $user The user attempting to log in * @param string $errorMsg Error message to display to the user * @return boolean True if login should succeed, false otherwise */ public static function onFacebookUserLoginSuccess(User $user, &$errorMsg) { global $wgRequest; $closeAccountHelper = new CloseMyAccountHelper(); if ($closeAccountHelper->isScheduledForClosure($user)) { $wgRequest->setSessionData('closeAccountSessionId', $user->getId()); $errorMsg = wfMessage('closemyaccount-reactivate-error-fbconnect', $user->getName())->parse(); return false; } elseif ($wgRequest->getSessionData('closeAccountSessionId') !== null) { // Clear close account session ID on logging in to another account unset($_SESSION['closeAccountSessionId']); } return true; }
public function execute() { global $wgUser, $wgExternalSharedDB; // Currently, inverted searches (using a column other than up_user) may not // be supported for preferences in the future. However this feature may be // supported for user "flags" if we need to do reverse lookups like these. // See https://wikia-inc.atlassian.net/browse/SERVICES-469. // --drsnyder echo "*******************************************************"; echo "Warning, inverted searches on 'user_properties' may be deprecated soon. Contact the services team."; echo "*******************************************************"; $closeAccountHelper = new CloseMyAccountHelper(); $dbr = wfGetDB(DB_SLAVE, [], $wgExternalSharedDB); // Only get users who self-requested account closure $subQuery = $dbr->selectSQLText('user_properties', ['up_user'], ['up_property' => 'requested-closure-date'], __METHOD__); $res = $dbr->select('user_properties', ['up_user'], ['up_property' => 'requested-closure', 'up_value' => 1, 'up_user IN (' . $subQuery . ')'], __METHOD__); $usersClosed = []; $closeReason = 'User requested account closure more than 30 days ago'; $wgUser = User::newFromName('Wikia'); foreach ($res as $row) { $userObj = User::newFromId($row->up_user); $daysRemaining = $closeAccountHelper->getDaysUntilClosure($userObj); if ($daysRemaining === 0) { $this->output("Closing account {$userObj->getName()}...\n"); $statusMsg1 = ''; $statusMsg2 = ''; $result = EditAccount::closeAccount($userObj, $closeReason, $statusMsg1, $statusMsg2, true); // Set an option that signifies this user was closed automatically $userObj->setGlobalFlag('disabled-by-user-request', true); // Cleanup $userObj->setGlobalFlag('requested-closure', null); $userObj->setGlobalAttribute('requested-closure-date', null); $userObj->saveSettings(); $closeAccountHelper->track($userObj, 'account-closed'); $usersClosed[] = $userObj->getName(); } } $this->output(count($usersClosed) . " user accounts closed.\n"); }
public function testIsClosed() { $userMock = $this->getMock('User', ['getGlobalFlag']); $userMock->expects($this->exactly(2))->method('getGlobalFlag')->with($this->equalTo('disabled'))->will($this->onConsecutiveCalls(1, 0)); $closeAccountHelper = new CloseMyAccountHelper(); $resultOne = $closeAccountHelper->isClosed($userMock); $this->assertTrue($resultOne); $resultTwo = $closeAccountHelper->isClosed($userMock); $this->assertFalse($resultTwo); }
private function clearClosureRequest() { global $wgEnableCloseMyAccountExt; if (!empty($wgEnableCloseMyAccountExt)) { $closeAccountHelper = new CloseMyAccountHelper(); $result = $closeAccountHelper->reactivateAccount($this->mUser); if (!$result) { $this->mStatusMsg = $this->msg('editaccount-error-clearclosurerequest')->text(); } else { $this->mStatusMsg = $this->msg('editaccount-success-clearclosurerequest', $this->mUser->getName())->text(); } return $result; } return true; }
/** * Entry point for requesting that an account is reactivated * * This is the form users will be taken to after successfully attempting * to login to an account that has requested closure. * * @responseParam boolean showForm - Whether or not to show the request form * @responseParam string error - Whether or not an error occurred * @responseParam string introText - The introductory text that explains the * reactivation process * @responseParam string submitButton - The HTML for the submit button * @return void */ public function reactivateRequest() { wfProfileIn(__METHOD__); $this->response->setTemplateEngine(WikiaResponse::TEMPLATE_ENGINE_MUSTACHE); $userId = $this->request->getSessionData('closeAccountSessionId'); $this->showForm = false; // Paranoia, if they got here, this shouldn't happen if ($userId === null) { $this->error = $this->msg('closemyaccount-reactivate-error-id')->escaped(); wfProfileOut(__METHOD__); return; } elseif ($this->getUser()->isLoggedIn()) { $this->error = $this->msg('closemyaccount-reactivate-error-logged-in')->escaped(); wfProfileOut(__METHOD__); return; } $helper = new CloseMyAccountHelper(); $userObj = User::newFromId($userId); if ($helper->isClosed($userObj)) { $this->error = $this->msg('closemyaccount-reactivate-error-disabled')->parse(); wfProfileOut(__METHOD__); return; } // Paranoia, shouldn't happen, but just in case... if (!$helper->isScheduledForClosure($userObj)) { $this->error = $this->msg('closemyaccount-reactivate-error-not-scheduled')->escaped(); wfProfileOut(__METHOD__); return; } if (!$userObj->isEmailConfirmed()) { $this->error = $this->msg('closemyaccount-reactivate-error-email')->parse(); wfProfileOut(__METHOD__); return; } $this->getOutput()->setPageTitle($this->msg('closemyaccount-reactivate-page-title')->plain()); if ($this->request->wasPosted()) { $result = $helper->requestReactivation($userObj, $this->app); if ($result) { $this->introText = $this->msg('closemyaccount-reactivate-requested')->parseAsBlock(); } else { $this->error = $this->msg('closemyaccount-reactivate-error-failed')->parse(); } } else { $this->showForm = true; // Show how many days they have before their account is permanently closed $daysUntilClosure = $helper->getDaysUntilClosure($userObj); $this->introText = $this->msg('closemyaccount-reactivate-intro', $this->getLanguage()->formatNum($daysUntilClosure), $userObj->getName())->parseAsBlock(); $buttonParams = ['type' => 'button', 'vars' => ['type' => 'submit', 'classes' => ['wikia-button', 'big', 'closemyaccount'], 'value' => $this->msg('closemyaccount-reactivate-button-text')->text(), 'data' => []]]; $this->submitButton = \Wikia\UI\Factory::getInstance()->init('button')->render($buttonParams); } wfProfileOut(__METHOD__); }