3 final class PhabricatorAuthNeedsMultiFactorController
4 extends PhabricatorAuthController
{
6 public function shouldRequireMultiFactorEnrollment() {
7 // Users need access to this controller in order to enroll in multi-factor
12 public function shouldRequireEnabledUser() {
13 // Users who haven't been approved yet are allowed to enroll in MFA. We'll
14 // kick disabled users out later.
18 public function shouldRequireEmailVerification() {
19 // Users who haven't verified their email addresses yet can still enroll
24 public function handleRequest(AphrontRequest
$request) {
25 $viewer = $this->getViewer();
27 if ($viewer->getIsDisabled()) {
28 // We allowed unapproved and disabled users to hit this controller, but
29 // want to kick out disabled users now.
30 return new Aphront400Response();
33 $panels = $this->loadPanels();
35 $multifactor_key = id(new PhabricatorMultiFactorSettingsPanel())
38 $panel_key = $request->getURIData('pageKey');
39 if (!strlen($panel_key)) {
40 $panel_key = $multifactor_key;
43 if (!isset($panels[$panel_key])) {
44 return new Aphront404Response();
47 $nav = $this->newNavigation();
48 $nav->selectFilter($panel_key);
50 $panel = $panels[$panel_key];
52 $viewer->updateMultiFactorEnrollment();
54 if ($panel_key === $multifactor_key) {
55 $header_text = pht('Add Multi-Factor Auth');
56 $help = $this->newGuidance();
57 $panel->setIsEnrollment(true);
59 $header_text = $panel->getPanelName();
64 ->setController($this)
66 ->processRequest($request);
68 if (($response instanceof AphrontResponse
) ||
69 ($response instanceof AphrontResponseProducerInterface
)) {
73 $crumbs = $this->buildApplicationCrumbs()
74 ->addTextCrumb(pht('Add Multi-Factor Auth'))
77 $header = id(new PHUIHeaderView())
78 ->setHeader($header_text);
80 $view = id(new PHUITwoColumnView())
88 return $this->newPage()
89 ->setTitle(pht('Add Multi-Factor Authentication'))
96 private function loadPanels() {
97 $viewer = $this->getViewer();
98 $preferences = PhabricatorUserPreferences
::loadUserPreferences($viewer);
100 $panels = PhabricatorSettingsPanel
::getAllDisplayPanels();
101 $base_uri = $this->newEnrollBaseURI();
104 foreach ($panels as $key => $panel) {
106 ->setPreferences($preferences)
109 ->setOverrideURI(urisprintf('%s%s/', $base_uri, $key));
111 if (!$panel->isEnabled()) {
115 if (!$panel->isUserPanel()) {
119 if (!$panel->isMultiFactorEnrollmentPanel()) {
123 if (!empty($result[$key])) {
124 throw new Exception(pht(
125 "Two settings panels share the same panel key ('%s'): %s, %s.",
128 get_class($result[$key])));
131 $result[$key] = $panel;
138 private function newNavigation() {
139 $viewer = $this->getViewer();
141 $enroll_uri = $this->newEnrollBaseURI();
143 $nav = id(new AphrontSideNavFilterView())
144 ->setBaseURI(new PhutilURI($enroll_uri));
146 $multifactor_key = id(new PhabricatorMultiFactorSettingsPanel())
151 pht('Enroll in MFA'),
153 'fa-exclamation-triangle blue');
155 $panels = $this->loadPanels();
158 $nav->addLabel(pht('Settings'));
161 foreach ($panels as $panel_key => $panel) {
162 if ($panel_key === $multifactor_key) {
167 $panel->getPanelKey(),
168 $panel->getPanelName(),
170 $panel->getPanelMenuIcon());
176 private function newEnrollBaseURI() {
177 return $this->getApplicationURI('enroll/');
180 private function newGuidance() {
181 $viewer = $this->getViewer();
183 if ($viewer->getIsEnrolledInMultiFactor()) {
185 '{icon check, color="green"} **Setup Complete!**'.
187 'You have successfully configured multi-factor authentication '.
190 'You can make adjustments from the [[ /settings/ | Settings ]] panel '.
193 return $this->newDialog()
194 ->setTitle(pht('Multi-Factor Authentication Setup Complete'))
195 ->setWidth(AphrontDialogView
::WIDTH_FULL
)
196 ->appendChild(new PHUIRemarkupView($viewer, $guidance))
197 ->addCancelButton('/', pht('Continue'));
205 'Before you can use this software, you need to add multi-factor '.
206 'authentication to your account. Multi-factor authentication helps '.
207 'secure your account by making it more difficult for attackers to '.
208 'gain access or take sensitive actions.');
210 $view = id(new PHUIInfoView())
211 ->setTitle(pht('Add Multi-Factor Authentication To Your Account'))
212 ->setSeverity(PHUIInfoView
::SEVERITY_WARNING
)
213 ->setErrors($messages);
218 $providers = id(new PhabricatorAuthFactorProviderQuery())
222 PhabricatorAuthFactorProviderStatus
::STATUS_ACTIVE
,
228 $required_key = 'security.require-multi-factor-auth';
231 'This install has the configuration option "%s" enabled, but does '.
232 'not have any active multifactor providers configured. This means '.
233 'you are required to add MFA, but are also prevented from doing so. '.
234 'An administrator must disable "%s" or enable an MFA provider to '.
235 'allow you to continue.',
239 $view = id(new PHUIInfoView())
240 ->setTitle(pht('Multi-Factor Authentication is Misconfigured'))
241 ->setSeverity(PHUIInfoView
::SEVERITY_ERROR
)
242 ->setErrors($messages);