Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conduit/controller/PhabricatorConduitTokenController.php
12256 views
1
<?php
2
3
final class PhabricatorConduitTokenController
4
extends PhabricatorConduitController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $request->getViewer();
8
9
id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
10
$viewer,
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
$viewer->getPHID());
23
if ($old_token) {
24
$old_token->delete();
25
}
26
27
$token = id(new PhabricatorConduitCertificateToken())
28
->setUserPHID($viewer->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($viewer)
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
$crumbs->setBorder(true);
59
60
$object_box = id(new PHUIObjectBoxView())
61
->setHeaderText(pht('Certificate Token'))
62
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
63
->setForm($form);
64
65
$title = pht('Certificate Install Token');
66
67
$header = id(new PHUIHeaderView())
68
->setHeader($title);
69
70
$view = id(new PHUITwoColumnView())
71
->setHeader($header)
72
->setFooter($object_box);
73
74
return $this->newPage()
75
->setTitle($title)
76
->setCrumbs($crumbs)
77
->appendChild($view);
78
}
79
80
}
81
82