[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/passphrase/controller/ -> PassphraseCredentialPublicController.php (source)

   1  <?php
   2  
   3  final class PassphraseCredentialPublicController
   4    extends PassphraseController {
   5  
   6    private $id;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->id = $data['id'];
  10    }
  11  
  12    public function processRequest() {
  13      $request = $this->getRequest();
  14      $viewer = $request->getUser();
  15  
  16      $credential = id(new PassphraseCredentialQuery())
  17        ->setViewer($viewer)
  18        ->withIDs(array($this->id))
  19        ->requireCapabilities(
  20          array(
  21            PhabricatorPolicyCapability::CAN_VIEW,
  22          ))
  23        ->executeOne();
  24      if (!$credential) {
  25        return new Aphront404Response();
  26      }
  27  
  28      $type = PassphraseCredentialType::getTypeByConstant(
  29        $credential->getCredentialType());
  30      if (!$type) {
  31        throw new Exception(pht('Credential has invalid type "%s"!', $type));
  32      }
  33  
  34      if (!$type->hasPublicKey()) {
  35        throw new Exception(pht('Credential has no public key!'));
  36      }
  37  
  38      $view_uri = '/'.$credential->getMonogram();
  39  
  40      $public_key = $type->getPublicKey($viewer, $credential);
  41  
  42      $body = id(new PHUIFormLayoutView())
  43        ->appendChild(
  44          id(new AphrontFormTextAreaControl())
  45            ->setLabel(pht('Public Key'))
  46            ->setReadOnly(true)
  47            ->setValue($public_key));
  48  
  49      $dialog = id(new AphrontDialogView())
  50        ->setUser($viewer)
  51        ->setWidth(AphrontDialogView::WIDTH_FORM)
  52        ->setTitle(pht('Public Key (%s)', $credential->getMonogram()))
  53        ->appendChild($body)
  54        ->addCancelButton($view_uri, pht('Done'));
  55  
  56      return id(new AphrontDialogResponse())->setDialog($dialog);
  57    }
  58  
  59  }


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