[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorAuthSSHKeyEditController 4 extends PhabricatorAuthSSHKeyController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $this->getViewer(); 8 9 $id = $request->getURIData('id'); 10 if ($id) { 11 $key = id(new PhabricatorAuthSSHKeyQuery()) 12 ->setViewer($viewer) 13 ->withIDs(array($id)) 14 ->requireCapabilities( 15 array( 16 PhabricatorPolicyCapability::CAN_VIEW, 17 PhabricatorPolicyCapability::CAN_EDIT, 18 )) 19 ->executeOne(); 20 if (!$key) { 21 return new Aphront404Response(); 22 } 23 24 $is_new = false; 25 } else { 26 $key = $this->newKeyForObjectPHID($request->getStr('objectPHID')); 27 if (!$key) { 28 return new Aphront404Response(); 29 } 30 $is_new = true; 31 } 32 33 $cancel_uri = $key->getObject()->getSSHPublicKeyManagementURI($viewer); 34 35 if ($key->getIsTrusted()) { 36 $id = $key->getID(); 37 38 return $this->newDialog() 39 ->setTitle(pht('Can Not Edit Trusted Key')) 40 ->appendParagraph( 41 pht( 42 'This key is trusted. Trusted keys can not be edited. '. 43 'Use %s to revoke trust before editing the key.', 44 phutil_tag( 45 'tt', 46 array(), 47 "bin/almanac untrust-key --id {$id}"))) 48 ->addCancelButton($cancel_uri, pht('Okay')); 49 } 50 51 $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( 52 $viewer, 53 $request, 54 $cancel_uri); 55 56 $v_name = $key->getName(); 57 $e_name = strlen($v_name) ? null : true; 58 59 $v_key = $key->getEntireKey(); 60 $e_key = strlen($v_key) ? null : true; 61 62 $errors = array(); 63 if ($request->isFormPost()) { 64 $v_name = $request->getStr('name'); 65 $v_key = $request->getStr('key'); 66 67 if (!strlen($v_name)) { 68 $errors[] = pht('You must provide a name for this public key.'); 69 $e_name = pht('Required'); 70 } else { 71 $key->setName($v_name); 72 } 73 74 if (!strlen($v_key)) { 75 $errors[] = pht('You must provide a public key.'); 76 $e_key = pht('Required'); 77 } else { 78 try { 79 $public_key = PhabricatorAuthSSHPublicKey::newFromRawKey($v_key); 80 81 $type = $public_key->getType(); 82 $body = $public_key->getBody(); 83 $comment = $public_key->getComment(); 84 85 $key->setKeyType($type); 86 $key->setKeyBody($body); 87 $key->setKeyComment($comment); 88 89 $e_key = null; 90 } catch (Exception $ex) { 91 $e_key = pht('Invalid'); 92 $errors[] = $ex->getMessage(); 93 } 94 } 95 96 if (!$errors) { 97 try { 98 $key->save(); 99 return id(new AphrontRedirectResponse())->setURI($cancel_uri); 100 } catch (Exception $ex) { 101 $e_key = pht('Duplicate'); 102 $errors[] = pht( 103 'This public key is already associated with another user or '. 104 'device. Each key must unambiguously identify a single unique '. 105 'owner.'); 106 } 107 } 108 } 109 110 $form = id(new AphrontFormView()) 111 ->setUser($viewer) 112 ->appendChild( 113 id(new AphrontFormTextControl()) 114 ->setLabel(pht('Name')) 115 ->setName('name') 116 ->setError($e_name) 117 ->setValue($v_name)) 118 ->appendChild( 119 id(new AphrontFormTextAreaControl()) 120 ->setLabel(pht('Public Key')) 121 ->setName('key') 122 ->setValue($v_key) 123 ->setError($e_key)); 124 125 if ($is_new) { 126 $title = pht('Upload SSH Public Key'); 127 $save_button = pht('Upload Public Key'); 128 $form->addHiddenInput('objectPHID', $key->getObject()->getPHID()); 129 } else { 130 $title = pht('Edit SSH Public Key'); 131 $save_button = pht('Save Changes'); 132 } 133 134 return $this->newDialog() 135 ->setTitle($title) 136 ->setWidth(AphrontDialogView::WIDTH_FORM) 137 ->setErrors($errors) 138 ->appendForm($form) 139 ->addSubmitButton($save_button) 140 ->addCancelButton($cancel_uri); 141 } 142 143 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |