Example #1
0
 /**
  * @dataProvider isScheduledProvider
  */
 public function testIsScheduledForClosure($expected, $requestedClosureMap, $requestedClosureDateMap)
 {
     $userMock = $this->getMock('User', ['getGlobalAttribute', 'getGlobalFlag']);
     $userMock->expects($this->any())->method('getGlobalFlag')->with('requested-closure', false)->willReturn($requestedClosureMap);
     $userMock->expects($this->any())->method('getGlobalAttribute')->with('requested-closure-date', false)->willReturn($requestedClosureDateMap);
     $closeAccountHelper = new CloseMyAccountHelper();
     $result = $closeAccountHelper->isScheduledForClosure($userMock);
     $this->assertEquals($expected, $result);
 }
 /**
  * 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;
 }
 private function isClosureRequested()
 {
     global $wgEnableCloseMyAccountExt;
     if (!empty($wgEnableCloseMyAccountExt)) {
         $closeAccountHelper = new CloseMyAccountHelper();
         return $closeAccountHelper->isScheduledForClosure($this->mUser) && !$closeAccountHelper->isClosed($this->mUser);
     }
     return false;
 }
 /**
  * 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__);
 }