[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/settings/panel/ -> PhabricatorSettingsPanelConduit.php (source)

   1  <?php
   2  
   3  final class PhabricatorSettingsPanelConduit
   4    extends PhabricatorSettingsPanel {
   5  
   6    public function isEditableByAdministrators() {
   7      return true;
   8    }
   9  
  10    public function getPanelKey() {
  11      return 'conduit';
  12    }
  13  
  14    public function getPanelName() {
  15      return pht('Conduit Certificate');
  16    }
  17  
  18    public function getPanelGroup() {
  19      return pht('Authentication');
  20    }
  21  
  22    public function processRequest(AphrontRequest $request) {
  23      $user = $this->getUser();
  24      $viewer = $request->getUser();
  25  
  26      id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
  27        $viewer,
  28        $request,
  29        '/settings/');
  30  
  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.')));
  42  
  43          return id(new AphrontDialogResponse())
  44            ->setDialog($dialog);
  45        }
  46  
  47        $sessions = id(new PhabricatorAuthSessionQuery())
  48          ->setViewer($user)
  49          ->withIdentityPHIDs(array($user->getPHID()))
  50          ->withSessionTypes(array(PhabricatorAuthSession::TYPE_CONDUIT))
  51          ->execute();
  52        foreach ($sessions as $session) {
  53          $session->delete();
  54        }
  55  
  56        // This implicitly regenerates the certificate.
  57        $user->setConduitCertificate(null);
  58        $user->save();
  59        return id(new AphrontRedirectResponse())
  60          ->setURI($this->getPanelURI('?regenerated=true'));
  61      }
  62  
  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(
  68          'p',
  69          array(),
  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();
  74      } else {
  75        $notice = null;
  76      }
  77  
  78      Javelin::initBehavior('select-on-click');
  79  
  80      $cert_form = new AphrontFormView();
  81      $cert_form
  82        ->setUser($viewer)
  83        ->appendChild(phutil_tag(
  84          'p',
  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'))))
  89        ->appendChild(
  90          id(new AphrontFormTextAreaControl())
  91            ->setLabel(pht('Certificate'))
  92            ->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)
  93            ->setReadonly(true)
  94            ->setSigil('select-on-click')
  95            ->setValue($user->getConduitCertificate()));
  96  
  97      $cert_form = id(new PHUIObjectBoxView())
  98        ->setHeaderText(pht('Arcanist Certificate'))
  99        ->setForm($cert_form);
 100  
 101      $regen_instruction = pht('You can regenerate this certificate, which '.
 102        'will invalidate the old certificate and create a new one.');
 103  
 104      $regen_form = new AphrontFormView();
 105      $regen_form
 106        ->setUser($viewer)
 107        ->setAction($this->getPanelURI())
 108        ->setWorkflow(true)
 109        ->appendChild(phutil_tag(
 110          'p',
 111          array('class' => 'aphront-form-instructions'),
 112          $regen_instruction))
 113        ->appendChild(
 114          id(new AphrontFormSubmitControl())
 115            ->setValue(pht('Regenerate Certificate')));
 116  
 117      $regen_form = id(new PHUIObjectBoxView())
 118        ->setHeaderText(pht('Regenerate Certificate'))
 119        ->setForm($regen_form);
 120  
 121      return array(
 122        $notice,
 123        $cert_form,
 124        $regen_form,
 125      );
 126    }
 127  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1