Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/controller/PhabricatorEmailVerificationController.php
12256 views
1
<?php
2
3
final class PhabricatorEmailVerificationController
4
extends PhabricatorAuthController {
5
6
public function shouldRequireEmailVerification() {
7
// Since users need to be able to hit this endpoint in order to verify
8
// email, we can't ever require email verification here.
9
return false;
10
}
11
12
public function shouldRequireEnabledUser() {
13
// Unapproved users are allowed to verify their email addresses. We'll kick
14
// disabled users out later.
15
return false;
16
}
17
18
public function handleRequest(AphrontRequest $request) {
19
$viewer = $this->getViewer();
20
$code = $request->getURIData('code');
21
22
if ($viewer->getIsDisabled()) {
23
// We allowed unapproved and disabled users to hit this controller, but
24
// want to kick out disabled users now.
25
return new Aphront400Response();
26
}
27
28
$email = id(new PhabricatorUserEmail())->loadOneWhere(
29
'userPHID = %s AND verificationCode = %s',
30
$viewer->getPHID(),
31
$code);
32
33
$submit = null;
34
35
if (!$email) {
36
$title = pht('Unable to Verify Email');
37
$content = pht(
38
'The verification code you provided is incorrect, or the email '.
39
'address has been removed, or the email address is owned by another '.
40
'user. Make sure you followed the link in the email correctly and are '.
41
'logged in with the user account associated with the email address.');
42
$continue = pht('Rats!');
43
} else if ($email->getIsVerified() && $viewer->getIsEmailVerified()) {
44
$title = pht('Address Already Verified');
45
$content = pht(
46
'This email address has already been verified.');
47
$continue = pht('Continue');
48
} else if ($request->isFormPost()) {
49
50
id(new PhabricatorUserEditor())
51
->setActor($viewer)
52
->verifyEmail($viewer, $email);
53
54
$title = pht('Address Verified');
55
$content = pht(
56
'The email address %s is now verified.',
57
phutil_tag('strong', array(), $email->getAddress()));
58
$continue = pht('Continue');
59
} else {
60
$title = pht('Verify Email Address');
61
$content = pht(
62
'Verify this email address (%s) and attach it to your account?',
63
phutil_tag('strong', array(), $email->getAddress()));
64
$continue = pht('Cancel');
65
$submit = pht('Verify %s', $email->getAddress());
66
}
67
68
$dialog = id(new AphrontDialogView())
69
->setUser($viewer)
70
->setTitle($title)
71
->addCancelButton('/', $continue)
72
->appendChild($content);
73
74
if ($submit) {
75
$dialog->addSubmitButton($submit);
76
}
77
78
$crumbs = $this->buildApplicationCrumbs();
79
$crumbs->addTextCrumb(pht('Verify Email'));
80
$crumbs->setBorder(true);
81
82
return $this->newPage()
83
->setTitle(pht('Verify Email'))
84
->setCrumbs($crumbs)
85
->appendChild($dialog);
86
87
}
88
89
}
90
91