Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / auth / management / PhabricatorAuthManagementRecoverWorkflow.php
blob21ef32ae05964b55e470cd207aec24c2b05472a3
1 <?php
3 final class PhabricatorAuthManagementRecoverWorkflow
4 extends PhabricatorAuthManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('recover')
9 ->setExamples('**recover** __username__')
10 ->setSynopsis(
11 pht(
12 'Recover access to an account if you have locked yourself out.'))
13 ->setArguments(
14 array(
15 array(
16 'name' => 'force-full-session',
17 'help' => pht(
18 'Recover directly into a full session without requiring MFA '.
19 'or other login checks.'),
21 array(
22 'name' => 'username',
23 'wildcard' => true,
25 ));
28 public function execute(PhutilArgumentParser $args) {
29 $usernames = $args->getArg('username');
30 if (!$usernames) {
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))
43 ->executeOne();
45 if (!$user) {
46 throw new PhutilArgumentUsageException(
47 pht(
48 'No such user "%s" to recover.',
49 $username));
52 if (!$user->canEstablishWebSessions()) {
53 throw new PhutilArgumentUsageException(
54 pht(
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 '.
58 'web UI.',
59 $username));
62 $force_full_session = $args->getArg('force-full-session');
64 $engine = new PhabricatorAuthSessionEngine();
65 $onetime_uri = $engine->getOneTimeLoginURI(
66 $user,
67 null,
68 PhabricatorAuthSessionEngine::ONETIME_RECOVER,
69 $force_full_session);
71 $console = PhutilConsole::getConsole();
72 $console->writeOut(
73 pht(
74 'Use this link to recover access to the "%s" account from the web '.
75 'interface:',
76 $username));
77 $console->writeOut("\n\n");
78 $console->writeOut(' %s', $onetime_uri);
79 $console->writeOut("\n\n");
80 $console->writeOut(
81 "%s\n",
82 pht(
83 'After logging in, you can use the "Auth" application to add or '.
84 'restore authentication providers and allow normal logins to '.
85 'succeed.'));
87 return 0;