Path: blob/master/src/applications/auth/management/PhabricatorAuthManagementRecoverWorkflow.php
12256 views
<?php12final class PhabricatorAuthManagementRecoverWorkflow3extends PhabricatorAuthManagementWorkflow {45protected function didConstruct() {6$this7->setName('recover')8->setExamples('**recover** __username__')9->setSynopsis(10pht(11'Recover access to an account if you have locked yourself out.'))12->setArguments(13array(14array(15'name' => 'force-full-session',16'help' => pht(17'Recover directly into a full session without requiring MFA '.18'or other login checks.'),19),20array(21'name' => 'username',22'wildcard' => true,23),24));25}2627public function execute(PhutilArgumentParser $args) {28$usernames = $args->getArg('username');29if (!$usernames) {30throw new PhutilArgumentUsageException(31pht('You must specify the username of the account to recover.'));32} else if (count($usernames) > 1) {33throw new PhutilArgumentUsageException(34pht('You can only recover the username for one account.'));35}3637$username = head($usernames);3839$user = id(new PhabricatorPeopleQuery())40->setViewer($this->getViewer())41->withUsernames(array($username))42->executeOne();4344if (!$user) {45throw new PhutilArgumentUsageException(46pht(47'No such user "%s" to recover.',48$username));49}5051if (!$user->canEstablishWebSessions()) {52throw new PhutilArgumentUsageException(53pht(54'This account ("%s") can not establish web sessions, so it is '.55'not possible to generate a functional recovery link. Special '.56'accounts like daemons and mailing lists can not log in via the '.57'web UI.',58$username));59}6061$force_full_session = $args->getArg('force-full-session');6263$engine = new PhabricatorAuthSessionEngine();64$onetime_uri = $engine->getOneTimeLoginURI(65$user,66null,67PhabricatorAuthSessionEngine::ONETIME_RECOVER,68$force_full_session);6970$console = PhutilConsole::getConsole();71$console->writeOut(72pht(73'Use this link to recover access to the "%s" account from the web '.74'interface:',75$username));76$console->writeOut("\n\n");77$console->writeOut(' %s', $onetime_uri);78$console->writeOut("\n\n");79$console->writeOut(80"%s\n",81pht(82'After logging in, you can use the "Auth" application to add or '.83'restore authentication providers and allow normal logins to '.84'succeed.'));8586return 0;87}8889}909192