/** * This method is called when user successfully logs in using FB credentials * * Facebook user ID is passed to our backend: * - if there's Wikia account connected, log the user in, * - if not, render sign up modal */ public function index() { $fbUserId = $this->getFacebookUserId(); // try to get connected Wikia account $user = FacebookClient::getInstance()->getWikiaUser($fbUserId); if ($user instanceof User && $fbUserId !== 0) { $errorMsg = ''; if ($this->isAccountDisabled($user)) { // User account was disabled, abort the login $errorMsg = wfMessage('userlogin-error-edit-account-closed-flag')->escaped(); $this->response->setData(['loginAborted' => true, 'errorMsg' => $errorMsg]); } elseif ($this->isAccountUnconfirmed($user)) { LoginForm::clearLoginToken(); $name = $user->getName(); $this->userLoginHelper->setNotConfirmedUserSession($user->getId()); $this->userLoginHelper->clearPasswordThrottle($name); $this->response->setData(['unconfirmed' => true, 'userName' => $name, 'errorMsg' => $errorMsg]); } elseif (!wfRunHooks('FacebookUserLoginSuccess', [$user, &$errorMsg])) { $this->response->setData(['loginAborted' => true, 'errorMsg' => $errorMsg]); } else { // account is connected - log the user in $user->setCookies(); $this->response->setData(['loggedIn' => true, 'userName' => $user->getName(), 'returnUrl' => $this->userLoginHelper->getRedirectUrl(), 'errorMsg' => '']); // Retrieve user email from Facebook if missing $email = $user->getEmail(); if (empty($email)) { $this->saveEmailAsynchronously($user->getId()); } } } else { $modal = $this->sendRequest('FacebookSignup', 'modal')->__toString(); $title = $this->sendRequest('FacebookSignup', 'modalHeader')->__toString(); if (empty($modal)) { $modal = wfMessage('usersignup-facebook-problem')->escaped(); } // no account connected - show FB sign up modal $this->response->setData(['htmlTitle' => $title, 'modal' => $modal, 'cancelMsg' => wfMessage('cancel')->escaped()]); } }
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; }