3 final class PhabricatorAuthManagementRecoverWorkflow
4 extends PhabricatorAuthManagementWorkflow
{
6 protected function didConstruct() {
9 ->setExamples('**recover** __username__')
12 'Recover access to an account if you have locked yourself out.'))
16 'name' => 'force-full-session',
18 'Recover directly into a full session without requiring MFA '.
19 'or other login checks.'),
28 public function execute(PhutilArgumentParser
$args) {
29 $usernames = $args->getArg('username');
31 throw new PhutilArgumentUsageException(
32 pht('You must specify the username of the account to recover.'));
33 } else if (count($usernames) > 1) {
34 throw new PhutilArgumentUsageException(
35 pht('You can only recover the username for one account.'));
38 $username = head($usernames);
40 $user = id(new PhabricatorPeopleQuery())
41 ->setViewer($this->getViewer())
42 ->withUsernames(array($username))
46 throw new PhutilArgumentUsageException(
48 'No such user "%s" to recover.',
52 if (!$user->canEstablishWebSessions()) {
53 throw new PhutilArgumentUsageException(
55 'This account ("%s") can not establish web sessions, so it is '.
56 'not possible to generate a functional recovery link. Special '.
57 'accounts like daemons and mailing lists can not log in via the '.
62 $force_full_session = $args->getArg('force-full-session');
64 $engine = new PhabricatorAuthSessionEngine();
65 $onetime_uri = $engine->getOneTimeLoginURI(
68 PhabricatorAuthSessionEngine
::ONETIME_RECOVER
,
71 $console = PhutilConsole
::getConsole();
74 'Use this link to recover access to the "%s" account from the web '.
77 $console->writeOut("\n\n");
78 $console->writeOut(' %s', $onetime_uri);
79 $console->writeOut("\n\n");
83 'After logging in, you can use the "Auth" application to add or '.
84 'restore authentication providers and allow normal logins to '.