Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderMessageController.php
12262 views
1
<?php
2
3
final class PhabricatorAuthFactorProviderMessageController
4
extends PhabricatorAuthFactorProviderController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$this->requireApplicationCapability(
8
AuthManageProvidersCapability::CAPABILITY);
9
10
$viewer = $request->getViewer();
11
$id = $request->getURIData('id');
12
13
$provider = id(new PhabricatorAuthFactorProviderQuery())
14
->setViewer($viewer)
15
->withIDs(array($id))
16
->requireCapabilities(
17
array(
18
PhabricatorPolicyCapability::CAN_VIEW,
19
PhabricatorPolicyCapability::CAN_EDIT,
20
))
21
->executeOne();
22
if (!$provider) {
23
return new Aphront404Response();
24
}
25
26
$cancel_uri = $provider->getURI();
27
$enroll_key =
28
PhabricatorAuthFactorProviderEnrollMessageTransaction::TRANSACTIONTYPE;
29
30
$message = $provider->getEnrollMessage();
31
32
if ($request->isFormOrHisecPost()) {
33
$message = $request->getStr('message');
34
35
$xactions = array();
36
37
$xactions[] = id(new PhabricatorAuthFactorProviderTransaction())
38
->setTransactionType($enroll_key)
39
->setNewValue($message);
40
41
$editor = id(new PhabricatorAuthFactorProviderEditor())
42
->setActor($viewer)
43
->setContentSourceFromRequest($request)
44
->setContinueOnNoEffect(true)
45
->setContinueOnMissingFields(true)
46
->setCancelURI($cancel_uri);
47
48
$editor->applyTransactions($provider, $xactions);
49
50
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
51
}
52
53
$default_message = $provider->getEnrollDescription($viewer);
54
$default_message = new PHUIRemarkupView($viewer, $default_message);
55
56
$form = id(new AphrontFormView())
57
->setViewer($viewer)
58
->appendRemarkupInstructions(
59
pht(
60
'When users add a factor for this provider, they are given this '.
61
'enrollment guidance by default:'))
62
->appendControl(
63
id(new AphrontFormMarkupControl())
64
->setLabel(pht('Default Message'))
65
->setValue($default_message))
66
->appendRemarkupInstructions(
67
pht(
68
'You may optionally customize the enrollment message users are '.
69
'presented with by providing a replacement message below:'))
70
->appendControl(
71
id(new PhabricatorRemarkupControl())
72
->setLabel(pht('Custom Message'))
73
->setName('message')
74
->setValue($message));
75
76
return $this->newDialog()
77
->setTitle(pht('Change Enroll Message'))
78
->setWidth(AphrontDialogView::WIDTH_FORM)
79
->appendForm($form)
80
->addCancelButton($cancel_uri)
81
->addSubmitButton(pht('Save'));
82
}
83
84
}
85
86