@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add first-time-setup registration flow

Summary:
Ref T1536. Currently, when you install Phabricator you're dumped on the login screen and have to consult the documentation to learn about `bin/accountadmin`.

Instead, detect that an install is running first-time setup:

- It has no configured providers; and
- it has no user accounts.

We can safely deduce that such an install isn't configured yet, and let the user create an admin account from the web UI.

After they login, we raise a setup issue and lead them to configure authentication.

(This could probably use some UI and copy tweaks.)

Test Plan:
{F46738}

{F46739}

Reviewers: chad, btrahan

Reviewed By: chad

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6228

+113 -10
+2
src/__phutil_library_map__.php
··· 1456 1456 'PhabricatorSettingsPanelSearchPreferences' => 'applications/settings/panel/PhabricatorSettingsPanelSearchPreferences.php', 1457 1457 'PhabricatorSetupCheck' => 'applications/config/check/PhabricatorSetupCheck.php', 1458 1458 'PhabricatorSetupCheckAPC' => 'applications/config/check/PhabricatorSetupCheckAPC.php', 1459 + 'PhabricatorSetupCheckAuth' => 'applications/config/check/PhabricatorSetupCheckAuth.php', 1459 1460 'PhabricatorSetupCheckBaseURI' => 'applications/config/check/PhabricatorSetupCheckBaseURI.php', 1460 1461 'PhabricatorSetupCheckBinaries' => 'applications/config/check/PhabricatorSetupCheckBinaries.php', 1461 1462 'PhabricatorSetupCheckDatabase' => 'applications/config/check/PhabricatorSetupCheckDatabase.php', ··· 3324 3325 'PhabricatorSettingsPanelSSHKeys' => 'PhabricatorSettingsPanel', 3325 3326 'PhabricatorSettingsPanelSearchPreferences' => 'PhabricatorSettingsPanel', 3326 3327 'PhabricatorSetupCheckAPC' => 'PhabricatorSetupCheck', 3328 + 'PhabricatorSetupCheckAuth' => 'PhabricatorSetupCheck', 3327 3329 'PhabricatorSetupCheckBaseURI' => 'PhabricatorSetupCheck', 3328 3330 'PhabricatorSetupCheckBinaries' => 'PhabricatorSetupCheck', 3329 3331 'PhabricatorSetupCheckDatabase' => 'PhabricatorSetupCheck',
+22
src/applications/auth/controller/PhabricatorAuthController.php
··· 29 29 30 30 } 31 31 32 + /** 33 + * Returns true if this install is newly setup (i.e., there are no user 34 + * accounts yet). In this case, we enter a special mode to permit creation 35 + * of the first account form the web UI. 36 + */ 37 + protected function isFirstTimeSetup() { 38 + // If there are any auth providers, this isn't first time setup, even if 39 + // we don't have accounts. 40 + if (PhabricatorAuthProvider::getAllEnabledProviders()) { 41 + return false; 42 + } 43 + 44 + // Otherwise, check if there are any user accounts. If not, we're in first 45 + // time setup. 46 + $any_users = id(new PhabricatorPeopleQuery()) 47 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 48 + ->setLimit(1) 49 + ->execute(); 50 + 51 + return !$any_users; 52 + } 53 + 32 54 33 55 /** 34 56 * Log a user into a web session and return an @{class:AphrontResponse} which
+55 -10
src/applications/auth/controller/PhabricatorAuthRegisterController.php
··· 20 20 return $this->renderError(pht('You are already logged in.')); 21 21 } 22 22 23 + $is_setup = false; 23 24 if (strlen($this->accountKey)) { 24 25 $result = $this->loadAccountForRegistrationOrLinking($this->accountKey); 25 26 list($account, $provider, $response) = $result; 26 27 $is_default = false; 28 + } else if ($this->isFirstTimeSetup()) { 29 + list($account, $provider, $response) = $this->loadSetupAccount(); 30 + $is_default = true; 31 + $is_setup = true; 27 32 } else { 28 33 list($account, $provider, $response) = $this->loadDefaultAccount(); 29 34 $is_default = true; ··· 213 218 $editor->changePassword($user, $envelope); 214 219 } 215 220 221 + if ($is_setup) { 222 + $editor->makeAdminUser($user, true); 223 + } 224 + 216 225 $account->setUserPHID($user->getPHID()); 217 226 $provider->willRegisterAccount($account); 218 227 $account->save(); ··· 319 328 ->setError($e_realname)); 320 329 } 321 330 322 - $form->appendChild( 323 - id(new AphrontFormSubmitControl()) 331 + $submit = id(new AphrontFormSubmitControl()); 332 + 333 + if ($is_setup) { 334 + $submit 335 + ->setValue(pht('Create Admin Account')); 336 + } else { 337 + $submit 324 338 ->addCancelButton($this->getApplicationURI('start/')) 325 - ->setValue(pht('Register Phabricator Account'))); 339 + ->setValue(pht('Register Phabricator Account')); 340 + } 326 341 327 - $title = pht('Phabricator Registration'); 342 + 343 + $form->appendChild($submit); 328 344 329 345 $crumbs = $this->buildApplicationCrumbs(); 330 - $crumbs->addCrumb( 331 - id(new PhabricatorCrumbView()) 332 - ->setName(pht('Register'))); 333 - $crumbs->addCrumb( 334 - id(new PhabricatorCrumbView()) 335 - ->setName($provider->getProviderName())); 346 + 347 + if ($is_setup) { 348 + $crumbs->addCrumb( 349 + id(new PhabricatorCrumbView()) 350 + ->setName(pht('Setup Admin Account'))); 351 + $title = pht('Welcome to Phabricator'); 352 + } else { 353 + $crumbs->addCrumb( 354 + id(new PhabricatorCrumbView()) 355 + ->setName(pht('Register'))); 356 + $crumbs->addCrumb( 357 + id(new PhabricatorCrumbView()) 358 + ->setName($provider->getProviderName())); 359 + $title = pht('Phabricator Registration'); 360 + } 361 + 362 + $welcome_view = null; 363 + if ($is_setup) { 364 + $welcome_view = id(new AphrontErrorView()) 365 + ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) 366 + ->setTitle(pht('Welcome to Phabricator')) 367 + ->appendChild( 368 + pht( 369 + 'Installation is complete. Register your administrator account '. 370 + 'below to log in. You will be able to configure options and add '. 371 + 'other authentication mechanisms (like LDAP or OAuth) later on.')); 372 + } 336 373 337 374 return $this->buildApplicationPage( 338 375 array( 339 376 $crumbs, 377 + $welcome_view, 340 378 $error_view, 341 379 $form, 342 380 ), ··· 378 416 $provider = head($providers); 379 417 $account = $provider->getDefaultExternalAccount(); 380 418 419 + return array($account, $provider, $response); 420 + } 421 + 422 + private function loadSetupAccount() { 423 + $provider = new PhabricatorAuthProviderPassword(); 424 + $account = $provider->getDefaultExternalAccount(); 425 + $response = null; 381 426 return array($account, $provider, $response); 382 427 } 383 428
+7
src/applications/auth/controller/PhabricatorAuthStartController.php
··· 44 44 } 45 45 46 46 if (!$providers) { 47 + if ($this->isFirstTimeSetup()) { 48 + // If this is a fresh install, let the user register their admin 49 + // account. 50 + return id(new AphrontRedirectResponse()) 51 + ->setURI($this->getApplicationURI('/register/')); 52 + } 53 + 47 54 return $this->renderError( 48 55 pht( 49 56 "This Phabricator install is not configured with any enabled ".
+27
src/applications/config/check/PhabricatorSetupCheckAuth.php
··· 1 + <?php 2 + 3 + final class PhabricatorSetupCheckAuth extends PhabricatorSetupCheck { 4 + 5 + protected function executeChecks() { 6 + $providers = PhabricatorAuthProvider::getAllEnabledProviders(); 7 + if (!$providers) { 8 + $message = pht( 9 + 'You have not configured any authentication providers yet. You '. 10 + 'should add a provider (like username/password, LDAP, or GitHub '. 11 + 'OAuth) so users can register and log in. You can add and configure '. 12 + 'providers %s.', 13 + phutil_tag( 14 + 'a', 15 + array( 16 + 'href' => '/auth/', 17 + ), 18 + pht('using the "Auth" application'))); 19 + 20 + $this 21 + ->newIssue('auth.noproviders') 22 + ->setShortName(pht('No Auth Providers')) 23 + ->setName(pht('No Authentication Providers Configured')) 24 + ->setMessage($message); 25 + } 26 + } 27 + }