Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/management/PhabricatorAuthManagementVerifyWorkflow.php
12256 views
1
<?php
2
3
final class PhabricatorAuthManagementVerifyWorkflow
4
extends PhabricatorAuthManagementWorkflow {
5
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,
20
),
21
));
22
}
23
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.'));
32
}
33
$address = head($emails);
34
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));
43
}
44
45
$viewer = $this->getViewer();
46
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!'));
53
}
54
55
$editor = id(new PhabricatorUserEditor())
56
->setActor($viewer)
57
->verifyEmail($user, $email);
58
59
$console = PhutilConsole::getConsole();
60
61
$console->writeOut(
62
"%s\n",
63
pht('Done.'));
64
65
return 0;
66
}
67
68
}
69
70