@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PassphraseCredentialPublicController
4 extends PassphraseController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
9
10 $credential = id(new PassphraseCredentialQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->requireCapabilities(
14 array(
15 PhabricatorPolicyCapability::CAN_VIEW,
16 ))
17 ->executeOne();
18 if (!$credential) {
19 return new Aphront404Response();
20 }
21
22 $type = PassphraseCredentialType::getTypeByConstant(
23 $credential->getCredentialType());
24 if (!$type) {
25 throw new Exception(pht('Credential has invalid type "%s"!', $type));
26 }
27
28 if (!$type->hasPublicKey()) {
29 throw new Exception(pht('Credential has no public key!'));
30 }
31
32 $view_uri = '/'.$credential->getMonogram();
33
34 $public_key = $type->getPublicKey($viewer, $credential);
35
36 $body = id(new PHUIFormLayoutView())
37 ->appendChild(
38 id(new AphrontFormTextAreaControl())
39 ->setLabel(pht('Public Key'))
40 ->setReadOnly(true)
41 ->setValue($public_key));
42
43 return $this->newDialog()
44 ->setWidth(AphrontDialogView::WIDTH_FORM)
45 ->setTitle(pht('Public Key (%s)', $credential->getMonogram()))
46 ->appendChild($body)
47 ->addCancelButton($view_uri, pht('Done'));
48
49 }
50
51}