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 '.
17 'name' => 'force-full-session',
19 'Recover directly into a full session without requiring MFA '.
20 'or other login checks.'),
29 public function execute(PhutilArgumentParser
$args) {
30 $usernames = $args->getArg('username');
32 throw new PhutilArgumentUsageException(
33 pht('You must specify the username of the account to recover.'));
34 } else if (count($usernames) > 1) {
35 throw new PhutilArgumentUsageException(
36 pht('You can only recover the username for one account.'));
39 $username = head($usernames);
41 $user = id(new PhabricatorPeopleQuery())
42 ->setViewer($this->getViewer())
43 ->withUsernames(array($username))
47 throw new PhutilArgumentUsageException(
49 'No such user "%s" to recover.',
53 if (!$user->canEstablishWebSessions()) {
54 throw new PhutilArgumentUsageException(
56 'This account ("%s") can not establish web sessions, so it is '.
57 'not possible to generate a functional recovery link. Special '.
58 'accounts like daemons and mailing lists can not log in via the '.
63 $force_full_session = $args->getArg('force-full-session');
65 $engine = new PhabricatorAuthSessionEngine();
66 $onetime_uri = $engine->getOneTimeLoginURI(
69 PhabricatorAuthSessionEngine
::ONETIME_RECOVER
,
72 $console = PhutilConsole
::getConsole();
75 'Use this link to recover access to the "%s" account from the web '.
78 $console->writeOut("\n\n");
79 $console->writeOut(' %s', $onetime_uri);
80 $console->writeOut("\n\n");
84 'After logging in, you can use the "Auth" application to add or '.
85 'restore authentication providers and allow normal logins to '.