Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / auth / management / PhabricatorAuthManagementVerifyWorkflow.php
blob59c66a9d4f6df0d79885f7c456729be1e89724b7
1 <?php
3 final class PhabricatorAuthManagementVerifyWorkflow
4 extends PhabricatorAuthManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('verify')
9 ->setExamples('**verify** __email__')
10 ->setSynopsis(
11 pht(
12 'Verify an unverified email address which is already attached to '.
13 'an account. This will also re-execute event hooks for addresses '.
14 'which are already verified.'))
15 ->setArguments(
16 array(
17 array(
18 'name' => 'email',
19 'wildcard' => true,
21 ));
24 public function execute(PhutilArgumentParser $args) {
25 $emails = $args->getArg('email');
26 if (!$emails) {
27 throw new PhutilArgumentUsageException(
28 pht('You must specify the email to verify.'));
29 } else if (count($emails) > 1) {
30 throw new PhutilArgumentUsageException(
31 pht('You can only verify one address at a time.'));
33 $address = head($emails);
35 $email = id(new PhabricatorUserEmail())->loadOneWhere(
36 'address = %s',
37 $address);
38 if (!$email) {
39 throw new PhutilArgumentUsageException(
40 pht(
41 'No email exists with address "%s"!',
42 $address));
45 $viewer = $this->getViewer();
47 $user = id(new PhabricatorPeopleQuery())
48 ->setViewer($viewer)
49 ->withPHIDs(array($email->getUserPHID()))
50 ->executeOne();
51 if (!$user) {
52 throw new Exception(pht('Email record has invalid user PHID!'));
55 $editor = id(new PhabricatorUserEditor())
56 ->setActor($viewer)
57 ->verifyEmail($user, $email);
59 $console = PhutilConsole::getConsole();
61 $console->writeOut(
62 "%s\n",
63 pht('Done.'));
65 return 0;