[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/conduit/controller/ -> PhabricatorConduitTokenController.php (source)

   1  <?php
   2  
   3  final class PhabricatorConduitTokenController
   4    extends PhabricatorConduitController {
   5  
   6    public function processRequest() {
   7      $user = $this->getRequest()->getUser();
   8  
   9      id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
  10        $user,
  11        $this->getRequest(),
  12        '/');
  13  
  14      // Ideally we'd like to verify this, but it's fine to leave it unguarded
  15      // for now and verifying it would need some Ajax junk or for the user to
  16      // click a button or similar.
  17      $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
  18  
  19      $old_token = id(new PhabricatorConduitCertificateToken())
  20        ->loadOneWhere(
  21          'userPHID = %s',
  22          $user->getPHID());
  23      if ($old_token) {
  24        $old_token->delete();
  25      }
  26  
  27      $token = id(new PhabricatorConduitCertificateToken())
  28        ->setUserPHID($user->getPHID())
  29        ->setToken(Filesystem::readRandomCharacters(40))
  30        ->save();
  31  
  32      unset($unguarded);
  33  
  34      $pre_instructions = pht(
  35        'Copy and paste this token into the prompt given to you by '.
  36        '`arc install-certificate`');
  37  
  38      $post_instructions = pht(
  39        'After you copy and paste this token, `arc` will complete '.
  40        'the certificate install process for you.');
  41  
  42      Javelin::initBehavior('select-on-click');
  43  
  44      $form = id(new AphrontFormView())
  45        ->setUser($user)
  46        ->appendRemarkupInstructions($pre_instructions)
  47        ->appendChild(
  48          id(new AphrontFormTextAreaControl())
  49            ->setLabel(pht('Token'))
  50            ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
  51            ->setReadonly(true)
  52            ->setSigil('select-on-click')
  53            ->setValue($token->getToken()))
  54        ->appendRemarkupInstructions($post_instructions);
  55  
  56      $crumbs = $this->buildApplicationCrumbs();
  57      $crumbs->addTextCrumb(pht('Install Certificate'));
  58  
  59      $object_box = id(new PHUIObjectBoxView())
  60        ->setHeaderText(pht('Certificate Token'))
  61        ->setForm($form);
  62  
  63      return $this->buildApplicationPage(
  64        array(
  65          $crumbs,
  66          $object_box,
  67        ),
  68        array(
  69          'title' => pht('Certificate Install Token'),
  70        ));
  71    }
  72  
  73  }


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