diff --git a/src/applications/conduit/controller/PhabricatorConduitTokenController.php b/src/applications/conduit/controller/PhabricatorConduitTokenController.php index 4a44c558c0..1bb0dfa2b9 100644 --- a/src/applications/conduit/controller/PhabricatorConduitTokenController.php +++ b/src/applications/conduit/controller/PhabricatorConduitTokenController.php @@ -1,68 +1,72 @@ getRequest()->getUser(); // Ideally we'd like to verify this, but it's fine to leave it unguarded // for now and verifying it would need some Ajax junk or for the user to // click a button or similar. $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $old_token = id(new PhabricatorConduitCertificateToken()) ->loadOneWhere( 'userPHID = %s', $user->getPHID()); if ($old_token) { $old_token->delete(); } $token = id(new PhabricatorConduitCertificateToken()) ->setUserPHID($user->getPHID()) ->setToken(Filesystem::readRandomCharacters(40)) ->save(); unset($unguarded); $pre_instructions = pht( 'Copy and paste this token into the prompt given to you by '. '`arc install-certificate`'); $post_instructions = pht( 'After you copy and paste this token, `arc` will complete '. 'the certificate install process for you.'); + Javelin::initBehavior('select-on-click'); + $form = id(new AphrontFormView()) ->setUser($user) ->appendRemarkupInstructions($pre_instructions) ->appendChild( id(new AphrontFormTextAreaControl()) ->setLabel(pht('Token')) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) + ->setReadonly(true) + ->setSigil('select-on-click') ->setValue($token->getToken())) ->appendRemarkupInstructions($post_instructions); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Install Certificate')); $object_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Certificate Token')) ->setForm($form); return $this->buildApplicationPage( array( $crumbs, $object_box, ), array( 'title' => pht('Certificate Install Token'), 'device' => true, )); } } diff --git a/src/applications/settings/panel/PhabricatorSettingsPanelConduit.php b/src/applications/settings/panel/PhabricatorSettingsPanelConduit.php index e44d86e8f9..afbb1b78e2 100644 --- a/src/applications/settings/panel/PhabricatorSettingsPanelConduit.php +++ b/src/applications/settings/panel/PhabricatorSettingsPanelConduit.php @@ -1,112 +1,116 @@ getUser(); if ($request->isFormPost()) { if (!$request->isDialogFormPost()) { $dialog = new AphrontDialogView(); $dialog->setUser($user); $dialog->setTitle(pht('Really regenerate session?')); $dialog->setSubmitURI($this->getPanelURI()); $dialog->addSubmitButton(pht('Regenerate')); $dialog->addCancelbutton($this->getPanelURI()); $dialog->appendChild(phutil_tag('p', array(), pht( 'Really destroy the old certificate? Any established '. 'sessions will be terminated.'))); 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()) ->setURI($this->getPanelURI('?regenerated=true')); } if ($request->getStr('regenerated')) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle(pht('Certificate Regenerated')); $notice->appendChild(phutil_tag( 'p', array(), pht('Your old certificate has been destroyed and you have been issued '. 'a new certificate. Sessions established under the old certificate '. 'are no longer valid.'))); $notice = $notice->render(); } else { $notice = null; } + Javelin::initBehavior('select-on-click'); + $cert_form = new AphrontFormView(); $cert_form ->setUser($user) ->appendChild(phutil_tag( 'p', array('class' => 'aphront-form-instructions'), pht('This certificate allows you to authenticate over Conduit, '. 'the Phabricator API. Normally, you just run %s to install it.', phutil_tag('tt', array(), 'arc install-certificate')))) ->appendChild( id(new AphrontFormTextAreaControl()) ->setLabel(pht('Certificate')) ->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT) + ->setReadonly(true) + ->setSigil('select-on-click') ->setValue($user->getConduitCertificate())); $cert_form = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Arcanist Certificate')) ->setForm($cert_form); $regen_instruction = pht('You can regenerate this certificate, which '. 'will invalidate the old certificate and create a new one.'); $regen_form = new AphrontFormView(); $regen_form ->setUser($user) ->setAction($this->getPanelURI()) ->setWorkflow(true) ->appendChild(phutil_tag( 'p', array('class' => 'aphront-form-instructions'), $regen_instruction)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Regenerate Certificate'))); $regen_form = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Regenerate Certificate')) ->setForm($regen_form); return array( $notice, $cert_form, $regen_form, ); } }