3
final class PhabricatorConduitCertificateSettingsPanel
4
extends PhabricatorSettingsPanel {
6
public function isEditableByAdministrators() {
10
public function getPanelKey() {
14
public function getPanelName() {
15
return pht('Conduit Certificate');
18
public function getPanelGroup() {
19
return pht('Authentication');
22
public function processRequest(AphrontRequest $request) {
23
$user = $this->getUser();
24
$viewer = $request->getUser();
26
id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
31
if ($request->isFormPost()) {
32
if (!$request->isDialogFormPost()) {
33
$dialog = new AphrontDialogView();
34
$dialog->setUser($viewer);
35
$dialog->setTitle(pht('Really regenerate session?'));
36
$dialog->setSubmitURI($this->getPanelURI());
37
$dialog->addSubmitButton(pht('Regenerate'));
38
$dialog->addCancelbutton($this->getPanelURI());
39
$dialog->appendChild(phutil_tag('p', array(), pht(
40
'Really destroy the old certificate? Any established '.
41
'sessions will be terminated.')));
43
return id(new AphrontDialogResponse())
47
$sessions = id(new PhabricatorAuthSessionQuery())
49
->withIdentityPHIDs(array($user->getPHID()))
50
->withSessionTypes(array(PhabricatorAuthSession::TYPE_CONDUIT))
52
foreach ($sessions as $session) {
56
// This implicitly regenerates the certificate.
57
$user->setConduitCertificate(null);
59
return id(new AphrontRedirectResponse())
60
->setURI($this->getPanelURI('?regenerated=true'));
63
if ($request->getStr('regenerated')) {
64
$notice = new AphrontErrorView();
65
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
66
$notice->setTitle(pht('Certificate Regenerated'));
67
$notice->appendChild(phutil_tag(
70
pht('Your old certificate has been destroyed and you have been issued '.
71
'a new certificate. Sessions established under the old certificate '.
72
'are no longer valid.')));
73
$notice = $notice->render();
78
Javelin::initBehavior('select-on-click');
80
$cert_form = new AphrontFormView();
83
->appendChild(phutil_tag(
85
array('class' => 'aphront-form-instructions'),
86
pht('This certificate allows you to authenticate over Conduit, '.
87
'the Phabricator API. Normally, you just run %s to install it.',
88
phutil_tag('tt', array(), 'arc install-certificate'))))
90
id(new AphrontFormTextAreaControl())
91
->setLabel(pht('Certificate'))
92
->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)
94
->setSigil('select-on-click')
95
->setValue($user->getConduitCertificate()));
97
$cert_form = id(new PHUIObjectBoxView())
98
->setHeaderText(pht('Arcanist Certificate'))
99
->setForm($cert_form);
101
$regen_instruction = pht('You can regenerate this certificate, which '.
102
'will invalidate the old certificate and create a new one.');
104
$regen_form = new AphrontFormView();
107
->setAction($this->getPanelURI())
109
->appendChild(phutil_tag(
111
array('class' => 'aphront-form-instructions'),
114
id(new AphrontFormSubmitControl())
115
->setValue(pht('Regenerate Certificate')));
117
$regen_form = id(new PHUIObjectBoxView())
118
->setHeaderText(pht('Regenerate Certificate'))
119
->setForm($regen_form);