/**
  * Handler for Facebook Login (and connect) for users with a Wikia account
  *
  * @return null
  */
 public function login()
 {
     $wg = $this->wg;
     $wikiaUserName = $wg->Request->getVal(self::SIGNUP_USERNAME_KEY);
     $wikiaPassword = $wg->Request->getVal(self::SIGNUP_PASSWORD_KEY);
     $user = $this->getValidWikiaUser($wikiaUserName, $wikiaPassword);
     if (!$user) {
         return;
     }
     // Log the user in with existing wikia account
     // Create the fb/Wikia user mapping if not already created
     $fbUserId = $this->getValidFbUserId();
     if (!$fbUserId) {
         return;
     }
     $status = $this->fbClientFactory->connectToFacebook($user->getId(), $fbUserId);
     if (!$status->isGood()) {
         list($message, $params) = $this->fbClientFactory->getStatusError($status);
         $this->setErrorResponse($message, $params);
         return;
     }
     $this->setupUserSession($user);
     \FacebookClientHelper::track('facebook-link-existing');
     $this->response->setData(['result' => 'ok', 'msg' => 'success']);
 }
 /**
  * Ajax endpoint for connecting a logged in Wikia user to a Facebook account.
  * By the time they get here they should already have logged into Facebook and have a Facebook user ID.
  */
 public function connectLoggedInUser()
 {
     $wg = F::app()->wg;
     $fb = FacebookClient::getInstance();
     $fbUserId = $fb->getUserId();
     // The user must be logged into Facebook and Wikia
     if (!$fbUserId || !$wg->User->isLoggedIn()) {
         $this->status = 'error';
         return;
     }
     // Create user mapping
     $status = $this->fbClientFactory->connectToFacebook($wg->User->getId(), $fbUserId);
     if (!$status->isGood()) {
         list($message, $params) = $this->fbClientFactory->getStatusError($status);
         $this->setErrorResponse($message, $params);
         return;
     }
     $this->status = 'ok';
     \FacebookClientHelper::track('facebook-link-existing');
 }
 /**
  * Connects given Wikia account with FB account and sets FB feed preferences
  * @param User $user Wikia account
  * @return bool true on success
  */
 private function connectWithFacebook(User $user)
 {
     $fbId = FacebookClient::getInstance()->getUserId();
     $fbClientFactory = new \FacebookClientFactory();
     $status = $fbClientFactory->connectToFacebook($user->getId(), $fbId);
     return $status->isGood();
 }