2011-07-18 17:02:00 +02:00
|
|
|
<?php
|
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
final class PhabricatorSettingsPanelConduit
|
|
|
|
extends PhabricatorSettingsPanel {
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
public function getPanelKey() {
|
|
|
|
return 'conduit';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelName() {
|
|
|
|
return pht('Conduit');
|
|
|
|
}
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
public function getPanelGroup() {
|
|
|
|
return pht('Authentication');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest(AphrontRequest $request) {
|
2011-07-18 17:02:00 +02:00
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
if (!$request->isDialogFormPost()) {
|
|
|
|
$dialog = new AphrontDialogView();
|
|
|
|
$dialog->setUser($user);
|
2013-03-03 15:52:42 +01:00
|
|
|
$dialog->setTitle(pht('Really regenerate session?'));
|
2012-08-13 21:37:26 +02:00
|
|
|
$dialog->setSubmitURI($this->getPanelURI());
|
2013-03-03 15:52:42 +01:00
|
|
|
$dialog->addSubmitButton(pht('Regenerate'));
|
2012-08-13 21:37:26 +02:00
|
|
|
$dialog->addCancelbutton($this->getPanelURI());
|
2013-02-13 23:50:15 +01:00
|
|
|
$dialog->appendChild(phutil_tag('p', array(), pht(
|
|
|
|
'Really destroy the old certificate? Any established '.
|
|
|
|
'sessions will be terminated.')));
|
2011-07-18 17:02:00 +02:00
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())
|
|
|
|
->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
$conn = $user->establishConnection('w');
|
|
|
|
queryfx(
|
|
|
|
$conn,
|
|
|
|
'DELETE FROM %T WHERE userPHID = %s AND type LIKE %>',
|
|
|
|
PhabricatorUser::SESSION_TABLE,
|
|
|
|
$user->getPHID(),
|
|
|
|
'conduit');
|
|
|
|
|
|
|
|
// This implicitly regenerates the certificate.
|
|
|
|
$user->setConduitCertificate(null);
|
|
|
|
$user->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
2012-08-13 21:37:26 +02:00
|
|
|
->setURI($this->getPanelURI('?regenerated=true'));
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->getStr('regenerated')) {
|
|
|
|
$notice = new AphrontErrorView();
|
|
|
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
2013-03-03 15:52:42 +01:00
|
|
|
$notice->setTitle(pht('Certificate Regenerated'));
|
2013-02-07 01:53:49 +01:00
|
|
|
$notice->appendChild(phutil_tag(
|
|
|
|
'p',
|
|
|
|
array(),
|
2013-03-03 15:52:42 +01:00
|
|
|
pht('Your old certificate has been destroyed and you have been issued '.
|
2011-07-18 17:02:00 +02:00
|
|
|
'a new certificate. Sessions established under the old certificate '.
|
2013-03-03 15:52:42 +01:00
|
|
|
'are no longer valid.')));
|
2011-07-18 17:02:00 +02:00
|
|
|
$notice = $notice->render();
|
|
|
|
} else {
|
|
|
|
$notice = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cert_form = new AphrontFormView();
|
|
|
|
$cert_form
|
|
|
|
->setUser($user)
|
2013-02-07 23:39:04 +01:00
|
|
|
->appendChild(hsprintf(
|
2013-03-03 15:52:42 +01:00
|
|
|
'<p class="aphront-form-instructions">%s</p>',
|
|
|
|
pht('This certificate allows you to authenticate over Conduit, '.
|
|
|
|
'the Phabricator API. Normally, you just run %s to install it.',
|
|
|
|
hsprintf('<tt>%s</tt>', 'arc install-certificate'))))
|
2011-07-18 17:02:00 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setLabel(pht('Certificate'))
|
2011-07-18 17:02:00 +02:00
|
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)
|
|
|
|
->setValue($user->getConduitCertificate()));
|
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$cert_form = id(new PHUIObjectBoxView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setHeaderText(pht('Arcanist Certificate'))
|
|
|
|
->setForm($cert_form);
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2013-03-03 15:52:42 +01:00
|
|
|
$regen_instruction = pht('You can regenerate this certificate, which '.
|
|
|
|
'will invalidate the old certificate and create a new one.');
|
|
|
|
|
2011-07-18 17:02:00 +02:00
|
|
|
$regen_form = new AphrontFormView();
|
|
|
|
$regen_form
|
|
|
|
->setUser($user)
|
2012-08-13 21:37:26 +02:00
|
|
|
->setAction($this->getPanelURI())
|
|
|
|
->setWorkflow(true)
|
2013-02-07 23:39:04 +01:00
|
|
|
->appendChild(hsprintf(
|
2013-03-03 15:52:42 +01:00
|
|
|
'<p class="aphront-form-instructions">%s</p>', $regen_instruction))
|
2011-07-18 17:02:00 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setValue(pht('Regenerate Certificate')));
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$regen_form = id(new PHUIObjectBoxView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setHeaderText(pht('Regenerate Certificate'))
|
|
|
|
->setForm($regen_form);
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
return array(
|
|
|
|
$notice,
|
2013-05-08 03:08:12 +02:00
|
|
|
$cert_form,
|
|
|
|
$regen_form,
|
2012-08-13 21:37:26 +02:00
|
|
|
);
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
}
|