Differential D14265 Diff 34518 src/applications/conduit/controller/PhabricatorConduitTokenController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conduit/controller/PhabricatorConduitTokenController.php
<?php | <?php | ||||
final class PhabricatorConduitTokenController | final class PhabricatorConduitTokenController | ||||
extends PhabricatorConduitController { | extends PhabricatorConduitController { | ||||
public function processRequest() { | public function handleRequest(AphrontRequest $request) { | ||||
$user = $this->getRequest()->getUser(); | $viewer = $request->getViewer(); | ||||
id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( | id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( | ||||
$user, | $viewer, | ||||
$this->getRequest(), | $this->getRequest(), | ||||
'/'); | '/'); | ||||
// Ideally we'd like to verify this, but it's fine to leave it unguarded | // Ideally we'd like to verify this, but it's fine to leave it unguarded | ||||
// for now and verifying it would need some Ajax junk or for the user to | // for now and verifying it would need some Ajax junk or for the user to | ||||
// click a button or similar. | // click a button or similar. | ||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | ||||
$old_token = id(new PhabricatorConduitCertificateToken()) | $old_token = id(new PhabricatorConduitCertificateToken()) | ||||
->loadOneWhere( | ->loadOneWhere( | ||||
'userPHID = %s', | 'userPHID = %s', | ||||
$user->getPHID()); | $viewer->getPHID()); | ||||
if ($old_token) { | if ($old_token) { | ||||
$old_token->delete(); | $old_token->delete(); | ||||
} | } | ||||
$token = id(new PhabricatorConduitCertificateToken()) | $token = id(new PhabricatorConduitCertificateToken()) | ||||
->setUserPHID($user->getPHID()) | ->setUserPHID($viewer->getPHID()) | ||||
->setToken(Filesystem::readRandomCharacters(40)) | ->setToken(Filesystem::readRandomCharacters(40)) | ||||
->save(); | ->save(); | ||||
unset($unguarded); | unset($unguarded); | ||||
$pre_instructions = pht( | $pre_instructions = pht( | ||||
'Copy and paste this token into the prompt given to you by '. | 'Copy and paste this token into the prompt given to you by '. | ||||
'`arc install-certificate`'); | '`arc install-certificate`'); | ||||
$post_instructions = pht( | $post_instructions = pht( | ||||
'After you copy and paste this token, `arc` will complete '. | 'After you copy and paste this token, `arc` will complete '. | ||||
'the certificate install process for you.'); | 'the certificate install process for you.'); | ||||
Javelin::initBehavior('select-on-click'); | Javelin::initBehavior('select-on-click'); | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->appendRemarkupInstructions($pre_instructions) | ->appendRemarkupInstructions($pre_instructions) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextAreaControl()) | id(new AphrontFormTextAreaControl()) | ||||
->setLabel(pht('Token')) | ->setLabel(pht('Token')) | ||||
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) | ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) | ||||
->setReadonly(true) | ->setReadonly(true) | ||||
->setSigil('select-on-click') | ->setSigil('select-on-click') | ||||
->setValue($token->getToken())) | ->setValue($token->getToken())) | ||||
Show All 20 Lines |