Differential D20118 Diff 48131 src/applications/auth/controller/PhabricatorAuthRegisterController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/PhabricatorAuthRegisterController.php
<?php | <?php | ||||
final class PhabricatorAuthRegisterController | final class PhabricatorAuthRegisterController | ||||
extends PhabricatorAuthController { | extends PhabricatorAuthController { | ||||
public function shouldRequireLogin() { | public function shouldRequireLogin() { | ||||
return false; | return false; | ||||
} | } | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$account_key = $request->getURIData('akey'); | $account_key = $request->getURIData('akey'); | ||||
if ($request->getUser()->isLoggedIn()) { | if ($viewer->isLoggedIn()) { | ||||
return id(new AphrontRedirectResponse())->setURI('/'); | return id(new AphrontRedirectResponse())->setURI('/'); | ||||
} | } | ||||
$invite = $this->loadInvite(); | |||||
$is_setup = false; | $is_setup = false; | ||||
if (strlen($account_key)) { | if (strlen($account_key)) { | ||||
$result = $this->loadAccountForRegistrationOrLinking($account_key); | $result = $this->loadAccountForRegistrationOrLinking($account_key); | ||||
list($account, $provider, $response) = $result; | list($account, $provider, $response) = $result; | ||||
$is_default = false; | $is_default = false; | ||||
} else if ($this->isFirstTimeSetup()) { | } else if ($this->isFirstTimeSetup()) { | ||||
$account = null; | $account = null; | ||||
$provider = null; | $provider = null; | ||||
$response = null; | $response = null; | ||||
$is_default = true; | $is_default = true; | ||||
$is_setup = true; | $is_setup = true; | ||||
} else { | } else { | ||||
list($account, $provider, $response) = $this->loadDefaultAccount(); | list($account, $provider, $response) = $this->loadDefaultAccount($invite); | ||||
$is_default = true; | $is_default = true; | ||||
} | } | ||||
if ($response) { | if ($response) { | ||||
return $response; | return $response; | ||||
} | } | ||||
$invite = $this->loadInvite(); | |||||
if (!$is_setup) { | if (!$is_setup) { | ||||
if (!$provider->shouldAllowRegistration()) { | if (!$provider->shouldAllowRegistration()) { | ||||
if ($invite) { | if ($invite) { | ||||
// If the user has an invite, we allow them to register with any | // If the user has an invite, we allow them to register with any | ||||
// provider, even a login-only provider. | // provider, even a login-only provider. | ||||
} else { | } else { | ||||
// TODO: This is a routine error if you click "Login" on an external | // TODO: This is a routine error if you click "Login" on an external | ||||
// auth source which doesn't allow registration. The error should be | // auth source which doesn't allow registration. The error should be | ||||
▲ Show 20 Lines • Show All 590 Lines • ▼ Show 20 Lines | $view = id(new PHUITwoColumnView()) | ||||
)); | )); | ||||
return $this->newPage() | return $this->newPage() | ||||
->setTitle($title) | ->setTitle($title) | ||||
->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
->appendChild($view); | ->appendChild($view); | ||||
} | } | ||||
private function loadDefaultAccount() { | private function loadDefaultAccount($invite) { | ||||
$providers = PhabricatorAuthProvider::getAllEnabledProviders(); | $providers = PhabricatorAuthProvider::getAllEnabledProviders(); | ||||
$account = null; | $account = null; | ||||
$provider = null; | $provider = null; | ||||
$response = null; | $response = null; | ||||
foreach ($providers as $key => $candidate_provider) { | foreach ($providers as $key => $candidate_provider) { | ||||
if (!$invite) { | |||||
if (!$candidate_provider->shouldAllowRegistration()) { | if (!$candidate_provider->shouldAllowRegistration()) { | ||||
unset($providers[$key]); | unset($providers[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
} | |||||
if (!$candidate_provider->isDefaultRegistrationProvider()) { | if (!$candidate_provider->isDefaultRegistrationProvider()) { | ||||
unset($providers[$key]); | unset($providers[$key]); | ||||
} | } | ||||
} | } | ||||
if (!$providers) { | if (!$providers) { | ||||
$response = $this->renderError( | $response = $this->renderError( | ||||
pht( | pht( | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |