repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/controller/FundInitiativeEditController.php
src/applications/fund/controller/FundInitiativeEditController.php
<?php final class FundInitiativeEditController extends FundController { public function handleRequest(AphrontRequest $request) { return id(new FundInitiativeEditEngine()) ->setController($this) ->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/controller/FundController.php
src/applications/fund/controller/FundController.php
<?php abstract class FundController extends PhabricatorController {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/controller/FundInitiativeViewController.php
src/applications/fund/controller/FundInitiativeViewController.php
<?php final class FundInitiativeViewController extends FundController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $initiative = id(new FundInitiativeQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$initiative) { return new Aphront404Response(); } $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($initiative->getMonogram()); $crumbs->setBorder(true); $title = pht( '%s %s', $initiative->getMonogram(), $initiative->getName()); if ($initiative->isClosed()) { $status_icon = 'fa-ban'; $status_color = 'indigo'; } else { $status_icon = 'fa-check'; $status_color = 'bluegrey'; } $status_name = idx( FundInitiative::getStatusNameMap(), $initiative->getStatus()); $header = id(new PHUIHeaderView()) ->setHeader($initiative->getName()) ->setUser($viewer) ->setPolicyObject($initiative) ->setStatus($status_icon, $status_color, $status_name) ->setHeaderIcon('fa-heart'); $curtain = $this->buildCurtain($initiative); $details = $this->buildPropertySectionView($initiative); $timeline = $this->buildTransactionTimeline( $initiative, new FundInitiativeTransactionQuery()); $timeline->setQuoteRef($initiative->getMonogram()); $comment_view = $this->buildCommentForm($initiative, $timeline); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->setMainColumn(array( $timeline, $comment_view, )) ->addPropertySection(pht('Details'), $details); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->setPageObjectPHIDs(array($initiative->getPHID())) ->appendChild($view); } private function buildPropertySectionView(FundInitiative $initiative) { $viewer = $this->getRequest()->getUser(); $view = id(new PHUIPropertyListView()) ->setUser($viewer); $owner_phid = $initiative->getOwnerPHID(); $merchant_phid = $initiative->getMerchantPHID(); $view->addProperty( pht('Owner'), $viewer->renderHandle($owner_phid)); $view->addProperty( pht('Payable to Merchant'), $viewer->renderHandle($merchant_phid)); $view->addProperty( pht('Total Funding'), $initiative->getTotalAsCurrency()->formatForDisplay()); $description = $initiative->getDescription(); if (strlen($description)) { $description = new PHUIRemarkupView($viewer, $description); $view->addSectionHeader( pht('Description'), PHUIPropertyListView::ICON_SUMMARY); $view->addTextContent($description); } $risks = $initiative->getRisks(); if (strlen($risks)) { $risks = new PHUIRemarkupView($viewer, $risks); $view->addSectionHeader( pht('Risks/Challenges'), 'fa-ambulance'); $view->addTextContent($risks); } return $view; } private function buildCurtain(FundInitiative $initiative) { $viewer = $this->getViewer(); $id = $initiative->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $initiative, PhabricatorPolicyCapability::CAN_EDIT); $curtain = $this->newCurtainView($initiative); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Initiative')) ->setIcon('fa-pencil') ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit) ->setHref($this->getApplicationURI("/edit/{$id}/"))); if ($initiative->isClosed()) { $close_name = pht('Reopen Initiative'); $close_icon = 'fa-check'; } else { $close_name = pht('Close Initiative'); $close_icon = 'fa-times'; } $curtain->addAction( id(new PhabricatorActionView()) ->setName($close_name) ->setIcon($close_icon) ->setDisabled(!$can_edit) ->setWorkflow(true) ->setHref($this->getApplicationURI("/close/{$id}/"))); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Back Initiative')) ->setIcon('fa-money') ->setDisabled($initiative->isClosed()) ->setWorkflow(true) ->setHref($this->getApplicationURI("/back/{$id}/"))); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('View Backers')) ->setIcon('fa-bank') ->setHref($this->getApplicationURI("/backers/{$id}/"))); return $curtain; } private function buildCommentForm(FundInitiative $initiative, $timeline) { $viewer = $this->getViewer(); $box = id(new FundInitiativeEditEngine()) ->setViewer($viewer) ->buildEditEngineCommentView($initiative) ->setTransactionTimeline($timeline); return $box; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/controller/FundInitiativeCloseController.php
src/applications/fund/controller/FundInitiativeCloseController.php
<?php final class FundInitiativeCloseController extends FundController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $initiative = id(new FundInitiativeQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$initiative) { return new Aphront404Response(); } $initiative_uri = '/'.$initiative->getMonogram(); $is_close = !$initiative->isClosed(); if ($request->isFormPost()) { $type_status = FundInitiativeStatusTransaction::TRANSACTIONTYPE; if ($is_close) { $new_status = FundInitiative::STATUS_CLOSED; } else { $new_status = FundInitiative::STATUS_OPEN; } $xaction = id(new FundInitiativeTransaction()) ->setTransactionType($type_status) ->setNewValue($new_status); $editor = id(new FundInitiativeEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnMissingFields(true); $editor->applyTransactions($initiative, array($xaction)); return id(new AphrontRedirectResponse())->setURI($initiative_uri); } if ($is_close) { $title = pht('Close Initiative?'); $body = pht( 'Really close this initiative? Users will no longer be able to '. 'back it.'); $button_text = pht('Close Initiative'); } else { $title = pht('Reopen Initiative?'); $body = pht('Really reopen this initiative?'); $button_text = pht('Reopen Initiative'); } return $this->newDialog() ->setTitle($title) ->appendParagraph($body) ->addCancelButton($initiative_uri) ->addSubmitButton($button_text); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/controller/FundInitiativeBackController.php
src/applications/fund/controller/FundInitiativeBackController.php
<?php final class FundInitiativeBackController extends FundController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $initiative = id(new FundInitiativeQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$initiative) { return new Aphront404Response(); } $merchant = id(new PhortuneMerchantQuery()) ->setViewer($viewer) ->withPHIDs(array($initiative->getMerchantPHID())) ->executeOne(); if (!$merchant) { return new Aphront404Response(); } $initiative_uri = '/'.$initiative->getMonogram(); if ($initiative->isClosed()) { return $this->newDialog() ->setTitle(pht('Initiative Closed')) ->appendParagraph( pht('You can not back a closed initiative.')) ->addCancelButton($initiative_uri); } $accounts = PhortuneAccountQuery::loadAccountsForUser( $viewer, PhabricatorContentSource::newFromRequest($request)); $v_amount = null; $e_amount = true; $v_account = head($accounts)->getPHID(); $errors = array(); if ($request->isFormPost()) { $v_amount = $request->getStr('amount'); $v_account = $request->getStr('accountPHID'); if (empty($accounts[$v_account])) { $errors[] = pht('You must specify an account.'); } else { $account = $accounts[$v_account]; } if (!strlen($v_amount)) { $errors[] = pht( 'You must specify how much money you want to contribute to the '. 'initiative.'); $e_amount = pht('Required'); } else { try { $currency = PhortuneCurrency::newFromUserInput( $viewer, $v_amount); $currency->assertInRange('1.00 USD', null); } catch (Exception $ex) { $errors[] = $ex->getMessage(); $e_amount = pht('Invalid'); } } if (!$errors) { $backer = FundBacker::initializeNewBacker($viewer) ->setInitiativePHID($initiative->getPHID()) ->attachInitiative($initiative) ->setAmountAsCurrency($currency) ->save(); $product = id(new PhortuneProductQuery()) ->setViewer($viewer) ->withClassAndRef('FundBackerProduct', $initiative->getPHID()) ->executeOne(); $cart_implementation = id(new FundBackerCart()) ->setInitiative($initiative); $cart = $account->newCart($viewer, $cart_implementation, $merchant); $purchase = $cart->newPurchase($viewer, $product); $purchase ->setBasePriceAsCurrency($currency) ->setMetadataValue('backerPHID', $backer->getPHID()) ->save(); $xactions = array(); $xactions[] = id(new FundBackerTransaction()) ->setTransactionType(FundBackerStatusTransaction::TRANSACTIONTYPE) ->setNewValue(FundBacker::STATUS_IN_CART); $editor = id(new FundBackerEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request); $editor->applyTransactions($backer, $xactions); $cart->activateCart(); return id(new AphrontRedirectResponse()) ->setURI($cart->getCheckoutURI()); } } $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormSelectControl()) ->setName('accountPHID') ->setLabel(pht('Account')) ->setValue($v_account) ->setOptions(mpull($accounts, 'getName', 'getPHID'))) ->appendChild( id(new AphrontFormTextControl()) ->setName('amount') ->setLabel(pht('Amount')) ->setValue($v_amount) ->setError($e_amount)); return $this->newDialog() ->setTitle( pht('Back %s %s', $initiative->getMonogram(), $initiative->getName())) ->setErrors($errors) ->appendChild($form->buildLayoutView()) ->addCancelButton($initiative_uri) ->addSubmitButton(pht('Continue')); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/controller/FundInitiativeListController.php
src/applications/fund/controller/FundInitiativeListController.php
<?php final class FundInitiativeListController extends FundController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $querykey = $request->getURIData('queryKey'); $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($querykey) ->setSearchEngine(new FundInitiativeSearchEngine()) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } public function buildSideNavView() { $viewer = $this->getViewer(); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); id(new FundInitiativeSearchEngine()) ->setViewer($viewer) ->addNavigationItems($nav->getMenu()); $nav->addLabel(pht('Backers')); $nav->addFilter('backers/', pht('Find Backers')); $nav->selectFilter(null); return $nav; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $can_create = $this->hasApplicationCapability( FundCreateInitiativesCapability::CAPABILITY); $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Initiative')) ->setHref($this->getApplicationURI('create/')) ->setIcon('fa-plus-square') ->setDisabled(!$can_create) ->setWorkflow(!$can_create)); return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/controller/FundBackerListController.php
src/applications/fund/controller/FundBackerListController.php
<?php final class FundBackerListController extends FundController { private $initiative; public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $querykey = $request->getURIData('queryKey'); if ($id) { $this->initiative = id(new FundInitiativeQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$this->initiative) { return new Aphront404Response(); } } $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($querykey) ->setSearchEngine($this->getEngine()) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } public function buildSideNavView() { $user = $this->getRequest()->getUser(); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $this->getEngine()->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); return $nav; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $crumbs->addTextCrumb( pht('Backers'), $this->getApplicationURI('backers/')); if ($this->initiative) { $crumbs->addTextCrumb( $this->initiative->getMonogram(), '/'.$this->initiative->getMonogram()); } return $crumbs; } private function getEngine() { $viewer = $this->getViewer(); $engine = id(new FundBackerSearchEngine()) ->setViewer($viewer); if ($this->initiative) { $engine->setInitiative($this->initiative); } return $engine; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/storage/FundBacker.php
src/applications/fund/storage/FundBacker.php
<?php final class FundBacker extends FundDAO implements PhabricatorPolicyInterface, PhabricatorApplicationTransactionInterface { protected $initiativePHID; protected $backerPHID; protected $amountAsCurrency; protected $status; protected $properties = array(); private $initiative = self::ATTACHABLE; const STATUS_NEW = 'new'; const STATUS_IN_CART = 'in-cart'; const STATUS_PURCHASED = 'purchased'; public static function initializeNewBacker(PhabricatorUser $actor) { return id(new FundBacker()) ->setBackerPHID($actor->getPHID()) ->setStatus(self::STATUS_NEW); } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'properties' => self::SERIALIZATION_JSON, ), self::CONFIG_APPLICATION_SERIALIZERS => array( 'amountAsCurrency' => new PhortuneCurrencySerializer(), ), self::CONFIG_COLUMN_SCHEMA => array( 'status' => 'text32', 'amountAsCurrency' => 'text64', ), self::CONFIG_KEY_SCHEMA => array( 'key_initiative' => array( 'columns' => array('initiativePHID'), ), 'key_backer' => array( 'columns' => array('backerPHID'), ), ), ) + parent::getConfiguration(); } public function generatePHID() { return PhabricatorPHID::generateNewPHID(FundBackerPHIDType::TYPECONST); } public function getProperty($key, $default = null) { return idx($this->properties, $key, $default); } public function setProperty($key, $value) { $this->properties[$key] = $value; return $this; } public function getInitiative() { return $this->assertAttached($this->initiative); } public function attachInitiative(FundInitiative $initiative = null) { $this->initiative = $initiative; return $this; } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: // If we have the initiative, use the initiative's policy. // Otherwise, return NOONE. This allows the backer to continue seeing // a backer even if they're no longer allowed to see the initiative. $initiative = $this->getInitiative(); if ($initiative) { return $initiative->getPolicy($capability); } return PhabricatorPolicies::POLICY_NOONE; case PhabricatorPolicyCapability::CAN_EDIT: return PhabricatorPolicies::POLICY_NOONE; } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return ($viewer->getPHID() == $this->getBackerPHID()); } public function describeAutomaticCapability($capability) { return pht('A backer can always see what they have backed.'); } /* -( PhabricatorApplicationTransactionInterface )------------------------- */ public function getApplicationTransactionEditor() { return new FundBackerEditor(); } public function getApplicationTransactionTemplate() { return new FundBackerTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/storage/FundBackerTransaction.php
src/applications/fund/storage/FundBackerTransaction.php
<?php final class FundBackerTransaction extends PhabricatorModularTransaction { public function getApplicationName() { return 'fund'; } public function getApplicationTransactionType() { return FundBackerPHIDType::TYPECONST; } public function getBaseTransactionClass() { return 'FundBackerTransactionType'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/storage/FundInitiative.php
src/applications/fund/storage/FundInitiative.php
<?php final class FundInitiative extends FundDAO implements PhabricatorPolicyInterface, PhabricatorProjectInterface, PhabricatorApplicationTransactionInterface, PhabricatorSubscribableInterface, PhabricatorMentionableInterface, PhabricatorFlaggableInterface, PhabricatorTokenReceiverInterface, PhabricatorDestructibleInterface, PhabricatorFulltextInterface, PhabricatorFerretInterface { protected $name; protected $ownerPHID; protected $merchantPHID; protected $description; protected $risks; protected $viewPolicy; protected $editPolicy; protected $status; protected $totalAsCurrency; private $projectPHIDs = self::ATTACHABLE; const STATUS_OPEN = 'open'; const STATUS_CLOSED = 'closed'; public static function getStatusNameMap() { return array( self::STATUS_OPEN => pht('Open'), self::STATUS_CLOSED => pht('Closed'), ); } public static function initializeNewInitiative(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery()) ->setViewer($actor) ->withClasses(array('PhabricatorFundApplication')) ->executeOne(); $view_policy = $app->getPolicy(FundDefaultViewCapability::CAPABILITY); return id(new FundInitiative()) ->setOwnerPHID($actor->getPHID()) ->setViewPolicy($view_policy) ->setEditPolicy($actor->getPHID()) ->setStatus(self::STATUS_OPEN) ->setTotalAsCurrency(PhortuneCurrency::newEmptyCurrency()); } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_COLUMN_SCHEMA => array( 'name' => 'text255', 'description' => 'text', 'risks' => 'text', 'status' => 'text32', 'merchantPHID' => 'phid?', 'totalAsCurrency' => 'text64', ), self::CONFIG_APPLICATION_SERIALIZERS => array( 'totalAsCurrency' => new PhortuneCurrencySerializer(), ), self::CONFIG_KEY_SCHEMA => array( 'key_status' => array( 'columns' => array('status'), ), 'key_owner' => array( 'columns' => array('ownerPHID'), ), ), ) + parent::getConfiguration(); } public function getPHIDType() { return FundInitiativePHIDType::TYPECONST; } public function getMonogram() { return 'I'.$this->getID(); } public function getViewURI() { return '/'.$this->getMonogram(); } public function getProjectPHIDs() { return $this->assertAttached($this->projectPHIDs); } public function attachProjectPHIDs(array $phids) { $this->projectPHIDs = $phids; return $this; } public function isClosed() { return ($this->getStatus() == self::STATUS_CLOSED); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: return $this->getViewPolicy(); case PhabricatorPolicyCapability::CAN_EDIT: return $this->getEditPolicy(); } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { if ($viewer->getPHID() == $this->getOwnerPHID()) { return true; } if ($capability == PhabricatorPolicyCapability::CAN_VIEW) { $can_merchant = PhortuneMerchantQuery::canViewersEditMerchants( array($viewer->getPHID()), array($this->getMerchantPHID())); if ($can_merchant) { return true; } } return false; } public function describeAutomaticCapability($capability) { return pht('The owner of an initiative can always view and edit it.'); } /* -( PhabricatorApplicationTransactionInterface )------------------------- */ public function getApplicationTransactionEditor() { return new FundInitiativeEditor(); } public function getApplicationTransactionTemplate() { return new FundInitiativeTransaction(); } /* -( PhabricatorSubscribableInterface )----------------------------------- */ public function isAutomaticallySubscribed($phid) { return ($phid == $this->getOwnerPHID()); } /* -( PhabricatorTokenRecevierInterface )---------------------------------- */ public function getUsersToNotifyOfTokenGiven() { return array( $this->getOwnerPHID(), ); } /* -( PhabricatorDestructibleInterface )----------------------------------- */ public function destroyObjectPermanently( PhabricatorDestructionEngine $engine) { $this->openTransaction(); $this->delete(); $this->saveTransaction(); } /* -( PhabricatorFulltextInterface )--------------------------------------- */ public function newFulltextEngine() { return new FundInitiativeFulltextEngine(); } /* -( PhabricatorFerretInterface )----------------------------------------- */ public function newFerretEngine() { return new FundInitiativeFerretEngine(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/storage/FundInitiativeTransactionComment.php
src/applications/fund/storage/FundInitiativeTransactionComment.php
<?php final class FundInitiativeTransactionComment extends PhabricatorApplicationTransactionComment { public function getApplicationTransactionObject() { return new FundInitiativeTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/storage/FundSchemaSpec.php
src/applications/fund/storage/FundSchemaSpec.php
<?php final class FundSchemaSpec extends PhabricatorConfigSchemaSpec { public function buildSchemata() { $this->buildEdgeSchemata(new FundInitiative()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/storage/FundInitiativeTransaction.php
src/applications/fund/storage/FundInitiativeTransaction.php
<?php final class FundInitiativeTransaction extends PhabricatorModularTransaction { const MAILTAG_BACKER = 'fund.backer'; const MAILTAG_STATUS = 'fund.status'; const MAILTAG_OTHER = 'fund.other'; const PROPERTY_AMOUNT = 'fund.amount'; const PROPERTY_BACKER = 'fund.backer'; public function getApplicationName() { return 'fund'; } public function getApplicationTransactionType() { return FundInitiativePHIDType::TYPECONST; } public function getApplicationTransactionCommentObject() { return new FundInitiativeTransactionComment(); } public function getBaseTransactionClass() { return 'FundInitiativeTransactionType'; } protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { return true; } public function getMailTags() { $tags = parent::getMailTags(); switch ($this->getTransactionType()) { case FundInitiativeStatusTransaction::TRANSACTIONTYPE: $tags[] = self::MAILTAG_STATUS; break; case FundInitiativeBackerTransaction::TRANSACTIONTYPE: case FundInitiativeRefundTransaction::TRANSACTIONTYPE: $tags[] = self::MAILTAG_BACKER; break; default: $tags[] = self::MAILTAG_OTHER; break; } return $tags; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/storage/FundDAO.php
src/applications/fund/storage/FundDAO.php
<?php abstract class FundDAO extends PhabricatorLiskDAO { public function getApplicationName() { return 'fund'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/query/FundBackerQuery.php
src/applications/fund/query/FundBackerQuery.php
<?php final class FundBackerQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $ids; private $phids; private $statuses; private $initiativePHIDs; private $backerPHIDs; public function withIDs(array $ids) { $this->ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withStatuses(array $statuses) { $this->statuses = $statuses; return $this; } public function withInitiativePHIDs(array $phids) { $this->initiativePHIDs = $phids; return $this; } public function withBackerPHIDs(array $phids) { $this->backerPHIDs = $phids; return $this; } protected function loadPage() { $table = new FundBacker(); $conn_r = $table->establishConnection('r'); $rows = queryfx_all( $conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); return $table->loadAllFromArray($rows); } protected function willFilterPage(array $backers) { $initiative_phids = mpull($backers, 'getInitiativePHID'); $initiatives = id(new PhabricatorObjectQuery()) ->setParentQuery($this) ->setViewer($this->getViewer()) ->withPHIDs($initiative_phids) ->execute(); $initiatives = mpull($initiatives, null, 'getPHID'); foreach ($backers as $backer) { $initiative_phid = $backer->getInitiativePHID(); $initiative = idx($initiatives, $initiative_phid); $backer->attachInitiative($initiative); } return $backers; } protected function buildWhereClause(AphrontDatabaseConnection $conn) { $where = array(); $where[] = $this->buildPagingClause($conn); if ($this->ids !== null) { $where[] = qsprintf( $conn, 'id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, 'phid IN (%Ls)', $this->phids); } if ($this->initiativePHIDs !== null) { $where[] = qsprintf( $conn, 'initiativePHID IN (%Ls)', $this->initiativePHIDs); } if ($this->backerPHIDs !== null) { $where[] = qsprintf( $conn, 'backerPHID IN (%Ls)', $this->backerPHIDs); } if ($this->statuses !== null) { $where[] = qsprintf( $conn, 'status IN (%Ls)', $this->statuses); } return $this->formatWhereClause($conn, $where); } public function getQueryApplicationClass() { return 'PhabricatorFundApplication'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/query/FundInitiativeSearchEngine.php
src/applications/fund/query/FundInitiativeSearchEngine.php
<?php final class FundInitiativeSearchEngine extends PhabricatorApplicationSearchEngine { public function getResultTypeDescription() { return pht('Fund Initiatives'); } public function getApplicationClassName() { return 'PhabricatorFundApplication'; } public function newQuery() { return new FundInitiativeQuery(); } protected function buildCustomSearchFields() { return array( id(new PhabricatorUsersSearchField()) ->setKey('ownerPHIDs') ->setAliases(array('owner', 'ownerPHID', 'owners')) ->setLabel(pht('Owners')), id(new PhabricatorSearchCheckboxesField()) ->setKey('statuses') ->setLabel(pht('Statuses')) ->setOptions(FundInitiative::getStatusNameMap()), ); } protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['ownerPHIDs']) { $query->withOwnerPHIDs($map['ownerPHIDs']); } if ($map['statuses']) { $query->withStatuses($map['statuses']); } return $query; } protected function getURI($path) { return '/fund/'.$path; } protected function getBuiltinQueryNames() { $names = array(); $names['open'] = pht('Open Initiatives'); if ($this->requireViewer()->isLoggedIn()) { $names['owned'] = pht('Owned Initiatives'); } $names['all'] = pht('All Initiatives'); return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'all': return $query; case 'owned': return $query->setParameter( 'ownerPHIDs', array( $this->requireViewer()->getPHID(), )); case 'open': return $query->setParameter( 'statuses', array( FundInitiative::STATUS_OPEN, )); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function renderResultList( array $initiatives, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($initiatives, 'FundInitiative'); $viewer = $this->requireViewer(); $load_phids = array(); foreach ($initiatives as $initiative) { $load_phids[] = $initiative->getOwnerPHID(); } if ($initiatives) { $edge_query = id(new PhabricatorEdgeQuery()) ->withSourcePHIDs(mpull($initiatives, 'getPHID')) ->withEdgeTypes( array( PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, )); $edge_query->execute(); foreach ($edge_query->getDestinationPHIDs() as $phid) { $load_phids[] = $phid; } } $handles = $viewer->loadHandles($load_phids); $handles = iterator_to_array($handles); $list = new PHUIObjectItemListView(); foreach ($initiatives as $initiative) { $owner_handle = $handles[$initiative->getOwnerPHID()]; $item = id(new PHUIObjectItemView()) ->setObjectName($initiative->getMonogram()) ->setHeader($initiative->getName()) ->setHref('/'.$initiative->getMonogram()) ->addByline(pht('Owner: %s', $owner_handle->renderLink())); if ($initiative->isClosed()) { $item->setDisabled(true); } $project_phids = $edge_query->getDestinationPHIDs( array( $initiative->getPHID(), )); $project_handles = array_select_keys($handles, $project_phids); if ($project_handles) { $item->addAttribute( id(new PHUIHandleTagListView()) ->setLimit(4) ->setSlim(true) ->setHandles($project_handles)); } $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No initiatives found.')); return $result; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/query/FundBackerSearchEngine.php
src/applications/fund/query/FundBackerSearchEngine.php
<?php final class FundBackerSearchEngine extends PhabricatorApplicationSearchEngine { private $initiative; public function setInitiative(FundInitiative $initiative) { $this->initiative = $initiative; return $this; } public function getInitiative() { return $this->initiative; } public function getResultTypeDescription() { return pht('Fund Backers'); } public function getApplicationClassName() { return 'PhabricatorFundApplication'; } public function buildSavedQueryFromRequest(AphrontRequest $request) { $saved = new PhabricatorSavedQuery(); $saved->setParameter( 'backerPHIDs', $this->readUsersFromRequest($request, 'backers')); return $saved; } public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { $query = id(new FundBackerQuery()); $query->withStatuses(array(FundBacker::STATUS_PURCHASED)); if ($this->getInitiative()) { $query->withInitiativePHIDs( array( $this->getInitiative()->getPHID(), )); } $backer_phids = $saved->getParameter('backerPHIDs'); if ($backer_phids) { $query->withBackerPHIDs($backer_phids); } return $query; } public function buildSearchForm( AphrontFormView $form, PhabricatorSavedQuery $saved) { $backer_phids = $saved->getParameter('backerPHIDs', array()); $form ->appendControl( id(new AphrontFormTokenizerControl()) ->setLabel(pht('Backers')) ->setName('backers') ->setDatasource(new PhabricatorPeopleDatasource()) ->setValue($backer_phids)); } protected function getURI($path) { if ($this->getInitiative()) { return '/fund/backers/'.$this->getInitiative()->getID().'/'.$path; } else { return '/fund/backers/'.$path; } } protected function getBuiltinQueryNames() { $names = array(); $names['all'] = pht('All Backers'); return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'all': return $query; } return parent::buildSavedQueryFromBuiltin($query_key); } protected function getRequiredHandlePHIDsForResultList( array $backers, PhabricatorSavedQuery $query) { $phids = array(); foreach ($backers as $backer) { $phids[] = $backer->getBackerPHID(); $phids[] = $backer->getInitiativePHID(); } return $phids; } protected function renderResultList( array $backers, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($backers, 'FundBacker'); $viewer = $this->requireViewer(); $rows = array(); foreach ($backers as $backer) { $rows[] = array( $handles[$backer->getInitiativePHID()]->renderLink(), $handles[$backer->getBackerPHID()]->renderLink(), $backer->getAmountAsCurrency()->formatForDisplay(), phabricator_datetime($backer->getDateCreated(), $viewer), ); } $table = id(new AphrontTableView($rows)) ->setNoDataString(pht('No backers found.')) ->setHeaders( array( pht('Initiative'), pht('Backer'), pht('Amount'), pht('Date'), )) ->setColumnClasses( array( null, null, 'wide right', 'right', )); $result = new PhabricatorApplicationSearchResultView(); $result->setTable($table); return $result; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/query/FundBackerTransactionQuery.php
src/applications/fund/query/FundBackerTransactionQuery.php
<?php final class FundBackerTransactionQuery extends PhabricatorApplicationTransactionQuery { public function getTemplateApplicationTransaction() { return new FundBackerTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/query/FundInitiativeTransactionQuery.php
src/applications/fund/query/FundInitiativeTransactionQuery.php
<?php final class FundInitiativeTransactionQuery extends PhabricatorApplicationTransactionQuery { public function getTemplateApplicationTransaction() { return new FundInitiativeTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/query/FundInitiativeQuery.php
src/applications/fund/query/FundInitiativeQuery.php
<?php final class FundInitiativeQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $ids; private $phids; private $ownerPHIDs; private $statuses; public function withIDs(array $ids) { $this->ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withOwnerPHIDs(array $phids) { $this->ownerPHIDs = $phids; return $this; } public function withStatuses(array $statuses) { $this->statuses = $statuses; return $this; } public function newResultObject() { return new FundInitiative(); } protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf( $conn, 'i.id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, 'i.phid IN (%Ls)', $this->phids); } if ($this->ownerPHIDs !== null) { $where[] = qsprintf( $conn, 'i.ownerPHID IN (%Ls)', $this->ownerPHIDs); } if ($this->statuses !== null) { $where[] = qsprintf( $conn, 'i.status IN (%Ls)', $this->statuses); } return $where; } public function getQueryApplicationClass() { return 'PhabricatorFundApplication'; } protected function getPrimaryTableAlias() { return 'i'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/mail/FundInitiativeReplyHandler.php
src/applications/fund/mail/FundInitiativeReplyHandler.php
<?php final class FundInitiativeReplyHandler extends PhabricatorApplicationTransactionReplyHandler { public function validateMailReceiver($mail_receiver) { if (!($mail_receiver instanceof FundInitiative)) { throw new Exception(pht('Mail receiver is not a %s!', 'FundInitiative')); } } public function getObjectPrefix() { return 'I'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/editor/FundBackerEditor.php
src/applications/fund/editor/FundBackerEditor.php
<?php final class FundBackerEditor extends PhabricatorApplicationTransactionEditor { public function getEditorApplicationClass() { return 'PhabricatorFundApplication'; } public function getEditorObjectsDescription() { return pht('Fund Backing'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/editor/FundInitiativeEditEngine.php
src/applications/fund/editor/FundInitiativeEditEngine.php
<?php final class FundInitiativeEditEngine extends PhabricatorEditEngine { const ENGINECONST = 'fund.initiative'; public function getEngineName() { return pht('Fund'); } public function getEngineApplicationClass() { return 'PhabricatorFundApplication'; } public function getSummaryHeader() { return pht('Configure Fund Forms'); } public function getSummaryText() { return pht('Configure creation and editing forms in Fund.'); } public function isEngineConfigurable() { return false; } protected function newEditableObject() { return FundInitiative::initializeNewInitiative($this->getViewer()); } protected function newObjectQuery() { return new FundInitiativeQuery(); } protected function getObjectCreateTitleText($object) { return pht('Create New Initiative'); } protected function getObjectEditTitleText($object) { return pht('Edit Initiative: %s', $object->getName()); } protected function getObjectEditShortText($object) { return $object->getName(); } protected function getObjectCreateShortText() { return pht('Create Initiative'); } protected function getObjectName() { return pht('Initiative'); } protected function getObjectCreateCancelURI($object) { return $this->getApplication()->getApplicationURI('/'); } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('edit/'); } protected function getObjectViewURI($object) { return $object->getViewURI(); } protected function getCreateNewObjectPolicy() { return $this->getApplication()->getPolicy( FundCreateInitiativesCapability::CAPABILITY); } protected function buildCustomEditFields($object) { $viewer = $this->getViewer(); $v_merchant = $object->getMerchantPHID(); $merchants = id(new PhortuneMerchantQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->execute(); $merchant_options = array(); foreach ($merchants as $merchant) { $merchant_options[$merchant->getPHID()] = pht( 'Merchant %d %s', $merchant->getID(), $merchant->getName()); } if ($v_merchant && empty($merchant_options[$v_merchant])) { $merchant_options = array( $v_merchant => pht('(Restricted Merchant)'), ) + $merchant_options; } $merchant_instructions = null; if (!$merchant_options) { $merchant_instructions = pht( 'NOTE: You do not control any merchant accounts which can receive '. 'payments from this initiative. When you create an initiative, '. 'you need to specify a merchant account where funds will be paid '. 'to. Create a merchant account in the Phortune application before '. 'creating an initiative in Fund.'); } return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setDescription(pht('Initiative name.')) ->setConduitTypeDescription(pht('New initiative name.')) ->setTransactionType( FundInitiativeNameTransaction::TRANSACTIONTYPE) ->setValue($object->getName()) ->setIsRequired(true), id(new PhabricatorSelectEditField()) ->setKey('merchantPHID') ->setLabel(pht('Merchant')) ->setDescription(pht('Merchant operating the initiative.')) ->setConduitTypeDescription(pht('New initiative merchant.')) ->setControlInstructions($merchant_instructions) ->setValue($object->getMerchantPHID()) ->setTransactionType( FundInitiativeMerchantTransaction::TRANSACTIONTYPE) ->setOptions($merchant_options) ->setIsRequired(true), id(new PhabricatorRemarkupEditField()) ->setKey('description') ->setLabel(pht('Description')) ->setDescription(pht('Initiative long description.')) ->setConduitTypeDescription(pht('New initiative description.')) ->setTransactionType( FundInitiativeDescriptionTransaction::TRANSACTIONTYPE) ->setValue($object->getDescription()), id(new PhabricatorRemarkupEditField()) ->setKey('risks') ->setLabel(pht('Risks/Challenges')) ->setDescription(pht('Initiative risks and challenges.')) ->setConduitTypeDescription(pht('Initiative risks and challenges.')) ->setTransactionType( FundInitiativeRisksTransaction::TRANSACTIONTYPE) ->setValue($object->getRisks()), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/editor/FundInitiativeEditor.php
src/applications/fund/editor/FundInitiativeEditor.php
<?php final class FundInitiativeEditor extends PhabricatorApplicationTransactionEditor { public function getEditorApplicationClass() { return 'PhabricatorFundApplication'; } public function getEditorObjectsDescription() { return pht('Fund Initiatives'); } public function getCreateObjectTitle($author, $object) { return pht('%s created this initiative.', $author); } public function getCreateObjectTitleForFeed($author, $object) { return pht('%s created %s.', $author, $object); } public function getTransactionTypes() { $types = parent::getTransactionTypes(); $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; $types[] = PhabricatorTransactions::TYPE_COMMENT; return $types; } protected function shouldSendMail( PhabricatorLiskDAO $object, array $xactions) { return true; } public function getMailTagsMap() { return array( FundInitiativeTransaction::MAILTAG_BACKER => pht('Someone backs an initiative.'), FundInitiativeTransaction::MAILTAG_STATUS => pht("An initiative's status changes."), FundInitiativeTransaction::MAILTAG_OTHER => pht('Other initiative activity not listed above occurs.'), ); } protected function buildMailTemplate(PhabricatorLiskDAO $object) { $monogram = $object->getMonogram(); $name = $object->getName(); return id(new PhabricatorMetaMTAMail()) ->setSubject("{$monogram}: {$name}"); } protected function buildMailBody( PhabricatorLiskDAO $object, array $xactions) { $body = parent::buildMailBody($object, $xactions); $body->addLinkSection( pht('INITIATIVE DETAIL'), PhabricatorEnv::getProductionURI('/'.$object->getMonogram())); return $body; } protected function getMailTo(PhabricatorLiskDAO $object) { return array($object->getOwnerPHID()); } protected function getMailSubjectPrefix() { return 'Fund'; } protected function buildReplyHandler(PhabricatorLiskDAO $object) { return id(new FundInitiativeReplyHandler()) ->setMailReceiver($object); } protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { return true; } protected function supportsSearch() { return true; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundInitiativeRefundTransaction.php
src/applications/fund/xaction/FundInitiativeRefundTransaction.php
<?php final class FundInitiativeRefundTransaction extends FundInitiativeTransactionType { const TRANSACTIONTYPE = 'fund:refund'; public function generateOldValue($object) { return null; } public function applyInternalEffects($object, $value) { $amount = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT); $amount = PhortuneCurrency::newFromString($amount); $total = $object->getTotalAsCurrency()->subtract($amount); $object->setTotalAsCurrency($total); } public function applyExternalEffects($object, $value) { $backer = id(new FundBackerQuery()) ->setViewer($this->getActor()) ->withPHIDs(array($value)) ->executeOne(); if (!$backer) { throw new Exception(pht('Unable to load %s!', 'FundBacker')); } $subx = array(); $amount = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT); $subx[] = id(new FundBackerTransaction()) ->setTransactionType(FundBackerStatusTransaction::TRANSACTIONTYPE) ->setNewValue($amount); $content_source = $this->getEditor()->getContentSource(); $editor = id(new FundBackerEditor()) ->setActor($this->getActor()) ->setContentSource($content_source) ->setContinueOnMissingFields(true) ->setContinueOnNoEffect(true); $editor->applyTransactions($backer, $subx); } public function getTitle() { $amount = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT); $amount = PhortuneCurrency::newFromString($amount); $backer_phid = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_BACKER); return pht( '%s refunded %s to %s.', $this->renderAuthor(), $amount->formatForDisplay(), $this->renderHandle($backer_phid)); } public function getTitleForFeed() { $amount = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT); $amount = PhortuneCurrency::newFromString($amount); $backer_phid = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_BACKER); return pht( '%s refunded %s to %s for %s.', $this->renderAuthor(), $amount->formatForDisplay(), $this->renderHandle($backer_phid), $this->renderObject()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundInitiativeMerchantTransaction.php
src/applications/fund/xaction/FundInitiativeMerchantTransaction.php
<?php final class FundInitiativeMerchantTransaction extends FundInitiativeTransactionType { const TRANSACTIONTYPE = 'fund:merchant'; public function generateOldValue($object) { return $object->getMerchantPHID(); } public function applyInternalEffects($object, $value) { $object->setMerchantPHID($value); } public function getTitle() { $new = $this->getNewValue(); $new_merchant = $this->renderHandleList(array($new)); $old = $this->getOldValue(); $old_merchant = $this->renderHandleList(array($old)); if ($old) { return pht( '%s changed the merchant receiving funds from this '. 'initiative from %s to %s.', $this->renderAuthor(), $old_merchant, $new_merchant); } else { return pht( '%s set the merchant receiving funds from this '. 'initiative to %s.', $this->renderAuthor(), $new_merchant); } } public function getTitleForFeed() { $new = $this->getNewValue(); $new_merchant = $this->renderHandleList(array($new)); $old = $this->getOldValue(); $old_merchant = $this->renderHandleList(array($old)); return pht( '%s changed the merchant receiving funds from %s '. 'from %s to %s.', $this->renderAuthor(), $this->renderObject(), $old_merchant, $new_merchant); } public function validateTransactions($object, array $xactions) { $errors = array(); if ($this->isEmptyTextTransaction($object->getMerchantPHID(), $xactions)) { $errors[] = $this->newRequiredError( pht('Initiatives must have a payable merchant.')); } foreach ($xactions as $xaction) { $merchant_phid = $xaction->getNewValue(); // Make sure the actor has permission to edit the merchant they're // selecting. You aren't allowed to send payments to an account you // do not control. $merchants = id(new PhortuneMerchantQuery()) ->setViewer($this->getActor()) ->withPHIDs(array($merchant_phid)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->execute(); if (!$merchants) { $errors[] = $this->newInvalidError( pht('You must specify a merchant account you control as the '. 'recipient of funds from this initiative.')); } } return $errors; } public function getIcon() { return 'fa-bank'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundBackerStatusTransaction.php
src/applications/fund/xaction/FundBackerStatusTransaction.php
<?php final class FundBackerStatusTransaction extends FundBackerTransactionType { const TRANSACTIONTYPE = 'fund:backer:status'; public function generateOldValue($object) { return $object->getStatus(); } public function applyInternalEffects($object, $value) { $object->setStatus($value); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundInitiativeRisksTransaction.php
src/applications/fund/xaction/FundInitiativeRisksTransaction.php
<?php final class FundInitiativeRisksTransaction extends FundInitiativeTransactionType { const TRANSACTIONTYPE = 'fund:risks'; public function generateOldValue($object) { return $object->getRisks(); } public function applyInternalEffects($object, $value) { $object->setRisks($value); } public function shouldHide() { $old = $this->getOldValue(); $new = $this->getNewValue(); if (!strlen($old) && !strlen($new)) { return true; } return false; } public function getTitle() { $old = $this->getOldValue(); $new = $this->getNewValue(); if ($old === null) { return pht( '%s set the initiative risks/challenges.', $this->renderAuthor()); } else { return pht( '%s updated the initiative risks/challenges.', $this->renderAuthor()); } } public function getTitleForFeed() { return pht( '%s updated the initiative risks/challenges for %s.', $this->renderAuthor(), $this->renderObject()); } public function hasChangeDetailView() { return true; } public function getMailDiffSectionHeader() { return pht('CHANGES TO INITIATIVE RISKS/CHALLENGES'); } public function newChangeDetailView() { $viewer = $this->getViewer(); return id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setViewer($viewer) ->setOldText($this->getOldValue()) ->setNewText($this->getNewValue()); } public function newRemarkupChanges() { $changes = array(); $changes[] = $this->newRemarkupChange() ->setOldValue($this->getOldValue()) ->setNewValue($this->getNewValue()); return $changes; } public function getIcon() { return 'fa-ambulance'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundInitiativeStatusTransaction.php
src/applications/fund/xaction/FundInitiativeStatusTransaction.php
<?php final class FundInitiativeStatusTransaction extends FundInitiativeTransactionType { const TRANSACTIONTYPE = 'fund:status'; public function generateOldValue($object) { return $object->getStatus(); } public function applyInternalEffects($object, $value) { $object->setStatus($value); } public function getTitle() { if ($this->getNewValue() == FundInitiative::STATUS_CLOSED) { return pht( '%s closed this initiative.', $this->renderAuthor()); } else { return pht( '%s reopened this initiative.', $this->renderAuthor()); } } public function getTitleForFeed() { if ($this->getNewValue() == FundInitiative::STATUS_CLOSED) { return pht( '%s closed %s.', $this->renderAuthor(), $this->renderObject()); } else { return pht( '%s reopened %s.', $this->renderAuthor(), $this->renderObject()); } } public function getIcon() { if ($this->getNewValue() == FundInitiative::STATUS_CLOSED) { return 'fa-ban'; } else { return 'fa-check'; } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundInitiativeDescriptionTransaction.php
src/applications/fund/xaction/FundInitiativeDescriptionTransaction.php
<?php final class FundInitiativeDescriptionTransaction extends FundInitiativeTransactionType { const TRANSACTIONTYPE = 'fund:description'; public function generateOldValue($object) { return $object->getDescription(); } public function applyInternalEffects($object, $value) { $object->setDescription($value); } public function shouldHide() { $old = $this->getOldValue(); $new = $this->getNewValue(); if (!strlen($old) && !strlen($new)) { return true; } return false; } public function getTitle() { $old = $this->getOldValue(); $new = $this->getNewValue(); if ($old === null) { return pht( '%s set the initiative description.', $this->renderAuthor()); } else { return pht( '%s updated the initiative description.', $this->renderAuthor()); } } public function getTitleForFeed() { return pht( '%s updated the initiative description for %s.', $this->renderAuthor(), $this->renderObject()); } public function hasChangeDetailView() { return true; } public function getMailDiffSectionHeader() { return pht('CHANGES TO INITIATIVE DESCRIPTION'); } public function newChangeDetailView() { $viewer = $this->getViewer(); return id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setViewer($viewer) ->setOldText($this->getOldValue()) ->setNewText($this->getNewValue()); } public function newRemarkupChanges() { $changes = array(); $changes[] = $this->newRemarkupChange() ->setOldValue($this->getOldValue()) ->setNewValue($this->getNewValue()); return $changes; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundBackerTransactionType.php
src/applications/fund/xaction/FundBackerTransactionType.php
<?php abstract class FundBackerTransactionType extends PhabricatorModularTransactionType {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundInitiativeNameTransaction.php
src/applications/fund/xaction/FundInitiativeNameTransaction.php
<?php final class FundInitiativeNameTransaction extends FundInitiativeTransactionType { const TRANSACTIONTYPE = 'fund:name'; public function generateOldValue($object) { return $object->getName(); } public function applyInternalEffects($object, $value) { $object->setName($value); } public function getTitle() { $old = $this->getOldValue(); if (!strlen($old)) { return pht( '%s created this initiative.', $this->renderAuthor()); } else { return pht( '%s renamed this initiative from %s to %s.', $this->renderAuthor(), $this->renderOldValue(), $this->renderNewValue()); } } public function getTitleForFeed() { $old = $this->getOldValue(); if (!strlen($old)) { return pht( '%s created initiative %s.', $this->renderAuthor(), $this->renderObject()); } else { return pht( '%s renamed %s from %s to %s.', $this->renderAuthor(), $this->renderObject(), $this->renderOldValue(), $this->renderNewValue()); } } public function validateTransactions($object, array $xactions) { $errors = array(); if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { $errors[] = $this->newRequiredError( pht('Initiatives must have a name.')); } $max_length = $object->getColumnMaximumByteLength('name'); foreach ($xactions as $xaction) { $new_value = $xaction->getNewValue(); $new_length = strlen($new_value); if ($new_length > $max_length) { $errors[] = $this->newInvalidError( pht('The name can be no longer than %s characters.', new PhutilNumber($max_length))); } } return $errors; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundBackerRefundTransaction.php
src/applications/fund/xaction/FundBackerRefundTransaction.php
<?php final class FundBackerRefundTransaction extends FundBackerTransactionType { const TRANSACTIONTYPE = 'fund:backer:refund'; public function generateOldValue($object) { return null; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundInitiativeTransactionType.php
src/applications/fund/xaction/FundInitiativeTransactionType.php
<?php abstract class FundInitiativeTransactionType extends PhabricatorModularTransactionType {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/xaction/FundInitiativeBackerTransaction.php
src/applications/fund/xaction/FundInitiativeBackerTransaction.php
<?php final class FundInitiativeBackerTransaction extends FundInitiativeTransactionType { const TRANSACTIONTYPE = 'fund:backer'; public function generateOldValue($object) { return null; } public function applyInternalEffects($object, $value) { $amount = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT); $amount = PhortuneCurrency::newFromString($amount); $total = $object->getTotalAsCurrency()->add($amount); $object->setTotalAsCurrency($total); } public function applyExternalEffects($object, $value) { $backer = id(new FundBackerQuery()) ->setViewer($this->getActor()) ->withPHIDs(array($value)) ->executeOne(); if (!$backer) { throw new Exception(pht('Unable to load %s!', 'FundBacker')); } $subx = array(); $subx[] = id(new FundBackerTransaction()) ->setTransactionType(FundBackerStatusTransaction::TRANSACTIONTYPE) ->setNewValue(FundBacker::STATUS_PURCHASED); $content_source = $this->getEditor()->getContentSource(); $editor = id(new FundBackerEditor()) ->setActor($this->getActor()) ->setContentSource($content_source) ->setContinueOnMissingFields(true) ->setContinueOnNoEffect(true); $editor->applyTransactions($backer, $subx); } public function getTitle() { $amount = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT); $amount = PhortuneCurrency::newFromString($amount); return pht( '%s backed this initiative with %s.', $this->renderAuthor(), $amount->formatForDisplay()); } public function getTitleForFeed() { $amount = $this->getMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT); $amount = PhortuneCurrency::newFromString($amount); return pht( '%s backed %s with %s.', $this->renderAuthor(), $this->renderObject(), $amount->formatForDisplay()); } public function getIcon() { return 'fa-heart'; } public function getColor() { return 'red'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/application/PhabricatorFundApplication.php
src/applications/fund/application/PhabricatorFundApplication.php
<?php final class PhabricatorFundApplication extends PhabricatorApplication { public function getName() { return pht('Fund'); } public function getBaseURI() { return '/fund/'; } public function getShortDescription() { return pht('Donate'); } public function getIcon() { return 'fa-heart'; } public function getTitleGlyph() { return "\xE2\x99\xA5"; } public function getApplicationGroup() { return self::GROUP_UTILITIES; } public function isPrototype() { return true; } public function getRemarkupRules() { return array( new FundInitiativeRemarkupRule(), ); } public function getRoutes() { return array( '/I(?P<id>[1-9]\d*)' => 'FundInitiativeViewController', '/fund/' => array( '(?:query/(?P<queryKey>[^/]+)/)?' => 'FundInitiativeListController', 'create/' => 'FundInitiativeEditController', $this->getEditRoutePattern('edit/') => 'FundInitiativeEditController', 'close/(?P<id>\d+)/' => 'FundInitiativeCloseController', 'back/(?P<id>\d+)/' => 'FundInitiativeBackController', 'backers/(?:(?P<id>\d+)/)?(?:query/(?P<queryKey>[^/]+)/)?' => 'FundBackerListController', ), ); } protected function getCustomCapabilities() { return array( FundDefaultViewCapability::CAPABILITY => array( 'caption' => pht('Default view policy for newly created initiatives.'), 'template' => FundInitiativePHIDType::TYPECONST, ), FundCreateInitiativesCapability::CAPABILITY => array( 'default' => PhabricatorPolicies::POLICY_ADMIN, ), ); } public function getApplicationSearchDocumentTypes() { return array( FundInitiativePHIDType::TYPECONST, ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/phortune/FundBackerProduct.php
src/applications/fund/phortune/FundBackerProduct.php
<?php final class FundBackerProduct extends PhortuneProductImplementation { private $initiativePHID; private $initiative; private $viewer; public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; } public function getViewer() { return $this->viewer; } public function getRef() { return $this->getInitiativePHID(); } public function getName(PhortuneProduct $product) { $initiative = $this->getInitiative(); if (!$initiative) { return pht('Fund <Unknown Initiative>'); } else { return pht( 'Fund %s %s', $initiative->getMonogram(), $initiative->getName()); } } public function getPriceAsCurrency(PhortuneProduct $product) { return PhortuneCurrency::newEmptyCurrency(); } public function setInitiativePHID($initiative_phid) { $this->initiativePHID = $initiative_phid; return $this; } public function getInitiativePHID() { return $this->initiativePHID; } public function setInitiative(FundInitiative $initiative) { $this->initiative = $initiative; return $this; } public function getInitiative() { return $this->initiative; } public function loadImplementationsForRefs( PhabricatorUser $viewer, array $refs) { $initiatives = id(new FundInitiativeQuery()) ->setViewer($viewer) ->withPHIDs($refs) ->execute(); $initiatives = mpull($initiatives, null, 'getPHID'); $objects = array(); foreach ($refs as $ref) { $object = id(new FundBackerProduct()) ->setViewer($viewer) ->setInitiativePHID($ref); $initiative = idx($initiatives, $ref); if ($initiative) { $object->setInitiative($initiative); } $objects[] = $object; } return $objects; } public function didPurchaseProduct( PhortuneProduct $product, PhortunePurchase $purchase) { $viewer = $this->getViewer(); $backer = id(new FundBackerQuery()) ->setViewer($viewer) ->withPHIDs(array($purchase->getMetadataValue('backerPHID'))) ->executeOne(); if (!$backer) { throw new Exception(pht('Unable to load %s!', 'FundBacker')); } // Load the actual backing user -- they may not be the curent viewer if this // product purchase is completing from a background worker or a merchant // action. $actor = id(new PhabricatorPeopleQuery()) ->setViewer($viewer) ->withPHIDs(array($backer->getBackerPHID())) ->executeOne(); $xactions = array(); $xactions[] = id(new FundInitiativeTransaction()) ->setTransactionType(FundInitiativeBackerTransaction::TRANSACTIONTYPE) ->setMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT, $backer->getAmountAsCurrency()->serializeForStorage()) ->setNewValue($backer->getPHID()); $editor = id(new FundInitiativeEditor()) ->setActor($actor) ->setContentSource($this->getContentSource()); $editor->applyTransactions($this->getInitiative(), $xactions); } public function didRefundProduct( PhortuneProduct $product, PhortunePurchase $purchase, PhortuneCurrency $amount) { $viewer = $this->getViewer(); $backer = id(new FundBackerQuery()) ->setViewer($viewer) ->withPHIDs(array($purchase->getMetadataValue('backerPHID'))) ->executeOne(); if (!$backer) { throw new Exception(pht('Unable to load %s!', 'FundBacker')); } $xactions = array(); $xactions[] = id(new FundInitiativeTransaction()) ->setTransactionType(FundInitiativeRefundTransaction::TRANSACTIONTYPE) ->setMetadataValue( FundInitiativeTransaction::PROPERTY_AMOUNT, $amount->serializeForStorage()) ->setMetadataValue( FundInitiativeTransaction::PROPERTY_BACKER, $backer->getBackerPHID()) ->setNewValue($backer->getPHID()); $editor = id(new FundInitiativeEditor()) ->setActor($viewer) ->setContentSource($this->getContentSource()); $editor->applyTransactions($this->getInitiative(), $xactions); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/phortune/FundBackerCart.php
src/applications/fund/phortune/FundBackerCart.php
<?php final class FundBackerCart extends PhortuneCartImplementation { private $initiativePHID; private $initiative; public function setInitiativePHID($initiative_phid) { $this->initiativePHID = $initiative_phid; return $this; } public function getInitiativePHID() { return $this->initiativePHID; } public function setInitiative(FundInitiative $initiative) { $this->initiative = $initiative; return $this; } public function getInitiative() { return $this->initiative; } public function getName(PhortuneCart $cart) { return pht('Fund Initiative'); } public function willCreateCart( PhabricatorUser $viewer, PhortuneCart $cart) { $initiative = $this->getInitiative(); if (!$initiative) { throw new PhutilInvalidStateException('setInitiative'); } $cart->setMetadataValue('initiativePHID', $initiative->getPHID()); } public function loadImplementationsForCarts( PhabricatorUser $viewer, array $carts) { $phids = array(); foreach ($carts as $cart) { $phids[] = $cart->getMetadataValue('initiativePHID'); } $initiatives = id(new FundInitiativeQuery()) ->setViewer($viewer) ->withPHIDs($phids) ->execute(); $initiatives = mpull($initiatives, null, 'getPHID'); $objects = array(); foreach ($carts as $key => $cart) { $initiative_phid = $cart->getMetadataValue('initiativePHID'); $object = id(new FundBackerCart()) ->setInitiativePHID($initiative_phid); $initiative = idx($initiatives, $initiative_phid); if ($initiative) { $object->setInitiative($initiative); } $objects[$key] = $object; } return $objects; } public function getCancelURI(PhortuneCart $cart) { return '/'.$this->getInitiative()->getMonogram(); } public function getDoneURI(PhortuneCart $cart) { return '/'.$this->getInitiative()->getMonogram(); } public function getDoneActionName(PhortuneCart $cart) { return pht('Return to Initiative'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/phid/FundBackerPHIDType.php
src/applications/fund/phid/FundBackerPHIDType.php
<?php final class FundBackerPHIDType extends PhabricatorPHIDType { const TYPECONST = 'FBAK'; public function getTypeName() { return pht('Variable'); } public function newObject() { return new FundInitiative(); } public function getPHIDTypeApplicationClass() { return 'PhabricatorFundApplication'; } protected function buildQueryForObjects( PhabricatorObjectQuery $query, array $phids) { return id(new FundInitiativeQuery()) ->withPHIDs($phids); } public function loadHandles( PhabricatorHandleQuery $query, array $handles, array $objects) { foreach ($handles as $phid => $handle) { $initiative = $objects[$phid]; $id = $initiative->getID(); $monogram = $initiative->getMonogram(); $name = $initiative->getName(); $handle->setName($name); $handle->setFullName("{$monogram} {$name}"); $handle->setURI("/fund/view/{$id}/"); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/phid/FundInitiativePHIDType.php
src/applications/fund/phid/FundInitiativePHIDType.php
<?php final class FundInitiativePHIDType extends PhabricatorPHIDType { const TYPECONST = 'FITV'; public function getTypeName() { return pht('Fund Initiative'); } public function newObject() { return new FundInitiative(); } public function getPHIDTypeApplicationClass() { return 'PhabricatorFundApplication'; } protected function buildQueryForObjects( PhabricatorObjectQuery $query, array $phids) { return id(new FundInitiativeQuery()) ->withPHIDs($phids); } public function loadHandles( PhabricatorHandleQuery $query, array $handles, array $objects) { foreach ($handles as $phid => $handle) { $initiative = $objects[$phid]; $id = $initiative->getID(); $monogram = $initiative->getMonogram(); $name = $initiative->getName(); if ($initiative->isClosed()) { $handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED); } $handle->setName($name); $handle->setFullName("{$monogram} {$name}"); $handle->setURI("/I{$id}"); } } public function canLoadNamedObject($name) { return preg_match('/^I\d*[1-9]\d*$/i', $name); } public function loadNamedObjects( PhabricatorObjectQuery $query, array $names) { $id_map = array(); foreach ($names as $name) { $id = (int)substr($name, 1); $id_map[$id][] = $name; } $objects = id(new FundInitiativeQuery()) ->setViewer($query->getViewer()) ->withIDs(array_keys($id_map)) ->execute(); $results = array(); foreach ($objects as $id => $object) { foreach (idx($id_map, $id, array()) as $name) { $results[$name] = $object; } } return $results; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/search/FundInitiativeFerretEngine.php
src/applications/fund/search/FundInitiativeFerretEngine.php
<?php final class FundInitiativeFerretEngine extends PhabricatorFerretEngine { public function getApplicationName() { return 'fund'; } public function getScopeName() { return 'initiative'; } public function newSearchEngine() { return new FundInitiativeSearchEngine(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/search/FundInitiativeFulltextEngine.php
src/applications/fund/search/FundInitiativeFulltextEngine.php
<?php final class FundInitiativeFulltextEngine extends PhabricatorFulltextEngine { protected function buildAbstractDocument( PhabricatorSearchAbstractDocument $document, $object) { $initiative = $object; $document->setDocumentTitle($initiative->getName()); $document->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $initiative->getOwnerPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $initiative->getDateCreated()); $document->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $initiative->getOwnerPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $initiative->getDateCreated()); $document->addRelationship( $initiative->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $initiative->getPHID(), FundInitiativePHIDType::TYPECONST, PhabricatorTime::getNow()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/capability/FundCreateInitiativesCapability.php
src/applications/fund/capability/FundCreateInitiativesCapability.php
<?php final class FundCreateInitiativesCapability extends PhabricatorPolicyCapability { const CAPABILITY = 'fund.create'; public function getCapabilityName() { return pht('Can Create Initiatives'); } public function describeCapabilityRejection() { return pht('You do not have permission to create Fund initiatives.'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/capability/FundDefaultViewCapability.php
src/applications/fund/capability/FundDefaultViewCapability.php
<?php final class FundDefaultViewCapability extends PhabricatorPolicyCapability { const CAPABILITY = 'fund.default.view'; public function getCapabilityName() { return pht('Default View Policy'); } public function shouldAllowPublicPolicySetting() { return true; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fund/remarkup/FundInitiativeRemarkupRule.php
src/applications/fund/remarkup/FundInitiativeRemarkupRule.php
<?php final class FundInitiativeRemarkupRule extends PhabricatorObjectRemarkupRule { protected function getObjectNamePrefix() { return 'I'; } protected function loadObjects(array $ids) { $viewer = $this->getEngine()->getConfig('viewer'); return id(new FundInitiativeQuery()) ->setViewer($viewer) ->withIDs($ids) ->execute(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/support/application/PhabricatorSupportApplication.php
src/applications/support/application/PhabricatorSupportApplication.php
<?php final class PhabricatorSupportApplication extends PhabricatorApplication { public function getName() { return pht('Support'); } public function canUninstall() { return false; } public function isUnlisted() { return true; } public function getRoutes() { return array( '/help/' => array( 'keyboardshortcut/' => 'PhabricatorHelpKeyboardShortcutController', ), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthLinkController.php
src/applications/auth/controller/PhabricatorAuthLinkController.php
<?php final class PhabricatorAuthLinkController extends PhabricatorAuthController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $action = $request->getURIData('action'); $id = $request->getURIData('id'); $config = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->withIsEnabled(true) ->executeOne(); if (!$config) { return new Aphront404Response(); } $provider = $config->getProvider(); switch ($action) { case 'link': if (!$provider->shouldAllowAccountLink()) { return $this->renderErrorPage( pht('Account Not Linkable'), array( pht('This provider is not configured to allow linking.'), )); } break; case 'refresh': if (!$provider->shouldAllowAccountRefresh()) { return $this->renderErrorPage( pht('Account Not Refreshable'), array( pht('This provider does not allow refreshing.'), )); } break; default: return new Aphront400Response(); } $accounts = id(new PhabricatorExternalAccountQuery()) ->setViewer($viewer) ->withUserPHIDs(array($viewer->getPHID())) ->withProviderConfigPHIDs(array($config->getPHID())) ->execute(); switch ($action) { case 'link': if ($accounts) { return $this->renderErrorPage( pht('Account Already Linked'), array( pht( 'Your account is already linked to an external account for '. 'this provider.'), )); } break; case 'refresh': if (!$accounts) { return $this->renderErrorPage( pht('No Account Linked'), array( pht( 'You do not have a linked account on this provider, and thus '. 'can not refresh it.'), )); } break; default: return new Aphront400Response(); } $panel_uri = '/settings/panel/external/'; PhabricatorCookies::setClientIDCookie($request); switch ($action) { case 'link': $form = $provider->buildLinkForm($this); break; case 'refresh': $form = $provider->buildRefreshForm($this); break; default: return new Aphront400Response(); } if ($provider->isLoginFormAButton()) { require_celerity_resource('auth-css'); $form = phutil_tag( 'div', array( 'class' => 'phabricator-link-button pl', ), $form); } switch ($action) { case 'link': $name = pht('Link Account'); $title = pht('Link %s Account', $provider->getProviderName()); break; case 'refresh': $name = pht('Refresh Account'); $title = pht('Refresh %s Account', $provider->getProviderName()); break; default: return new Aphront400Response(); } $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Link Account'), $panel_uri); $crumbs->addTextCrumb($provider->getProviderName($name)); $crumbs->setBorder(true); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($form); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthOldOAuthRedirectController.php
src/applications/auth/controller/PhabricatorAuthOldOAuthRedirectController.php
<?php final class PhabricatorAuthOldOAuthRedirectController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function shouldAllowRestrictedParameter($parameter_name) { if ($parameter_name == 'code') { return true; } return parent::shouldAllowRestrictedParameter($parameter_name); } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $provider = $request->getURIData('provider'); // TODO: Most OAuth providers are OK with changing the redirect URI, but // Google and GitHub are strict. We need to respect the old OAuth URI until // we can get installs to migrate. This just keeps the old OAuth URI working // by redirecting to the new one. $provider_map = array( 'google' => 'google:google.com', 'github' => 'github:github.com', ); if (!isset($provider_map[$provider])) { return new Aphront404Response(); } $provider_key = $provider_map[$provider]; $uri = $this->getRequest()->getRequestURI(); $uri->setPath($this->getApplicationURI('login/'.$provider_key.'/')); return id(new AphrontRedirectResponse())->setURI($uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorEmailLoginController.php
src/applications/auth/controller/PhabricatorEmailLoginController.php
<?php final class PhabricatorEmailLoginController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $is_logged_in = $viewer->isLoggedIn(); $e_email = true; $e_captcha = true; $errors = array(); if ($is_logged_in) { if (!$this->isPasswordAuthEnabled()) { return $this->newDialog() ->setTitle(pht('No Password Auth')) ->appendParagraph( pht( 'Password authentication is not enabled and you are already '. 'logged in. There is nothing for you here.')) ->addCancelButton('/', pht('Continue')); } $v_email = $viewer->loadPrimaryEmailAddress(); } else { $v_email = $request->getStr('email'); } if ($request->isFormPost()) { $e_email = null; $e_captcha = pht('Again'); if (!$is_logged_in) { $captcha_ok = AphrontFormRecaptchaControl::processCaptcha($request); if (!$captcha_ok) { $errors[] = pht('Captcha response is incorrect, try again.'); $e_captcha = pht('Invalid'); } } if (!strlen($v_email)) { $errors[] = pht('You must provide an email address.'); $e_email = pht('Required'); } if (!$errors) { // NOTE: Don't validate the email unless the captcha is good; this makes // it expensive to fish for valid email addresses while giving the user // a better error if they goof their email. $action_actor = PhabricatorSystemActionEngine::newActorFromRequest( $request); PhabricatorSystemActionEngine::willTakeAction( array($action_actor), new PhabricatorAuthTryEmailLoginAction(), 1); $target_email = id(new PhabricatorUserEmail())->loadOneWhere( 'address = %s', $v_email); $target_user = null; if ($target_email) { $target_user = id(new PhabricatorUser())->loadOneWhere( 'phid = %s', $target_email->getUserPHID()); } if (!$target_user) { $errors[] = pht('There is no account associated with that email address.'); $e_email = pht('Invalid'); } // If this address is unverified, only send a reset link to it if // the account has no verified addresses. This prevents an opportunistic // attacker from compromising an account if a user adds an email // address but mistypes it and doesn't notice. // (For a newly created account, all the addresses may be unverified, // which is why we'll send to an unverified address in that case.) if ($target_email && !$target_email->getIsVerified()) { $verified_addresses = id(new PhabricatorUserEmail())->loadAllWhere( 'userPHID = %s AND isVerified = 1', $target_email->getUserPHID()); if ($verified_addresses) { $errors[] = pht( 'That email address is not verified, but the account it is '. 'connected to has at least one other verified address. When an '. 'account has at least one verified address, you can only send '. 'password reset links to one of the verified addresses. Try '. 'a verified address instead.'); $e_email = pht('Unverified'); } } if (!$errors) { $target_address = new PhutilEmailAddress($target_email->getAddress()); $user_log = PhabricatorUserLog::initializeNewLog( $viewer, $target_user->getPHID(), PhabricatorEmailLoginUserLogType::LOGTYPE); $mail_engine = id(new PhabricatorPeopleEmailLoginMailEngine()) ->setSender($viewer) ->setRecipient($target_user) ->setRecipientAddress($target_address) ->setActivityLog($user_log); try { $mail_engine->validateMail(); } catch (PhabricatorPeopleMailEngineException $ex) { return $this->newDialog() ->setTitle($ex->getTitle()) ->appendParagraph($ex->getBody()) ->addCancelButton('/auth/start/', pht('Done')); } $mail_engine->sendMail(); if ($is_logged_in) { $instructions = pht( 'An email has been sent containing a link you can use to set '. 'a password for your account.'); } else { $instructions = pht( 'An email has been sent containing a link you can use to log '. 'in to your account.'); } return $this->newDialog() ->setTitle(pht('Check Your Email')) ->setShortTitle(pht('Email Sent')) ->appendParagraph($instructions) ->addCancelButton('/', pht('Done')); } } } $form = id(new AphrontFormView()) ->setViewer($viewer); if ($this->isPasswordAuthEnabled()) { if ($is_logged_in) { $title = pht('Set Password'); $form->appendRemarkupInstructions( pht( 'A password reset link will be sent to your primary email '. 'address. Follow the link to set an account password.')); } else { $title = pht('Password Reset'); $form->appendRemarkupInstructions( pht( 'To reset your password, provide your email address. An email '. 'with a login link will be sent to you.')); } } else { $title = pht('Email Login'); $form->appendRemarkupInstructions( pht( 'To access your account, provide your email address. An email '. 'with a login link will be sent to you.')); } if ($is_logged_in) { $address_control = new AphrontFormStaticControl(); } else { $address_control = id(new AphrontFormTextControl()) ->setName('email') ->setError($e_email); } $address_control ->setLabel(pht('Email Address')) ->setValue($v_email); $form ->appendControl($address_control); if (!$is_logged_in) { $form->appendControl( id(new AphrontFormRecaptchaControl()) ->setLabel(pht('Captcha')) ->setError($e_captcha)); } return $this->newDialog() ->setTitle($title) ->setErrors($errors) ->setWidth(AphrontDialogView::WIDTH_FORM) ->appendForm($form) ->addCancelButton('/auth/start/') ->addSubmitButton(pht('Send Email')); } private function isPasswordAuthEnabled() { return (bool)PhabricatorPasswordAuthProvider::getPasswordProvider(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthSetExternalController.php
src/applications/auth/controller/PhabricatorAuthSetExternalController.php
<?php final class PhabricatorAuthSetExternalController extends PhabricatorAuthController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $configs = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer($viewer) ->withIsEnabled(true) ->execute(); $linkable = array(); foreach ($configs as $config) { if (!$config->getShouldAllowLink()) { continue; } // For now, only buttons get to appear here: for example, we can't // reasonably embed an entire LDAP form into this UI. $provider = $config->getProvider(); if (!$provider->isLoginFormAButton()) { continue; } $linkable[] = $config; } if (!$linkable) { return $this->newDialog() ->setTitle(pht('No Linkable External Providers')) ->appendParagraph( pht( 'Currently, there are no configured external auth providers '. 'which you can link your account to.')) ->addCancelButton('/'); } $text = PhabricatorAuthMessage::loadMessageText( $viewer, PhabricatorAuthLinkMessageType::MESSAGEKEY); if (!phutil_nonempty_string($text)) { $text = pht( 'You can link your %s account to an external account to '. 'allow you to log in more easily in the future. To continue, choose '. 'an account to link below. If you prefer not to link your account, '. 'you can skip this step.', PlatformSymbols::getPlatformServerName()); } $remarkup_view = new PHUIRemarkupView($viewer, $text); $remarkup_view = phutil_tag( 'div', array( 'class' => 'phui-object-box-instructions', ), $remarkup_view); PhabricatorCookies::setClientIDCookie($request); $view = array(); foreach ($configs as $config) { $provider = $config->getProvider(); $form = $provider->buildLinkForm($this); if ($provider->isLoginFormAButton()) { require_celerity_resource('auth-css'); $form = phutil_tag( 'div', array( 'class' => 'phabricator-link-button pl', ), $form); } $view[] = $form; } $form = id(new AphrontFormView()) ->setViewer($viewer) ->appendControl( id(new AphrontFormSubmitControl()) ->addCancelButton('/', pht('Skip This Step'))); $header = id(new PHUIHeaderView()) ->setHeader(pht('Link External Account')); $box = id(new PHUIObjectBoxView()) ->setViewer($viewer) ->setHeader($header) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->appendChild($remarkup_view) ->appendChild($view) ->appendChild($form); $main_view = id(new PHUITwoColumnView()) ->setFooter($box); $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb(pht('Link External Account')) ->setBorder(true); return $this->newPage() ->setTitle(pht('Link External Account')) ->setCrumbs($crumbs) ->appendChild($main_view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthTerminateSessionController.php
src/applications/auth/controller/PhabricatorAuthTerminateSessionController.php
<?php final class PhabricatorAuthTerminateSessionController extends PhabricatorAuthController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); $is_all = ($id === 'all'); $query = id(new PhabricatorAuthSessionQuery()) ->setViewer($viewer) ->withIdentityPHIDs(array($viewer->getPHID())); if (!$is_all) { $query->withIDs(array($id)); } $current_key = PhabricatorAuthSession::newSessionDigest( new PhutilOpaqueEnvelope( $request->getCookie(PhabricatorCookies::COOKIE_SESSION))); $sessions = $query->execute(); foreach ($sessions as $key => $session) { $is_current = phutil_hashes_are_identical( $session->getSessionKey(), $current_key); if ($is_current) { // Don't terminate the current login session. unset($sessions[$key]); } } $panel_uri = '/settings/panel/sessions/'; if (!$sessions) { return $this->newDialog() ->setTitle(pht('No Matching Sessions')) ->appendParagraph( pht('There are no matching sessions to terminate.')) ->appendParagraph( pht( '(You can not terminate your current login session. To '. 'terminate it, log out.)')) ->addCancelButton($panel_uri); } if ($request->isDialogFormPost()) { foreach ($sessions as $session) { $session->delete(); } return id(new AphrontRedirectResponse())->setURI($panel_uri); } if ($is_all) { $title = pht('Terminate Sessions?'); $short = pht('Terminate Sessions'); $body = pht( 'Really terminate all sessions? (Your current login session will '. 'not be terminated.)'); } else { $title = pht('Terminate Session?'); $short = pht('Terminate Session'); $body = pht( 'Really terminate session %s?', phutil_tag('strong', array(), substr($session->getSessionKey(), 0, 6))); } return $this->newDialog() ->setTitle($title) ->setShortTitle($short) ->appendParagraph($body) ->addSubmitButton(pht('Terminate')) ->addCancelButton($panel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthInviteController.php
src/applications/auth/controller/PhabricatorAuthInviteController.php
<?php final class PhabricatorAuthInviteController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $engine = id(new PhabricatorAuthInviteEngine()) ->setViewer($viewer); if ($request->isFormPost()) { $engine->setUserHasConfirmedVerify(true); } $invite_code = $request->getURIData('code'); try { $invite = $engine->processInviteCode($invite_code); } catch (PhabricatorAuthInviteDialogException $ex) { $response = $this->newDialog() ->setTitle($ex->getTitle()) ->appendParagraph($ex->getBody()); $submit_text = $ex->getSubmitButtonText(); if ($submit_text) { $response->addSubmitButton($submit_text); } $submit_uri = $ex->getSubmitButtonURI(); if ($submit_uri) { $response->setSubmitURI($submit_uri); } $cancel_uri = $ex->getCancelButtonURI(); $cancel_text = $ex->getCancelButtonText(); if ($cancel_uri && $cancel_text) { $response->addCancelButton($cancel_uri, $cancel_text); } else if ($cancel_uri) { $response->addCancelButton($cancel_uri); } return $response; } catch (PhabricatorAuthInviteRegisteredException $ex) { // We're all set on processing this invite, just send the user home. return id(new AphrontRedirectResponse())->setURI('/'); } // Give the user a cookie with the invite code and send them through // normal registration. We'll adjust the flow there. $request->setCookie( PhabricatorCookies::COOKIE_INVITE, $invite_code); return id(new AphrontRedirectResponse())->setURI('/auth/start/'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthSetPasswordController.php
src/applications/auth/controller/PhabricatorAuthSetPasswordController.php
<?php final class PhabricatorAuthSetPasswordController extends PhabricatorAuthController { public function shouldAllowPartialSessions() { return true; } public function shouldAllowLegallyNonCompliantUsers() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); if (!PhabricatorPasswordAuthProvider::getPasswordProvider()) { return new Aphront404Response(); } $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( $viewer, $request, '/'); $key = $request->getStr('key'); $password_type = PhabricatorAuthPasswordResetTemporaryTokenType::TOKENTYPE; if (!$key) { return new Aphront404Response(); } $auth_token = id(new PhabricatorAuthTemporaryTokenQuery()) ->setViewer($viewer) ->withTokenResources(array($viewer->getPHID())) ->withTokenTypes(array($password_type)) ->withTokenCodes(array(PhabricatorHash::weakDigest($key))) ->withExpired(false) ->executeOne(); if (!$auth_token) { return new Aphront404Response(); } $content_source = PhabricatorContentSource::newFromRequest($request); $account_type = PhabricatorAuthPassword::PASSWORD_TYPE_ACCOUNT; $password_objects = id(new PhabricatorAuthPasswordQuery()) ->setViewer($viewer) ->withObjectPHIDs(array($viewer->getPHID())) ->withPasswordTypes(array($account_type)) ->withIsRevoked(false) ->execute(); if ($password_objects) { $password_object = head($password_objects); $has_password = true; } else { $password_object = PhabricatorAuthPassword::initializeNewPassword( $viewer, $account_type); $has_password = false; } $engine = id(new PhabricatorAuthPasswordEngine()) ->setViewer($viewer) ->setContentSource($content_source) ->setPasswordType($account_type) ->setObject($viewer); $e_password = true; $e_confirm = true; $errors = array(); if ($request->isFormPost()) { $password = $request->getStr('password'); $confirm = $request->getStr('confirm'); $password_envelope = new PhutilOpaqueEnvelope($password); $confirm_envelope = new PhutilOpaqueEnvelope($confirm); try { $engine->checkNewPassword($password_envelope, $confirm_envelope, true); $e_password = null; $e_confirm = null; } catch (PhabricatorAuthPasswordException $ex) { $errors[] = $ex->getMessage(); $e_password = $ex->getPasswordError(); $e_confirm = $ex->getConfirmError(); } if (!$errors) { $password_object ->setPassword($password_envelope, $viewer) ->save(); // Destroy the token. $auth_token->delete(); return id(new AphrontRedirectResponse())->setURI('/'); } } $min_len = PhabricatorEnv::getEnvConfig('account.minimum-password-length'); $min_len = (int)$min_len; $len_caption = null; if ($min_len) { $len_caption = pht('Minimum password length: %d characters.', $min_len); } if ($has_password) { $title = pht('Reset Password'); $crumb = pht('Reset Password'); $submit = pht('Reset Password'); } else { $title = pht('Set Password'); $crumb = pht('Set Password'); $submit = pht('Set Account Password'); } $form = id(new AphrontFormView()) ->setViewer($viewer) ->addHiddenInput('key', $key) ->appendChild( id(new AphrontFormPasswordControl()) ->setDisableAutocomplete(true) ->setLabel(pht('New Password')) ->setError($e_password) ->setName('password')) ->appendChild( id(new AphrontFormPasswordControl()) ->setDisableAutocomplete(true) ->setLabel(pht('Confirm Password')) ->setCaption($len_caption) ->setError($e_confirm) ->setName('confirm')) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton('/', pht('Skip This Step')) ->setValue($submit)); $form_box = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->setFormErrors($errors) ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) ->setForm($form); $main_view = id(new PHUITwoColumnView()) ->setFooter($form_box); $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb($crumb) ->setBorder(true); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($main_view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthDowngradeSessionController.php
src/applications/auth/controller/PhabricatorAuthDowngradeSessionController.php
<?php final class PhabricatorAuthDowngradeSessionController extends PhabricatorAuthController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $panel_uri = '/settings/panel/sessions/'; $session = $viewer->getSession(); if ($session->getHighSecurityUntil() < time()) { return $this->newDialog() ->setTitle(pht('Normal Security Restored')) ->appendParagraph( pht('Your session is no longer in high security.')) ->addCancelButton($panel_uri, pht('Continue')); } if ($request->isFormPost()) { id(new PhabricatorAuthSessionEngine()) ->exitHighSecurity($viewer, $session); return id(new AphrontRedirectResponse()) ->setURI($this->getApplicationURI('session/downgrade/')); } return $this->newDialog() ->setTitle(pht('Leaving High Security')) ->appendParagraph( pht( 'Leave high security and return your session to normal '. 'security levels?')) ->appendParagraph( pht( 'If you leave high security, you will need to authenticate '. 'again the next time you try to take a high security action.')) ->appendParagraph( pht( 'On the plus side, that purple notification bubble will '. 'disappear.')) ->addSubmitButton(pht('Leave High Security')) ->addCancelButton($panel_uri, pht('Stay')); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthRevokeTokenController.php
src/applications/auth/controller/PhabricatorAuthRevokeTokenController.php
<?php final class PhabricatorAuthRevokeTokenController extends PhabricatorAuthController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); $is_all = ($id === 'all'); $query = id(new PhabricatorAuthTemporaryTokenQuery()) ->setViewer($viewer) ->withTokenResources(array($viewer->getPHID())); if (!$is_all) { $query->withIDs(array($id)); } $tokens = $query->execute(); foreach ($tokens as $key => $token) { if (!$token->isRevocable()) { // Don't revoke unrevocable tokens. unset($tokens[$key]); } } $panel_uri = id(new PhabricatorTokensSettingsPanel()) ->setViewer($viewer) ->setUser($viewer) ->getPanelURI(); if (!$tokens) { return $this->newDialog() ->setTitle(pht('No Matching Tokens')) ->appendParagraph( pht('There are no matching tokens to revoke.')) ->appendParagraph( pht( '(Some types of token can not be revoked, and you can not revoke '. 'tokens which have already expired.)')) ->addCancelButton($panel_uri); } if ($request->isDialogFormPost()) { foreach ($tokens as $token) { $token->revokeToken(); } return id(new AphrontRedirectResponse())->setURI($panel_uri); } if ($is_all) { $title = pht('Revoke Tokens?'); $short = pht('Revoke Tokens'); $body = pht( 'Really revoke all tokens? Among other temporary authorizations, '. 'this will disable any outstanding password reset or account '. 'recovery links.'); } else { $title = pht('Revoke Token?'); $short = pht('Revoke Token'); $body = pht( 'Really revoke this token? Any temporary authorization it enables '. 'will be disabled.'); } return $this->newDialog() ->setTitle($title) ->setShortTitle($short) ->appendParagraph($body) ->addSubmitButton(pht('Revoke')) ->addCancelButton($panel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorLogoutController.php
src/applications/auth/controller/PhabricatorLogoutController.php
<?php final class PhabricatorLogoutController extends PhabricatorAuthController { public function shouldRequireLogin() { // See T13310. We allow access to the "Logout" controller even if you are // not logged in: otherwise, users who do not have access to any Spaces can // not log out. // When you try to access a controller which requires you be logged in, // and you do not have access to any Spaces, an access check fires first // and prevents access with a "No Access to Spaces" error. If this // controller requires users be logged in, users who are trying to log out // and also have no access to Spaces get the error instead of a logout // workflow and are trapped. // By permitting access to this controller even if you are not logged in, // we bypass the Spaces check and allow users who have no access to Spaces // to log out. // This incidentally allows users who are already logged out to access the // controller, but this is harmless: we just no-op these requests. return false; } public function shouldRequireEmailVerification() { // Allow unverified users to logout. return false; } public function shouldRequireEnabledUser() { // Allow disabled users to logout. return false; } public function shouldAllowPartialSessions() { return true; } public function shouldAllowLegallyNonCompliantUsers() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); if ($request->isFormPost()) { // Destroy the user's session in the database so logout works even if // their cookies have some issues. We'll detect cookie issues when they // try to login again and tell them to clear any junk. $phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION); if (strlen($phsid)) { $session = id(new PhabricatorAuthSessionQuery()) ->setViewer($viewer) ->withSessionKeys(array($phsid)) ->executeOne(); if ($session) { $engine = new PhabricatorAuthSessionEngine(); $engine->logoutSession($viewer, $session); } } $request->clearCookie(PhabricatorCookies::COOKIE_SESSION); return id(new AphrontRedirectResponse()) ->setURI('/auth/loggedout/'); } if ($viewer->getPHID()) { $dialog = $this->newDialog() ->setTitle(pht('Log Out?')) ->appendParagraph(pht('Are you sure you want to log out?')) ->addCancelButton('/'); $configs = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->execute(); if (!$configs) { $dialog ->appendRemarkup( pht( 'WARNING: You have not configured any authentication providers '. 'yet, so your account has no login credentials. If you log out '. 'now, you will not be able to log back in normally.')) ->appendParagraph( pht( 'To enable the login flow, follow setup guidance and configure '. 'at least one authentication provider, then associate '. 'credentials with your account. After completing these steps, '. 'you will be able to log out and log back in normally.')) ->appendParagraph( pht( 'If you log out now, you can still regain access to your '. 'account later by using the account recovery workflow. The '. 'login screen will prompt you with recovery instructions.')); $button = pht('Log Out Anyway'); } else { $button = pht('Log Out'); } $dialog->addSubmitButton($button); return $dialog; } return id(new AphrontRedirectResponse())->setURI('/'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorEmailVerificationController.php
src/applications/auth/controller/PhabricatorEmailVerificationController.php
<?php final class PhabricatorEmailVerificationController extends PhabricatorAuthController { public function shouldRequireEmailVerification() { // Since users need to be able to hit this endpoint in order to verify // email, we can't ever require email verification here. return false; } public function shouldRequireEnabledUser() { // Unapproved users are allowed to verify their email addresses. We'll kick // disabled users out later. return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $code = $request->getURIData('code'); if ($viewer->getIsDisabled()) { // We allowed unapproved and disabled users to hit this controller, but // want to kick out disabled users now. return new Aphront400Response(); } $email = id(new PhabricatorUserEmail())->loadOneWhere( 'userPHID = %s AND verificationCode = %s', $viewer->getPHID(), $code); $submit = null; if (!$email) { $title = pht('Unable to Verify Email'); $content = pht( 'The verification code you provided is incorrect, or the email '. 'address has been removed, or the email address is owned by another '. 'user. Make sure you followed the link in the email correctly and are '. 'logged in with the user account associated with the email address.'); $continue = pht('Rats!'); } else if ($email->getIsVerified() && $viewer->getIsEmailVerified()) { $title = pht('Address Already Verified'); $content = pht( 'This email address has already been verified.'); $continue = pht('Continue'); } else if ($request->isFormPost()) { id(new PhabricatorUserEditor()) ->setActor($viewer) ->verifyEmail($viewer, $email); $title = pht('Address Verified'); $content = pht( 'The email address %s is now verified.', phutil_tag('strong', array(), $email->getAddress())); $continue = pht('Continue'); } else { $title = pht('Verify Email Address'); $content = pht( 'Verify this email address (%s) and attach it to your account?', phutil_tag('strong', array(), $email->getAddress())); $continue = pht('Cancel'); $submit = pht('Verify %s', $email->getAddress()); } $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setTitle($title) ->addCancelButton('/', $continue) ->appendChild($content); if ($submit) { $dialog->addSubmitButton($submit); } $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Verify Email')); $crumbs->setBorder(true); return $this->newPage() ->setTitle(pht('Verify Email')) ->setCrumbs($crumbs) ->appendChild($dialog); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthSSHKeyListController.php
src/applications/auth/controller/PhabricatorAuthSSHKeyListController.php
<?php final class PhabricatorAuthSSHKeyListController extends PhabricatorAuthSSHKeyController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $object_phid = $request->getURIData('forPHID'); $object = $this->loadSSHKeyObject($object_phid, false); if (!$object) { return new Aphront404Response(); } $engine = id(new PhabricatorAuthSSHKeySearchEngine()) ->setSSHKeyObject($object); return id($engine) ->setController($this) ->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthConfirmLinkController.php
src/applications/auth/controller/PhabricatorAuthConfirmLinkController.php
<?php final class PhabricatorAuthConfirmLinkController extends PhabricatorAuthController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $accountkey = $request->getURIData('akey'); $result = $this->loadAccountForRegistrationOrLinking($accountkey); list($account, $provider, $response) = $result; if ($response) { return $response; } if (!$provider->shouldAllowAccountLink()) { return $this->renderError(pht('This account is not linkable.')); } $panel_uri = '/settings/panel/external/'; if ($request->isFormOrHisecPost()) { $workflow_key = sprintf( 'account.link(%s)', $account->getPHID()); $hisec_token = id(new PhabricatorAuthSessionEngine()) ->setWorkflowKey($workflow_key) ->requireHighSecurityToken($viewer, $request, $panel_uri); $account->setUserPHID($viewer->getPHID()); $account->save(); $this->clearRegistrationCookies(); // TODO: Send the user email about the new account link. return id(new AphrontRedirectResponse())->setURI($panel_uri); } $dialog = $this->newDialog() ->setTitle(pht('Confirm %s Account Link', $provider->getProviderName())) ->addCancelButton($panel_uri) ->addSubmitButton(pht('Confirm Account Link')); $form = id(new PHUIFormLayoutView()) ->setFullWidth(true) ->appendChild( phutil_tag( 'div', array( 'class' => 'aphront-form-instructions', ), pht( 'Confirm the link with this %s account. This account will be '. 'able to log in to your %s account.', $provider->getProviderName(), PlatformSymbols::getPlatformServerName()))) ->appendChild( id(new PhabricatorAuthAccountView()) ->setUser($viewer) ->setExternalAccount($account) ->setAuthProvider($provider)); $dialog->appendChild($form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Confirm Link'), $panel_uri); $crumbs->addTextCrumb($provider->getProviderName()); $crumbs->setBorder(true); return $this->newPage() ->setTitle(pht('Confirm External Account Link')) ->setCrumbs($crumbs) ->appendChild($dialog); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthSSHKeyViewController.php
src/applications/auth/controller/PhabricatorAuthSSHKeyViewController.php
<?php final class PhabricatorAuthSSHKeyViewController extends PhabricatorAuthSSHKeyController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $ssh_key = id(new PhabricatorAuthSSHKeyQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$ssh_key) { return new Aphront404Response(); } $this->setSSHKeyObject($ssh_key->getObject()); $title = pht('SSH Key %d', $ssh_key->getID()); $curtain = $this->buildCurtain($ssh_key); $details = $this->buildPropertySection($ssh_key); $header = id(new PHUIHeaderView()) ->setUser($viewer) ->setHeader($ssh_key->getName()) ->setHeaderIcon('fa-key'); if ($ssh_key->getIsActive()) { $header->setStatus('fa-check', 'bluegrey', pht('Active')); } else { $header->setStatus('fa-ban', 'dark', pht('Revoked')); } $header->addActionLink( id(new PHUIButtonView()) ->setTag('a') ->setText(pht('View Active Keys')) ->setHref($ssh_key->getObject()->getSSHPublicKeyManagementURI($viewer)) ->setIcon('fa-list-ul')); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); $crumbs->setBorder(true); $timeline = $this->buildTransactionTimeline( $ssh_key, new PhabricatorAuthSSHKeyTransactionQuery()); $timeline->setShouldTerminate(true); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->setMainColumn( array( $details, $timeline, )); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($view); } private function buildCurtain(PhabricatorAuthSSHKey $ssh_key) { $viewer = $this->getViewer(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $ssh_key, PhabricatorPolicyCapability::CAN_EDIT); $id = $ssh_key->getID(); $edit_uri = $this->getApplicationURI("sshkey/edit/{$id}/"); $revoke_uri = $this->getApplicationURI("sshkey/revoke/{$id}/"); $curtain = $this->newCurtainView($ssh_key); $curtain->addAction( id(new PhabricatorActionView()) ->setIcon('fa-pencil') ->setName(pht('Edit SSH Key')) ->setHref($edit_uri) ->setWorkflow(true) ->setDisabled(!$can_edit)); $curtain->addAction( id(new PhabricatorActionView()) ->setIcon('fa-times') ->setName(pht('Revoke SSH Key')) ->setHref($revoke_uri) ->setWorkflow(true) ->setDisabled(!$can_edit)); return $curtain; } private function buildPropertySection( PhabricatorAuthSSHKey $ssh_key) { $viewer = $this->getViewer(); $properties = id(new PHUIPropertyListView()) ->setUser($viewer); $properties->addProperty(pht('SSH Key Type'), $ssh_key->getKeyType()); $properties->addProperty( pht('Created'), phabricator_datetime($ssh_key->getDateCreated(), $viewer)); return id(new PHUIObjectBoxView()) ->setHeaderText(pht('Details')) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->appendChild($properties); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorMustVerifyEmailController.php
src/applications/auth/controller/PhabricatorMustVerifyEmailController.php
<?php final class PhabricatorMustVerifyEmailController extends PhabricatorAuthController { public function shouldRequireEmailVerification() { // NOTE: We don't technically need this since PhabricatorController forces // us here in either case, but it's more consistent with intent. return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $email = $viewer->loadPrimaryEmail(); if ($viewer->getIsEmailVerified()) { return id(new AphrontRedirectResponse())->setURI('/'); } $email_address = $email->getAddress(); $sent = null; if ($request->isFormPost()) { $email->sendVerificationEmail($viewer); $sent = new PHUIInfoView(); $sent->setSeverity(PHUIInfoView::SEVERITY_NOTICE); $sent->setTitle(pht('Email Sent')); $sent->appendChild( pht( 'Another verification email was sent to %s.', phutil_tag('strong', array(), $email_address))); } $must_verify = pht( 'You must verify your email address to log in. You should have a '. 'new email message with verification instructions in your inbox (%s).', phutil_tag('strong', array(), $email_address)); $send_again = pht( 'If you did not receive an email, you can click the button below '. 'to try sending another one.'); $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setTitle(pht('Check Your Email')) ->appendParagraph($must_verify) ->appendParagraph($send_again) ->addSubmitButton(pht('Send Another Email')); $view = array( $sent, $dialog, ); return $this->newPage() ->setTitle(pht('Must Verify Email')) ->appendChild($view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthFinishController.php
src/applications/auth/controller/PhabricatorAuthFinishController.php
<?php final class PhabricatorAuthFinishController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function shouldAllowPartialSessions() { return true; } public function shouldAllowLegallyNonCompliantUsers() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); // If the user already has a full session, just kick them out of here. $has_partial_session = $viewer->hasSession() && $viewer->getSession()->getIsPartial(); if (!$has_partial_session) { return id(new AphrontRedirectResponse())->setURI('/'); } $engine = new PhabricatorAuthSessionEngine(); // If this cookie is set, the user is headed into a high security area // after login (normally because of a password reset) so if they are // able to pass the checkpoint we just want to put their account directly // into high security mode, rather than prompt them again for the same // set of credentials. $jump_into_hisec = $request->getCookie(PhabricatorCookies::COOKIE_HISEC); try { $token = $engine->requireHighSecuritySession( $viewer, $request, '/logout/', $jump_into_hisec); } catch (PhabricatorAuthHighSecurityRequiredException $ex) { $form = id(new PhabricatorAuthSessionEngine())->renderHighSecurityForm( $ex->getFactors(), $ex->getFactorValidationResults(), $viewer, $request); return $this->newDialog() ->setTitle(pht('Provide Multi-Factor Credentials')) ->setShortTitle(pht('Multi-Factor Login')) ->setWidth(AphrontDialogView::WIDTH_FORM) ->addHiddenInput(AphrontRequest::TYPE_HISEC, true) ->appendParagraph( pht( 'Welcome, %s. To complete the process of logging in, provide your '. 'multi-factor credentials.', phutil_tag('strong', array(), $viewer->getUsername()))) ->appendChild($form->buildLayoutView()) ->setSubmitURI($request->getPath()) ->addCancelButton($ex->getCancelURI()) ->addSubmitButton(pht('Continue')); } // Upgrade the partial session to a full session. $engine->upgradePartialSession($viewer); // TODO: It might be nice to add options like "bind this session to my IP" // here, even for accounts without multi-factor auth attached to them. $next = PhabricatorCookies::getNextURICookie($request); $request->clearCookie(PhabricatorCookies::COOKIE_NEXTURI); $request->clearCookie(PhabricatorCookies::COOKIE_HISEC); if (!PhabricatorEnv::isValidLocalURIForLink($next)) { $next = '/'; } return id(new AphrontRedirectResponse())->setURI($next); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthSSHKeyEditController.php
src/applications/auth/controller/PhabricatorAuthSSHKeyEditController.php
<?php final class PhabricatorAuthSSHKeyEditController extends PhabricatorAuthSSHKeyController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); if ($id) { $key = id(new PhabricatorAuthSSHKeyQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$key) { return new Aphront404Response(); } $is_new = false; } else { $key = $this->newKeyForObjectPHID($request->getStr('objectPHID')); if (!$key) { return new Aphront404Response(); } $is_new = true; } $cancel_uri = $key->getObject()->getSSHPublicKeyManagementURI($viewer); if ($key->getIsTrusted()) { $id = $key->getID(); return $this->newDialog() ->setTitle(pht('Can Not Edit Trusted Key')) ->appendParagraph( pht( 'This key is trusted. Trusted keys can not be edited. '. 'Use %s to revoke trust before editing the key.', phutil_tag( 'tt', array(), "bin/almanac untrust-key --id {$id}"))) ->addCancelButton($cancel_uri, pht('Okay')); } $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( $viewer, $request, $cancel_uri); $v_name = $key->getName(); $e_name = $v_name !== null && strlen($v_name) ? null : true; $v_key = $key->getEntireKey(); $e_key = $v_key !== null && strlen($v_key) ? null : true; $validation_exception = null; if ($request->isFormPost()) { $type_create = PhabricatorTransactions::TYPE_CREATE; $type_name = PhabricatorAuthSSHKeyTransaction::TYPE_NAME; $type_key = PhabricatorAuthSSHKeyTransaction::TYPE_KEY; $e_name = null; $e_key = null; $v_name = $request->getStr('name'); $v_key = $request->getStr('key'); $xactions = array(); if (!$key->getID()) { $xactions[] = id(new PhabricatorAuthSSHKeyTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_CREATE); } $xactions[] = id(new PhabricatorAuthSSHKeyTransaction()) ->setTransactionType($type_name) ->setNewValue($v_name); $xactions[] = id(new PhabricatorAuthSSHKeyTransaction()) ->setTransactionType($type_key) ->setNewValue($v_key); $editor = id(new PhabricatorAuthSSHKeyEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); try { $editor->applyTransactions($key, $xactions); return id(new AphrontRedirectResponse())->setURI($cancel_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_name = $ex->getShortMessage($type_name); $e_key = $ex->getShortMessage($type_key); } } $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Name')) ->setName('name') ->setError($e_name) ->setValue($v_name)) ->appendChild( id(new AphrontFormTextAreaControl()) ->setLabel(pht('Public Key')) ->setName('key') ->setValue($v_key) ->setError($e_key)); if ($is_new) { $title = pht('Upload SSH Public Key'); $save_button = pht('Upload Public Key'); $form->addHiddenInput('objectPHID', $key->getObject()->getPHID()); } else { $title = pht('Edit SSH Public Key'); $save_button = pht('Save Changes'); } return $this->newDialog() ->setTitle($title) ->setWidth(AphrontDialogView::WIDTH_FORM) ->setValidationException($validation_exception) ->appendForm($form) ->addSubmitButton($save_button) ->addCancelButton($cancel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthUnlinkController.php
src/applications/auth/controller/PhabricatorAuthUnlinkController.php
<?php final class PhabricatorAuthUnlinkController extends PhabricatorAuthController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); $account = id(new PhabricatorExternalAccountQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$account) { return new Aphront404Response(); } $done_uri = '/settings/panel/external/'; $config = $account->getProviderConfig(); $provider = $config->getProvider(); if (!$provider->shouldAllowAccountUnlink()) { return $this->renderNotUnlinkableErrorDialog($provider, $done_uri); } $confirmations = $request->getStrList('confirmations'); $confirmations = array_fuse($confirmations); if (!$request->isFormOrHisecPost() || !isset($confirmations['unlink'])) { return $this->renderConfirmDialog($confirmations, $config, $done_uri); } // Check that this account isn't the only account which can be used to // login. We warn you when you remove your only login account. if ($account->isUsableForLogin()) { $other_accounts = id(new PhabricatorExternalAccountQuery()) ->setViewer($viewer) ->withUserPHIDs(array($viewer->getPHID())) ->execute(); $valid_accounts = 0; foreach ($other_accounts as $other_account) { if ($other_account->isUsableForLogin()) { $valid_accounts++; } } if ($valid_accounts < 2) { if (!isset($confirmations['only'])) { return $this->renderOnlyUsableAccountConfirmDialog( $confirmations, $done_uri); } } } $workflow_key = sprintf( 'account.unlink(%s)', $account->getPHID()); $hisec_token = id(new PhabricatorAuthSessionEngine()) ->setWorkflowKey($workflow_key) ->requireHighSecurityToken($viewer, $request, $done_uri); $account->unlinkAccount(); id(new PhabricatorAuthSessionEngine())->terminateLoginSessions( $viewer, new PhutilOpaqueEnvelope( $request->getCookie(PhabricatorCookies::COOKIE_SESSION))); return id(new AphrontRedirectResponse())->setURI($done_uri); } private function renderNotUnlinkableErrorDialog( PhabricatorAuthProvider $provider, $done_uri) { return $this->newDialog() ->setTitle(pht('Permanent Account Link')) ->appendChild( pht( 'You can not unlink this account because the administrator has '. 'configured this server to make links to "%s" accounts permanent.', $provider->getProviderName())) ->addCancelButton($done_uri); } private function renderOnlyUsableAccountConfirmDialog( array $confirmations, $done_uri) { $confirmations[] = 'only'; return $this->newDialog() ->setTitle(pht('Unlink Your Only Login Account?')) ->addHiddenInput('confirmations', implode(',', $confirmations)) ->appendParagraph( pht( 'This is the only external login account linked to your Phabicator '. 'account. If you remove it, you may no longer be able to log in.')) ->appendParagraph( pht( 'If you lose access to your account, you can recover access by '. 'sending yourself an email login link from the login screen.')) ->addCancelButton($done_uri) ->addSubmitButton(pht('Unlink External Account')); } private function renderConfirmDialog( array $confirmations, PhabricatorAuthProviderConfig $config, $done_uri) { $confirmations[] = 'unlink'; $provider = $config->getProvider(); $title = pht('Unlink "%s" Account?', $provider->getProviderName()); $body = pht( 'You will no longer be able to use your %s account to '. 'log in.', $provider->getProviderName()); return $this->newDialog() ->setTitle($title) ->addHiddenInput('confirmations', implode(',', $confirmations)) ->appendParagraph($body) ->appendParagraph( pht( 'Note: Unlinking an authentication provider will terminate any '. 'other active login sessions.')) ->addSubmitButton(pht('Unlink Account')) ->addCancelButton($done_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthLoginController.php
src/applications/auth/controller/PhabricatorAuthLoginController.php
<?php final class PhabricatorAuthLoginController extends PhabricatorAuthController { private $providerKey; private $extraURIData; private $provider; public function shouldRequireLogin() { return false; } public function shouldAllowRestrictedParameter($parameter_name) { // Whitelist the OAuth 'code' parameter. if ($parameter_name == 'code') { return true; } return parent::shouldAllowRestrictedParameter($parameter_name); } public function getExtraURIData() { return $this->extraURIData; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $this->providerKey = $request->getURIData('pkey'); $this->extraURIData = $request->getURIData('extra'); $response = $this->loadProvider(); if ($response) { return $response; } $invite = $this->loadInvite(); $provider = $this->provider; try { list($account, $response) = $provider->processLoginRequest($this); } catch (PhutilAuthUserAbortedException $ex) { if ($viewer->isLoggedIn()) { // If a logged-in user cancels, take them back to the external accounts // panel. $next_uri = '/settings/panel/external/'; } else { // If a logged-out user cancels, take them back to the auth start page. $next_uri = '/'; } // User explicitly hit "Cancel". $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setTitle(pht('Authentication Canceled')) ->appendChild( pht('You canceled authentication.')) ->addCancelButton($next_uri, pht('Continue')); return id(new AphrontDialogResponse())->setDialog($dialog); } if ($response) { return $response; } if (!$account) { throw new Exception( pht( 'Auth provider failed to load an account from %s!', 'processLoginRequest()')); } if ($account->getUserPHID()) { // The account is already attached to a Phabricator user, so this is // either a login or a bad account link request. if (!$viewer->isLoggedIn()) { if ($provider->shouldAllowLogin()) { return $this->processLoginUser($account); } else { return $this->renderError( pht( 'The external service ("%s") you just authenticated with is '. 'not configured to allow logins on this server. An '. 'administrator may have recently disabled it.', $provider->getProviderName())); } } else if ($viewer->getPHID() == $account->getUserPHID()) { // This is either an attempt to re-link an existing and already // linked account (which is silly) or a refresh of an external account // (e.g., an OAuth account). return id(new AphrontRedirectResponse()) ->setURI('/settings/panel/external/'); } else { return $this->renderError( pht( 'The external service ("%s") you just used to log in is already '. 'associated with another %s user account. Log in to the '. 'other %s account and unlink the external account before '. 'linking it to a new %s account.', $provider->getProviderName(), PlatformSymbols::getPlatformServerName(), PlatformSymbols::getPlatformServerName(), PlatformSymbols::getPlatformServerName())); } } else { // The account is not yet attached to a Phabricator user, so this is // either a registration or an account link request. if (!$viewer->isLoggedIn()) { if ($provider->shouldAllowRegistration() || $invite) { return $this->processRegisterUser($account); } else { return $this->renderError( pht( 'The external service ("%s") you just authenticated with is '. 'not configured to allow registration on this server. An '. 'administrator may have recently disabled it.', $provider->getProviderName())); } } else { // If the user already has a linked account on this provider, prevent // them from linking a second account. This can happen if they swap // logins and then refresh the account link. // There's no technical reason we can't allow you to link multiple // accounts from a single provider; disallowing this is currently a // product deciison. See T2549. $existing_accounts = id(new PhabricatorExternalAccountQuery()) ->setViewer($viewer) ->withUserPHIDs(array($viewer->getPHID())) ->withProviderConfigPHIDs( array( $provider->getProviderConfigPHID(), )) ->execute(); if ($existing_accounts) { return $this->renderError( pht( 'Your %s account is already connected to an external '. 'account on this service ("%s"), but you are currently logged '. 'in to the service with a different account. Log out of the '. 'external service, then log back in with the correct account '. 'before refreshing the account link.', PlatformSymbols::getPlatformServerName(), $provider->getProviderName())); } if ($provider->shouldAllowAccountLink()) { return $this->processLinkUser($account); } else { return $this->renderError( pht( 'The external service ("%s") you just authenticated with is '. 'not configured to allow account linking on this server. An '. 'administrator may have recently disabled it.', $provider->getProviderName())); } } } // This should be unreachable, but fail explicitly if we get here somehow. return new Aphront400Response(); } private function processLoginUser(PhabricatorExternalAccount $account) { $user = id(new PhabricatorUser())->loadOneWhere( 'phid = %s', $account->getUserPHID()); if (!$user) { return $this->renderError( pht( 'The external account you just logged in with is not associated '. 'with a valid %s user account.', PlatformSymbols::getPlatformServerName())); } return $this->loginUser($user); } private function processRegisterUser(PhabricatorExternalAccount $account) { $account_secret = $account->getAccountSecret(); $register_uri = $this->getApplicationURI('register/'.$account_secret.'/'); return $this->setAccountKeyAndContinue($account, $register_uri); } private function processLinkUser(PhabricatorExternalAccount $account) { $account_secret = $account->getAccountSecret(); $confirm_uri = $this->getApplicationURI('confirmlink/'.$account_secret.'/'); return $this->setAccountKeyAndContinue($account, $confirm_uri); } private function setAccountKeyAndContinue( PhabricatorExternalAccount $account, $next_uri) { if ($account->getUserPHID()) { throw new Exception(pht('Account is already registered or linked.')); } // Regenerate the registration secret key, set it on the external account, // set a cookie on the user's machine, and redirect them to registration. // See PhabricatorAuthRegisterController for discussion of the registration // key. $registration_key = Filesystem::readRandomCharacters(32); $account->setProperty( 'registrationKey', PhabricatorHash::weakDigest($registration_key)); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $account->save(); unset($unguarded); $this->getRequest()->setTemporaryCookie( PhabricatorCookies::COOKIE_REGISTRATION, $registration_key); return id(new AphrontRedirectResponse())->setURI($next_uri); } private function loadProvider() { $provider = PhabricatorAuthProvider::getEnabledProviderByKey( $this->providerKey); if (!$provider) { return $this->renderError( pht( 'The account you are attempting to log in with uses a nonexistent '. 'or disabled authentication provider (with key "%s"). An '. 'administrator may have recently disabled this provider.', $this->providerKey)); } $this->provider = $provider; return null; } protected function renderError($message) { return $this->renderErrorPage( pht('Login Failed'), array($message)); } public function buildProviderPageResponse( PhabricatorAuthProvider $provider, $content) { $crumbs = $this->buildApplicationCrumbs(); $viewer = $this->getViewer(); if ($viewer->isLoggedIn()) { $crumbs->addTextCrumb(pht('Link Account'), $provider->getSettingsURI()); } else { $crumbs->addTextCrumb(pht('Login'), $this->getApplicationURI('start/')); $content = array( $this->newCustomStartMessage(), $content, ); } $crumbs->addTextCrumb($provider->getProviderName()); $crumbs->setBorder(true); return $this->newPage() ->setTitle(pht('Login')) ->setCrumbs($crumbs) ->appendChild($content); } public function buildProviderErrorResponse( PhabricatorAuthProvider $provider, $message) { $message = pht( 'Authentication provider ("%s") encountered an error while attempting '. 'to log in. %s', $provider->getProviderName(), $message); return $this->renderError($message); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorRefreshCSRFController.php
src/applications/auth/controller/PhabricatorRefreshCSRFController.php
<?php final class PhabricatorRefreshCSRFController extends PhabricatorAuthController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); return id(new AphrontAjaxResponse()) ->setContent( array( 'token' => $viewer->getCSRFToken(), )); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthOneTimeLoginController.php
src/applications/auth/controller/PhabricatorAuthOneTimeLoginController.php
<?php final class PhabricatorAuthOneTimeLoginController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); $link_type = $request->getURIData('type'); $key = $request->getURIData('key'); $email_id = $request->getURIData('emailID'); $target_user = id(new PhabricatorPeopleQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withIDs(array($id)) ->executeOne(); if (!$target_user) { return new Aphront404Response(); } // NOTE: We allow you to use a one-time login link for your own current // login account. This supports the "Set Password" flow. $is_logged_in = false; if ($viewer->isLoggedIn()) { if ($viewer->getPHID() !== $target_user->getPHID()) { return $this->renderError( pht('You are already logged in.')); } else { $is_logged_in = true; } } // NOTE: As a convenience to users, these one-time login URIs may also // be associated with an email address which will be verified when the // URI is used. // This improves the new user experience for users receiving "Welcome" // emails on installs that require verification: if we did not verify the // email, they'd immediately get roadblocked with a "Verify Your Email" // error and have to go back to their email account, wait for a // "Verification" email, and then click that link to actually get access to // their account. This is hugely unwieldy, and if the link was only sent // to the user's email in the first place we can safely verify it as a // side effect of login. // The email hashed into the URI so users can't verify some email they // do not own by doing this: // // - Add some address you do not own; // - request a password reset; // - change the URI in the email to the address you don't own; // - login via the email link; and // - get a "verified" address you don't control. $target_email = null; if ($email_id) { $target_email = id(new PhabricatorUserEmail())->loadOneWhere( 'userPHID = %s AND id = %d', $target_user->getPHID(), $email_id); if (!$target_email) { return new Aphront404Response(); } } $engine = new PhabricatorAuthSessionEngine(); $token = $engine->loadOneTimeLoginKey( $target_user, $target_email, $key); if (!$token) { return $this->newDialog() ->setTitle(pht('Unable to Log In')) ->setShortTitle(pht('Login Failure')) ->appendParagraph( pht( 'The login link you clicked is invalid, out of date, or has '. 'already been used.')) ->appendParagraph( pht( 'Make sure you are copy-and-pasting the entire link into '. 'your browser. Login links are only valid for 24 hours, and '. 'can only be used once.')) ->appendParagraph( pht('You can try again, or request a new link via email.')) ->addCancelButton('/login/email/', pht('Send Another Email')); } if (!$target_user->canEstablishWebSessions()) { return $this->newDialog() ->setTitle(pht('Unable to Establish Web Session')) ->setShortTitle(pht('Login Failure')) ->appendParagraph( pht( 'You are trying to gain access to an account ("%s") that can not '. 'establish a web session.', $target_user->getUsername())) ->appendParagraph( pht( 'Special users like daemons and mailing lists are not permitted '. 'to log in via the web. Log in as a normal user instead.')) ->addCancelButton('/'); } if ($request->isFormPost() || $is_logged_in) { // If we have an email bound into this URI, verify email so that clicking // the link in the "Welcome" email is good enough, without requiring users // to go through a second round of email verification. $editor = id(new PhabricatorUserEditor()) ->setActor($target_user); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); // Nuke the token and all other outstanding password reset tokens. // There is no particular security benefit to destroying them all, but // it should reduce HackerOne reports of nebulous harm. $editor->revokePasswordResetLinks($target_user); if ($target_email) { $editor->verifyEmail($target_user, $target_email); } unset($unguarded); $next_uri = $this->getNextStepURI($target_user); // If the user is already logged in, we're just doing a "password set" // flow. Skip directly to the next step. if ($is_logged_in) { return id(new AphrontRedirectResponse())->setURI($next_uri); } PhabricatorCookies::setNextURICookie($request, $next_uri, $force = true); $force_full_session = false; if ($link_type === PhabricatorAuthSessionEngine::ONETIME_RECOVER) { $force_full_session = $token->getShouldForceFullSession(); } return $this->loginUser($target_user, $force_full_session); } // NOTE: We need to CSRF here so attackers can't generate an email link, // then log a user in to an account they control via sneaky invisible // form submissions. switch ($link_type) { case PhabricatorAuthSessionEngine::ONETIME_WELCOME: $title = pht( 'Welcome to %s', PlatformSymbols::getPlatformServerName()); break; case PhabricatorAuthSessionEngine::ONETIME_RECOVER: $title = pht('Account Recovery'); break; case PhabricatorAuthSessionEngine::ONETIME_USERNAME: case PhabricatorAuthSessionEngine::ONETIME_RESET: default: $title = pht( 'Log in to %s', PlatformSymbols::getPlatformServerName()); break; } $body = array(); $body[] = pht( 'Use the button below to log in as: %s', phutil_tag('strong', array(), $target_user->getUsername())); if ($target_email && !$target_email->getIsVerified()) { $body[] = pht( 'Logging in will verify %s as an email address you own.', phutil_tag('strong', array(), $target_email->getAddress())); } $body[] = pht( 'After logging in you should set a password for your account, or '. 'link your account to an external account that you can use to '. 'authenticate in the future.'); $dialog = $this->newDialog() ->setTitle($title) ->addSubmitButton(pht('Log In (%s)', $target_user->getUsername())) ->addCancelButton('/'); foreach ($body as $paragraph) { $dialog->appendParagraph($paragraph); } return id(new AphrontDialogResponse())->setDialog($dialog); } private function getNextStepURI(PhabricatorUser $user) { $request = $this->getRequest(); // If we have password auth, let the user set or reset their password after // login. $have_passwords = PhabricatorPasswordAuthProvider::getPasswordProvider(); if ($have_passwords) { // We're going to let the user reset their password without knowing // the old one. Generate a one-time token for that. $key = Filesystem::readRandomCharacters(16); $password_type = PhabricatorAuthPasswordResetTemporaryTokenType::TOKENTYPE; $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); id(new PhabricatorAuthTemporaryToken()) ->setTokenResource($user->getPHID()) ->setTokenType($password_type) ->setTokenExpires(time() + phutil_units('1 hour in seconds')) ->setTokenCode(PhabricatorHash::weakDigest($key)) ->save(); unset($unguarded); $panel_uri = '/auth/password/'; $request->setTemporaryCookie(PhabricatorCookies::COOKIE_HISEC, 'yes'); $params = array( 'key' => $key, ); return (string)new PhutilURI($panel_uri, $params); } // Check if the user already has external accounts linked. If they do, // it's not obvious why they aren't using them to log in, but assume they // know what they're doing. We won't send them to the link workflow. $accounts = id(new PhabricatorExternalAccountQuery()) ->setViewer($user) ->withUserPHIDs(array($user->getPHID())) ->execute(); $configs = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer($user) ->withIsEnabled(true) ->execute(); $linkable = array(); foreach ($configs as $config) { if (!$config->getShouldAllowLink()) { continue; } $provider = $config->getProvider(); if (!$provider->isLoginFormAButton()) { continue; } $linkable[] = $provider; } // If there's at least one linkable provider, and the user doesn't already // have accounts, send the user to the link workflow. if (!$accounts && $linkable) { return '/auth/external/'; } // If there are no configured providers and the user is an administrator, // send them to Auth to configure a provider. This is probably where they // want to go. You can end up in this state by accidentally losing your // first session during initial setup, or after restoring exported data // from a hosted instance. if (!$configs && $user->getIsAdmin()) { return '/auth/'; } // If we didn't find anywhere better to send them, give up and just send // them to the home page. return '/'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthSSHKeyController.php
src/applications/auth/controller/PhabricatorAuthSSHKeyController.php
<?php abstract class PhabricatorAuthSSHKeyController extends PhabricatorAuthController { private $keyObject; public function setSSHKeyObject(PhabricatorSSHPublicKeyInterface $object) { $this->keyObject = $object; return $this; } public function getSSHKeyObject() { return $this->keyObject; } protected function loadSSHKeyObject($object_phid, $need_edit) { $viewer = $this->getViewer(); $query = id(new PhabricatorObjectQuery()) ->setViewer($viewer) ->withPHIDs(array($object_phid)); if ($need_edit) { $query->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )); } $object = $query->executeOne(); if (!$object) { return null; } // If this kind of object can't have SSH keys, don't let the viewer // add them. if (!($object instanceof PhabricatorSSHPublicKeyInterface)) { return null; } $this->keyObject = $object; return $object; } protected function newKeyForObjectPHID($object_phid) { $viewer = $this->getViewer(); $object = $this->loadSSHKeyObject($object_phid, true); if (!$object) { return null; } return PhabricatorAuthSSHKey::initializeNewSSHKey($viewer, $object); } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $viewer = $this->getViewer(); $key_object = $this->getSSHKeyObject(); if ($key_object) { $object_phid = $key_object->getPHID(); $handles = $viewer->loadHandles(array($object_phid)); $handle = $handles[$object_phid]; $uri = $key_object->getSSHPublicKeyManagementURI($viewer); $crumbs->addTextCrumb($handle->getObjectName(), $uri); } return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorDisabledUserController.php
src/applications/auth/controller/PhabricatorDisabledUserController.php
<?php final class PhabricatorDisabledUserController extends PhabricatorAuthController { public function shouldRequireEnabledUser() { return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); if (!$viewer->getIsDisabled()) { return new Aphront404Response(); } return $this->newDialog() ->setTitle(pht('Account Disabled')) ->addCancelButton('/logout/', pht('Okay')) ->appendParagraph(pht('Your account has been disabled.')); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthValidateController.php
src/applications/auth/controller/PhabricatorAuthValidateController.php
<?php final class PhabricatorAuthValidateController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function shouldAllowPartialSessions() { return true; } public function shouldAllowLegallyNonCompliantUsers() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $failures = array(); if (!strlen($request->getStr('expect'))) { return $this->renderErrors( array( pht( 'Login validation is missing expected parameter ("%s").', 'phusr'), )); } $expect_phusr = $request->getStr('expect'); $actual_phusr = $request->getCookie(PhabricatorCookies::COOKIE_USERNAME); if ($actual_phusr != $expect_phusr) { if ($actual_phusr) { $failures[] = pht( "Attempted to set '%s' cookie to '%s', but your browser sent back ". "a cookie with the value '%s'. Clear your browser's cookies and ". "try again.", 'phusr', $expect_phusr, $actual_phusr); } else { $failures[] = pht( "Attempted to set '%s' cookie to '%s', but your browser did not ". "accept the cookie. Check that cookies are enabled, clear them, ". "and try again.", 'phusr', $expect_phusr); } } if (!$failures) { if (!$viewer->getPHID()) { $failures[] = pht( 'Login cookie was set correctly, but your login session is not '. 'valid. Try clearing cookies and logging in again.'); } } if ($failures) { return $this->renderErrors($failures); } $finish_uri = $this->getApplicationURI('finish/'); return id(new AphrontRedirectResponse())->setURI($finish_uri); } private function renderErrors(array $messages) { return $this->renderErrorPage( pht('Login Failure'), $messages); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthRegisterController.php
src/applications/auth/controller/PhabricatorAuthRegisterController.php
<?php final class PhabricatorAuthRegisterController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $account_key = $request->getURIData('akey'); if ($viewer->isLoggedIn()) { return id(new AphrontRedirectResponse())->setURI('/'); } $invite = $this->loadInvite(); $is_setup = false; if ($account_key !== null && strlen($account_key)) { $result = $this->loadAccountForRegistrationOrLinking($account_key); list($account, $provider, $response) = $result; $is_default = false; } else if ($this->isFirstTimeSetup()) { $account = null; $provider = null; $response = null; $is_default = true; $is_setup = true; } else { list($account, $provider, $response) = $this->loadDefaultAccount($invite); $is_default = true; } if ($response) { return $response; } if (!$is_setup) { if (!$provider->shouldAllowRegistration()) { if ($invite) { // If the user has an invite, we allow them to register with any // provider, even a login-only provider. } else { // TODO: This is a routine error if you click "Login" on an external // auth source which doesn't allow registration. The error should be // more tailored. return $this->renderError( pht( 'The account you are attempting to register with uses an '. 'authentication provider ("%s") which does not allow '. 'registration. An administrator may have recently disabled '. 'registration with this provider.', $provider->getProviderName())); } } } $errors = array(); $user = new PhabricatorUser(); if ($is_setup) { $default_username = null; $default_realname = null; $default_email = null; } else { $default_username = $account->getUsername(); $default_realname = $account->getRealName(); $default_email = $account->getEmail(); } $account_type = PhabricatorAuthPassword::PASSWORD_TYPE_ACCOUNT; $content_source = PhabricatorContentSource::newFromRequest($request); if ($invite) { $default_email = $invite->getEmailAddress(); } if ($default_email !== null) { if (!PhabricatorUserEmail::isValidAddress($default_email)) { $errors[] = pht( 'The email address associated with this external account ("%s") is '. 'not a valid email address and can not be used to register an '. 'account. Choose a different, valid address.', phutil_tag('strong', array(), $default_email)); $default_email = null; } } if ($default_email !== null) { // We should bypass policy here because e.g. limiting an application use // to a subset of users should not allow the others to overwrite // configured application emails. $application_email = id(new PhabricatorMetaMTAApplicationEmailQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withAddresses(array($default_email)) ->executeOne(); if ($application_email) { $errors[] = pht( 'The email address associated with this account ("%s") is '. 'already in use by an application and can not be used to '. 'register a new account. Choose a different, valid address.', phutil_tag('strong', array(), $default_email)); $default_email = null; } } $show_existing = null; if ($default_email !== null) { // If the account source provided an email, but it's not allowed by // the configuration, roadblock the user. Previously, we let the user // pick a valid email address instead, but this does not align well with // user expectation and it's not clear the cases it enables are valuable. // See discussion in T3472. if (!PhabricatorUserEmail::isAllowedAddress($default_email)) { $debug_email = new PHUIInvisibleCharacterView($default_email); return $this->renderError( array( pht( 'The account you are attempting to register with has an invalid '. 'email address (%s). This server only allows registration with '. 'specific email addresses:', $debug_email), phutil_tag('br'), phutil_tag('br'), PhabricatorUserEmail::describeAllowedAddresses(), )); } // If the account source provided an email, but another account already // has that email, just pretend we didn't get an email. if ($default_email !== null) { $same_email = id(new PhabricatorUserEmail())->loadOneWhere( 'address = %s', $default_email); if ($same_email) { if ($invite) { // We're allowing this to continue. The fact that we loaded the // invite means that the address is nonprimary and unverified and // we're OK to steal it. } else { $show_existing = $default_email; $default_email = null; } } } } if ($show_existing !== null) { if (!$request->getInt('phase')) { return $this->newDialog() ->setTitle(pht('Email Address Already in Use')) ->addHiddenInput('phase', 1) ->appendParagraph( pht( 'You are creating a new account linked to an existing '. 'external account.')) ->appendParagraph( pht( 'The email address ("%s") associated with the external account '. 'is already in use by an existing %s account. Multiple '. '%s accounts may not have the same email address, so '. 'you can not use this email address to register a new account.', phutil_tag('strong', array(), $show_existing), PlatformSymbols::getPlatformServerName(), PlatformSymbols::getPlatformServerName())) ->appendParagraph( pht( 'If you want to register a new account, continue with this '. 'registration workflow and choose a new, unique email address '. 'for the new account.')) ->appendParagraph( pht( 'If you want to link an existing %s account to this '. 'external account, do not continue. Instead: log in to your '. 'existing account, then go to "Settings" and link the account '. 'in the "External Accounts" panel.', PlatformSymbols::getPlatformServerName())) ->appendParagraph( pht( 'If you continue, you will create a new account. You will not '. 'be able to link this external account to an existing account.')) ->addCancelButton('/auth/login/', pht('Cancel')) ->addSubmitButton(pht('Create New Account')); } else { $errors[] = pht( 'The external account you are registering with has an email address '. 'that is already in use ("%s") by an existing %s account. '. 'Choose a new, valid email address to register a new account.', phutil_tag('strong', array(), $show_existing), PlatformSymbols::getPlatformServerName()); } } $profile = id(new PhabricatorRegistrationProfile()) ->setDefaultUsername($default_username) ->setDefaultEmail($default_email) ->setDefaultRealName($default_realname) ->setCanEditUsername(true) ->setCanEditEmail(($default_email === null)) ->setCanEditRealName(true) ->setShouldVerifyEmail(false); $event_type = PhabricatorEventType::TYPE_AUTH_WILLREGISTERUSER; $event_data = array( 'account' => $account, 'profile' => $profile, ); $event = id(new PhabricatorEvent($event_type, $event_data)) ->setUser($user); PhutilEventEngine::dispatchEvent($event); $default_username = $profile->getDefaultUsername(); $default_email = $profile->getDefaultEmail(); $default_realname = $profile->getDefaultRealName(); $can_edit_username = $profile->getCanEditUsername(); $can_edit_email = $profile->getCanEditEmail(); $can_edit_realname = $profile->getCanEditRealName(); if ($is_setup) { $must_set_password = false; } else { $must_set_password = $provider->shouldRequireRegistrationPassword(); } $can_edit_anything = $profile->getCanEditAnything() || $must_set_password; $force_verify = $profile->getShouldVerifyEmail(); // Automatically verify the administrator's email address during first-time // setup. if ($is_setup) { $force_verify = true; } $value_username = $default_username; $value_realname = $default_realname; $value_email = $default_email; $value_password = null; $require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name'); $e_username = phutil_nonempty_string($value_username) ? null : true; $e_realname = $require_real_name ? true : null; $e_email = phutil_nonempty_string($value_email) ? null : true; $e_password = true; $e_captcha = true; $skip_captcha = false; if ($invite) { // If the user is accepting an invite, assume they're trustworthy enough // that we don't need to CAPTCHA them. $skip_captcha = true; } $min_len = PhabricatorEnv::getEnvConfig('account.minimum-password-length'); $min_len = (int)$min_len; $from_invite = $request->getStr('invite'); if ($from_invite && $can_edit_username) { $value_username = $request->getStr('username'); $e_username = null; } $try_register = ($request->isFormPost() || !$can_edit_anything) && !$from_invite && ($request->getInt('phase') != 1); if ($try_register) { $errors = array(); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); if ($must_set_password && !$skip_captcha) { $e_captcha = pht('Again'); $captcha_ok = AphrontFormRecaptchaControl::processCaptcha($request); if (!$captcha_ok) { $errors[] = pht('Captcha response is incorrect, try again.'); $e_captcha = pht('Invalid'); } } if ($can_edit_username) { $value_username = $request->getStr('username'); if (!phutil_nonempty_string($value_username)) { $e_username = pht('Required'); $errors[] = pht('Username is required.'); } else if (!PhabricatorUser::validateUsername($value_username)) { $e_username = pht('Invalid'); $errors[] = PhabricatorUser::describeValidUsername(); } else { $e_username = null; } } if ($must_set_password) { $value_password = $request->getStr('password'); $value_confirm = $request->getStr('confirm'); $password_envelope = new PhutilOpaqueEnvelope($value_password); $confirm_envelope = new PhutilOpaqueEnvelope($value_confirm); $engine = id(new PhabricatorAuthPasswordEngine()) ->setViewer($user) ->setContentSource($content_source) ->setPasswordType($account_type) ->setObject($user); try { $engine->checkNewPassword($password_envelope, $confirm_envelope); $e_password = null; } catch (PhabricatorAuthPasswordException $ex) { $errors[] = $ex->getMessage(); $e_password = $ex->getPasswordError(); } } if ($can_edit_email) { $value_email = $request->getStr('email'); if (!phutil_nonempty_string($value_email)) { $e_email = pht('Required'); $errors[] = pht('Email is required.'); } else if (!PhabricatorUserEmail::isValidAddress($value_email)) { $e_email = pht('Invalid'); $errors[] = PhabricatorUserEmail::describeValidAddresses(); } else if (!PhabricatorUserEmail::isAllowedAddress($value_email)) { $e_email = pht('Disallowed'); $errors[] = PhabricatorUserEmail::describeAllowedAddresses(); } else { $e_email = null; } } if ($can_edit_realname) { $value_realname = $request->getStr('realName'); if (!phutil_nonempty_string($value_realname) && $require_real_name) { $e_realname = pht('Required'); $errors[] = pht('Real name is required.'); } else { $e_realname = null; } } if (!$errors) { if (!$is_setup) { $image = $this->loadProfilePicture($account); if ($image) { $user->setProfileImagePHID($image->getPHID()); } } try { $verify_email = false; if ($force_verify) { $verify_email = true; } if (!$is_setup) { if ($value_email === $default_email) { if ($account->getEmailVerified()) { $verify_email = true; } if ($provider->shouldTrustEmails()) { $verify_email = true; } if ($invite) { $verify_email = true; } } } $email_obj = null; if ($invite) { // If we have a valid invite, this email may exist but be // nonprimary and unverified, so we'll reassign it. $email_obj = id(new PhabricatorUserEmail())->loadOneWhere( 'address = %s', $value_email); } if (!$email_obj) { $email_obj = id(new PhabricatorUserEmail()) ->setAddress($value_email); } $email_obj->setIsVerified((int)$verify_email); $user->setUsername($value_username); $user->setRealname($value_realname); if ($is_setup) { $must_approve = false; } else if ($invite) { $must_approve = false; } else { $must_approve = PhabricatorEnv::getEnvConfig( 'auth.require-approval'); } if ($must_approve) { $user->setIsApproved(0); } else { $user->setIsApproved(1); } if ($invite) { $allow_reassign_email = true; } else { $allow_reassign_email = false; } $user->openTransaction(); $editor = id(new PhabricatorUserEditor()) ->setActor($user); $editor->createNewUser($user, $email_obj, $allow_reassign_email); if ($must_set_password) { $password_object = PhabricatorAuthPassword::initializeNewPassword( $user, $account_type); $password_object ->setPassword($password_envelope, $user) ->save(); } if ($is_setup) { $xactions = array(); $xactions[] = id(new PhabricatorUserTransaction()) ->setTransactionType( PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE) ->setNewValue(true); $actor = PhabricatorUser::getOmnipotentUser(); $content_source = PhabricatorContentSource::newFromRequest( $request); $people_application_phid = id(new PhabricatorPeopleApplication()) ->getPHID(); $transaction_editor = id(new PhabricatorUserTransactionEditor()) ->setActor($actor) ->setActingAsPHID($people_application_phid) ->setContentSource($content_source) ->setContinueOnMissingFields(true); $transaction_editor->applyTransactions($user, $xactions); } if (!$is_setup) { $account->setUserPHID($user->getPHID()); $account->save(); } $user->saveTransaction(); if (!$email_obj->getIsVerified()) { $email_obj->sendVerificationEmail($user); } if ($must_approve) { $this->sendWaitingForApprovalEmail($user); } if ($invite) { $invite->setAcceptedByPHID($user->getPHID())->save(); } return $this->loginUser($user); } catch (AphrontDuplicateKeyQueryException $exception) { $same_username = id(new PhabricatorUser())->loadOneWhere( 'userName = %s', $user->getUserName()); $same_email = id(new PhabricatorUserEmail())->loadOneWhere( 'address = %s', $value_email); if ($same_username) { $e_username = pht('Duplicate'); $errors[] = pht('Another user already has that username.'); } if ($same_email) { // TODO: See T3340. $e_email = pht('Duplicate'); $errors[] = pht('Another user already has that email.'); } if (!$same_username && !$same_email) { throw $exception; } } } unset($unguarded); } $form = id(new AphrontFormView()) ->setUser($request->getUser()) ->addHiddenInput('phase', 2); if (!$is_default) { $form->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('External Account')) ->setValue( id(new PhabricatorAuthAccountView()) ->setUser($request->getUser()) ->setExternalAccount($account) ->setAuthProvider($provider))); } if ($can_edit_username) { $form->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Username')) ->setName('username') ->setValue($value_username) ->setError($e_username)); } else { $form->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('Username')) ->setValue($value_username) ->setError($e_username)); } if ($can_edit_realname) { $form->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Real Name')) ->setName('realName') ->setValue($value_realname) ->setError($e_realname)); } if ($must_set_password) { $form->appendChild( id(new AphrontFormPasswordControl()) ->setLabel(pht('Password')) ->setName('password') ->setError($e_password)); $form->appendChild( id(new AphrontFormPasswordControl()) ->setLabel(pht('Confirm Password')) ->setName('confirm') ->setError($e_password) ->setCaption( $min_len ? pht('Minimum length of %d characters.', $min_len) : null)); } if ($can_edit_email) { $form->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Email')) ->setName('email') ->setValue($value_email) ->setCaption(PhabricatorUserEmail::describeAllowedAddresses()) ->setError($e_email)); } if ($must_set_password && !$skip_captcha) { $form->appendChild( id(new AphrontFormRecaptchaControl()) ->setLabel(pht('Captcha')) ->setError($e_captcha)); } $submit = id(new AphrontFormSubmitControl()); if ($is_setup) { $submit ->setValue(pht('Create Admin Account')); } else { $submit ->addCancelButton($this->getApplicationURI('start/')) ->setValue(pht('Register Account')); } $form->appendChild($submit); $crumbs = $this->buildApplicationCrumbs(); if ($is_setup) { $crumbs->addTextCrumb(pht('Setup Admin Account')); $title = pht( 'Welcome to %s', PlatformSymbols::getPlatformServerName()); } else { $crumbs->addTextCrumb(pht('Register')); $crumbs->addTextCrumb($provider->getProviderName()); $title = pht('Create a New Account'); } $crumbs->setBorder(true); $welcome_view = null; if ($is_setup) { $welcome_view = id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) ->setTitle( pht( 'Welcome to %s', PlatformSymbols::getPlatformServerName())) ->appendChild( pht( 'Installation is complete. Register your administrator account '. 'below to log in. You will be able to configure options and add '. 'authentication mechanisms later on.')); } $object_box = id(new PHUIObjectBoxView()) ->setForm($form) ->setFormErrors($errors); $invite_header = null; if ($invite) { $invite_header = $this->renderInviteHeader($invite); } $header = id(new PHUIHeaderView()) ->setHeader($title); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter( array( $welcome_view, $invite_header, $object_box, )); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($view); } private function loadDefaultAccount($invite) { $providers = PhabricatorAuthProvider::getAllEnabledProviders(); $account = null; $provider = null; $response = null; foreach ($providers as $key => $candidate_provider) { if (!$invite) { if (!$candidate_provider->shouldAllowRegistration()) { unset($providers[$key]); continue; } } if (!$candidate_provider->isDefaultRegistrationProvider()) { unset($providers[$key]); } } if (!$providers) { $response = $this->renderError( pht( 'There are no configured default registration providers.')); return array($account, $provider, $response); } else if (count($providers) > 1) { $response = $this->renderError( pht('There are too many configured default registration providers.')); return array($account, $provider, $response); } $provider = head($providers); $account = $provider->newDefaultExternalAccount(); return array($account, $provider, $response); } private function loadProfilePicture(PhabricatorExternalAccount $account) { $phid = $account->getProfileImagePHID(); if (!$phid) { return null; } // NOTE: Use of omnipotent user is okay here because the registering user // can not control the field value, and we can't use their user object to // do meaningful policy checks anyway since they have not registered yet. // Reaching this means the user holds the account secret key and the // registration secret key, and thus has permission to view the image. $file = id(new PhabricatorFileQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withPHIDs(array($phid)) ->executeOne(); if (!$file) { return null; } $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); return $xform->executeTransform($file); } protected function renderError($message) { return $this->renderErrorPage( pht('Registration Failed'), array($message)); } private function sendWaitingForApprovalEmail(PhabricatorUser $user) { $title = pht( '[%s] New User "%s" Awaiting Approval', PlatformSymbols::getPlatformServerName(), $user->getUsername()); $body = new PhabricatorMetaMTAMailBody(); $body->addRawSection( pht( 'Newly registered user "%s" is awaiting account approval by an '. 'administrator.', $user->getUsername())); $body->addLinkSection( pht('APPROVAL QUEUE'), PhabricatorEnv::getProductionURI( '/people/query/approval/')); $body->addLinkSection( pht('DISABLE APPROVAL QUEUE'), PhabricatorEnv::getProductionURI( '/config/edit/auth.require-approval/')); $admins = id(new PhabricatorPeopleQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withIsAdmin(true) ->execute(); if (!$admins) { return; } $mail = id(new PhabricatorMetaMTAMail()) ->addTos(mpull($admins, 'getPHID')) ->setSubject($title) ->setBody($body->render()) ->saveAndSend(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php
src/applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php
<?php final class PhabricatorAuthSSHKeyGenerateController extends PhabricatorAuthSSHKeyController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $key = $this->newKeyForObjectPHID($request->getStr('objectPHID')); if (!$key) { return new Aphront404Response(); } $cancel_uri = $key->getObject()->getSSHPublicKeyManagementURI($viewer); $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( $viewer, $request, $cancel_uri); if ($request->isFormPost()) { $default_name = $key->getObject()->getSSHKeyDefaultName(); $keys = PhabricatorSSHKeyGenerator::generateKeypair(); list($public_key, $private_key) = $keys; $key_name = $default_name.'.key'; $file = PhabricatorFile::newFromFileData( $private_key, array( 'name' => $key_name, 'ttl.relative' => phutil_units('10 minutes in seconds'), 'viewPolicy' => $viewer->getPHID(), )); $public_key = PhabricatorAuthSSHPublicKey::newFromRawKey($public_key); $type = $public_key->getType(); $body = $public_key->getBody(); $comment = pht('Generated'); $entire_key = "{$type} {$body} {$comment}"; $type_create = PhabricatorTransactions::TYPE_CREATE; $type_name = PhabricatorAuthSSHKeyTransaction::TYPE_NAME; $type_key = PhabricatorAuthSSHKeyTransaction::TYPE_KEY; $xactions = array(); $xactions[] = id(new PhabricatorAuthSSHKeyTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_CREATE); $xactions[] = id(new PhabricatorAuthSSHKeyTransaction()) ->setTransactionType($type_name) ->setNewValue($default_name); $xactions[] = id(new PhabricatorAuthSSHKeyTransaction()) ->setTransactionType($type_key) ->setNewValue($entire_key); $editor = id(new PhabricatorAuthSSHKeyEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->applyTransactions($key, $xactions); $download_link = phutil_tag( 'a', array( 'href' => $file->getDownloadURI(), ), array( id(new PHUIIconView())->setIcon('fa-download'), ' ', pht('Download Private Key (%s)', $key_name), )); $download_link = phutil_tag('strong', array(), $download_link); // NOTE: We're disabling workflow on cancel so the page reloads, showing // the new key. return $this->newDialog() ->setTitle(pht('Download Private Key')) ->appendParagraph( pht( 'A keypair has been generated, and the public key has been '. 'added as a recognized key.')) ->appendParagraph($download_link) ->appendParagraph( pht( 'After you download the private key, it will be destroyed. '. 'You will not be able to retrieve it if you lose your copy.')) ->setDisableWorkflowOnCancel(true) ->addCancelButton($cancel_uri, pht('Done')); } try { PhabricatorSSHKeyGenerator::assertCanGenerateKeypair(); return $this->newDialog() ->setTitle(pht('Generate New Keypair')) ->addHiddenInput('objectPHID', $key->getObject()->getPHID()) ->appendParagraph( pht( 'This workflow will generate a new SSH keypair, add the public '. 'key, and let you download the private key.')) ->appendParagraph( pht('The private key will not be retained.')) ->addSubmitButton(pht('Generate New Keypair')) ->addCancelButton($cancel_uri); } catch (Exception $ex) { return $this->newDialog() ->setTitle(pht('Unable to Generate Keys')) ->appendParagraph($ex->getMessage()) ->addCancelButton($cancel_uri); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthNeedsApprovalController.php
src/applications/auth/controller/PhabricatorAuthNeedsApprovalController.php
<?php final class PhabricatorAuthNeedsApprovalController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function shouldRequireEmailVerification() { return false; } public function shouldRequireEnabledUser() { return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $instructions = $this->newCustomWaitForApprovalInstructions(); $wait_for_approval = pht( "Your account has been created, but needs to be approved by an ". "administrator. You'll receive an email once your account is approved."); $dialog = $this->newDialog() ->setTitle(pht('Wait for Approval')) ->appendChild($wait_for_approval) ->addCancelButton('/', pht('Wait Patiently')); $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb(pht('Wait For Approval')) ->setBorder(true); return $this->newPage() ->setTitle(pht('Wait For Approval')) ->setCrumbs($crumbs) ->appendChild( array( $instructions, $dialog, )); } private function newCustomWaitForApprovalInstructions() { $viewer = $this->getViewer(); $text = PhabricatorAuthMessage::loadMessageText( $viewer, PhabricatorAuthWaitForApprovalMessageType::MESSAGEKEY); if (!strlen($text)) { return null; } $remarkup_view = new PHUIRemarkupView($viewer, $text); return phutil_tag( 'div', array( 'class' => 'auth-custom-message', ), $remarkup_view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthNeedsMultiFactorController.php
src/applications/auth/controller/PhabricatorAuthNeedsMultiFactorController.php
<?php final class PhabricatorAuthNeedsMultiFactorController extends PhabricatorAuthController { public function shouldRequireMultiFactorEnrollment() { // Users need access to this controller in order to enroll in multi-factor // auth. return false; } public function shouldRequireEnabledUser() { // Users who haven't been approved yet are allowed to enroll in MFA. We'll // kick disabled users out later. return false; } public function shouldRequireEmailVerification() { // Users who haven't verified their email addresses yet can still enroll // in MFA. return false; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); if ($viewer->getIsDisabled()) { // We allowed unapproved and disabled users to hit this controller, but // want to kick out disabled users now. return new Aphront400Response(); } $panels = $this->loadPanels(); $multifactor_key = id(new PhabricatorMultiFactorSettingsPanel()) ->getPanelKey(); $panel_key = $request->getURIData('pageKey'); if (!strlen($panel_key)) { $panel_key = $multifactor_key; } if (!isset($panels[$panel_key])) { return new Aphront404Response(); } $nav = $this->newNavigation(); $nav->selectFilter($panel_key); $panel = $panels[$panel_key]; $viewer->updateMultiFactorEnrollment(); if ($panel_key === $multifactor_key) { $header_text = pht('Add Multi-Factor Auth'); $help = $this->newGuidance(); $panel->setIsEnrollment(true); } else { $header_text = $panel->getPanelName(); $help = null; } $response = $panel ->setController($this) ->setNavigation($nav) ->processRequest($request); if (($response instanceof AphrontResponse) || ($response instanceof AphrontResponseProducerInterface)) { return $response; } $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb(pht('Add Multi-Factor Auth')) ->setBorder(true); $header = id(new PHUIHeaderView()) ->setHeader($header_text); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter( array( $help, $response, )); return $this->newPage() ->setTitle(pht('Add Multi-Factor Authentication')) ->setCrumbs($crumbs) ->setNavigation($nav) ->appendChild($view); } private function loadPanels() { $viewer = $this->getViewer(); $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer); $panels = PhabricatorSettingsPanel::getAllDisplayPanels(); $base_uri = $this->newEnrollBaseURI(); $result = array(); foreach ($panels as $key => $panel) { $panel ->setPreferences($preferences) ->setViewer($viewer) ->setUser($viewer) ->setOverrideURI(urisprintf('%s%s/', $base_uri, $key)); if (!$panel->isEnabled()) { continue; } if (!$panel->isUserPanel()) { continue; } if (!$panel->isMultiFactorEnrollmentPanel()) { continue; } if (!empty($result[$key])) { throw new Exception(pht( "Two settings panels share the same panel key ('%s'): %s, %s.", $key, get_class($panel), get_class($result[$key]))); } $result[$key] = $panel; } return $result; } private function newNavigation() { $viewer = $this->getViewer(); $enroll_uri = $this->newEnrollBaseURI(); $nav = id(new AphrontSideNavFilterView()) ->setBaseURI(new PhutilURI($enroll_uri)); $multifactor_key = id(new PhabricatorMultiFactorSettingsPanel()) ->getPanelKey(); $nav->addFilter( $multifactor_key, pht('Enroll in MFA'), null, 'fa-exclamation-triangle blue'); $panels = $this->loadPanels(); if ($panels) { $nav->addLabel(pht('Settings')); } foreach ($panels as $panel_key => $panel) { if ($panel_key === $multifactor_key) { continue; } $nav->addFilter( $panel->getPanelKey(), $panel->getPanelName(), null, $panel->getPanelMenuIcon()); } return $nav; } private function newEnrollBaseURI() { return $this->getApplicationURI('enroll/'); } private function newGuidance() { $viewer = $this->getViewer(); if ($viewer->getIsEnrolledInMultiFactor()) { $guidance = pht( '{icon check, color="green"} **Setup Complete!**'. "\n\n". 'You have successfully configured multi-factor authentication '. 'for your account.'. "\n\n". 'You can make adjustments from the [[ /settings/ | Settings ]] panel '. 'later.'); return $this->newDialog() ->setTitle(pht('Multi-Factor Authentication Setup Complete')) ->setWidth(AphrontDialogView::WIDTH_FULL) ->appendChild(new PHUIRemarkupView($viewer, $guidance)) ->addCancelButton('/', pht('Continue')); } $views = array(); $messages = array(); $messages[] = pht( 'Before you can use this software, you need to add multi-factor '. 'authentication to your account. Multi-factor authentication helps '. 'secure your account by making it more difficult for attackers to '. 'gain access or take sensitive actions.'); $view = id(new PHUIInfoView()) ->setTitle(pht('Add Multi-Factor Authentication To Your Account')) ->setSeverity(PHUIInfoView::SEVERITY_WARNING) ->setErrors($messages); $views[] = $view; $providers = id(new PhabricatorAuthFactorProviderQuery()) ->setViewer($viewer) ->withStatuses( array( PhabricatorAuthFactorProviderStatus::STATUS_ACTIVE, )) ->execute(); if (!$providers) { $messages = array(); $required_key = 'security.require-multi-factor-auth'; $messages[] = pht( 'This install has the configuration option "%s" enabled, but does '. 'not have any active multifactor providers configured. This means '. 'you are required to add MFA, but are also prevented from doing so. '. 'An administrator must disable "%s" or enable an MFA provider to '. 'allow you to continue.', $required_key, $required_key); $view = id(new PHUIInfoView()) ->setTitle(pht('Multi-Factor Authentication is Misconfigured')) ->setSeverity(PHUIInfoView::SEVERITY_ERROR) ->setErrors($messages); $views[] = $view; } return $views; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthController.php
src/applications/auth/controller/PhabricatorAuthController.php
<?php abstract class PhabricatorAuthController extends PhabricatorController { protected function renderErrorPage($title, array $messages) { $view = new PHUIInfoView(); $view->setTitle($title); $view->setErrors($messages); return $this->newPage() ->setTitle($title) ->appendChild($view); } /** * Returns true if this install is newly setup (i.e., there are no user * accounts yet). In this case, we enter a special mode to permit creation * of the first account form the web UI. */ protected function isFirstTimeSetup() { // If there are any auth providers, this isn't first time setup, even if // we don't have accounts. if (PhabricatorAuthProvider::getAllEnabledProviders()) { return false; } // Otherwise, check if there are any user accounts. If not, we're in first // time setup. $any_users = id(new PhabricatorPeopleQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->setLimit(1) ->execute(); return !$any_users; } /** * Log a user into a web session and return an @{class:AphrontResponse} which * corresponds to continuing the login process. * * Normally, this is a redirect to the validation controller which makes sure * the user's cookies are set. However, event listeners can intercept this * event and do something else if they prefer. * * @param PhabricatorUser User to log the viewer in as. * @param bool True to issue a full session immediately, bypassing MFA. * @return AphrontResponse Response which continues the login process. */ protected function loginUser( PhabricatorUser $user, $force_full_session = false) { $response = $this->buildLoginValidateResponse($user); $session_type = PhabricatorAuthSession::TYPE_WEB; if ($force_full_session) { $partial_session = false; } else { $partial_session = true; } $session_key = id(new PhabricatorAuthSessionEngine()) ->establishSession($session_type, $user->getPHID(), $partial_session); // NOTE: We allow disabled users to login and roadblock them later, so // there's no check for users being disabled here. $request = $this->getRequest(); $request->setCookie( PhabricatorCookies::COOKIE_USERNAME, $user->getUsername()); $request->setCookie( PhabricatorCookies::COOKIE_SESSION, $session_key); $this->clearRegistrationCookies(); return $response; } protected function clearRegistrationCookies() { $request = $this->getRequest(); // Clear the registration key. $request->clearCookie(PhabricatorCookies::COOKIE_REGISTRATION); // Clear the client ID / OAuth state key. $request->clearCookie(PhabricatorCookies::COOKIE_CLIENTID); // Clear the invite cookie. $request->clearCookie(PhabricatorCookies::COOKIE_INVITE); } private function buildLoginValidateResponse(PhabricatorUser $user) { $validate_uri = new PhutilURI($this->getApplicationURI('validate/')); $validate_uri->replaceQueryParam('expect', $user->getUsername()); return id(new AphrontRedirectResponse())->setURI((string)$validate_uri); } protected function renderError($message) { return $this->renderErrorPage( pht('Authentication Error'), array( $message, )); } protected function loadAccountForRegistrationOrLinking($account_key) { $request = $this->getRequest(); $viewer = $request->getUser(); $account = null; $provider = null; $response = null; if (!$account_key) { $response = $this->renderError( pht('Request did not include account key.')); return array($account, $provider, $response); } // NOTE: We're using the omnipotent user because the actual user may not // be logged in yet, and because we want to tailor an error message to // distinguish between "not usable" and "does not exist". We do explicit // checks later on to make sure this account is valid for the intended // operation. This requires edit permission for completeness and consistency // but it won't actually be meaningfully checked because we're using the // omnipotent user. $account = id(new PhabricatorExternalAccountQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withAccountSecrets(array($account_key)) ->needImages(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$account) { $response = $this->renderError(pht('No valid linkable account.')); return array($account, $provider, $response); } if ($account->getUserPHID()) { if ($account->getUserPHID() != $viewer->getPHID()) { $response = $this->renderError( pht( 'The account you are attempting to register or link is already '. 'linked to another user.')); } else { $response = $this->renderError( pht( 'The account you are attempting to link is already linked '. 'to your account.')); } return array($account, $provider, $response); } $registration_key = $request->getCookie( PhabricatorCookies::COOKIE_REGISTRATION); // NOTE: This registration key check is not strictly necessary, because // we're only creating new accounts, not linking existing accounts. It // might be more hassle than it is worth, especially for email. // // The attack this prevents is getting to the registration screen, then // copy/pasting the URL and getting someone else to click it and complete // the process. They end up with an account bound to credentials you // control. This doesn't really let you do anything meaningful, though, // since you could have simply completed the process yourself. if (!$registration_key) { $response = $this->renderError( pht( 'Your browser did not submit a registration key with the request. '. 'You must use the same browser to begin and complete registration. '. 'Check that cookies are enabled and try again.')); return array($account, $provider, $response); } // We store the digest of the key rather than the key itself to prevent a // theoretical attacker with read-only access to the database from // hijacking registration sessions. $actual = $account->getProperty('registrationKey'); $expect = PhabricatorHash::weakDigest($registration_key); if (!phutil_hashes_are_identical($actual, $expect)) { $response = $this->renderError( pht( 'Your browser submitted a different registration key than the one '. 'associated with this account. You may need to clear your cookies.')); return array($account, $provider, $response); } $config = $account->getProviderConfig(); if (!$config->getIsEnabled()) { $response = $this->renderError( pht( 'The account you are attempting to register with uses a disabled '. 'authentication provider ("%s"). An administrator may have '. 'recently disabled this provider.', $config->getDisplayName())); return array($account, $provider, $response); } $provider = $config->getProvider(); return array($account, $provider, null); } protected function loadInvite() { $invite_cookie = PhabricatorCookies::COOKIE_INVITE; $invite_code = $this->getRequest()->getCookie($invite_cookie); if (!$invite_code) { return null; } $engine = id(new PhabricatorAuthInviteEngine()) ->setViewer($this->getViewer()) ->setUserHasConfirmedVerify(true); try { return $engine->processInviteCode($invite_code); } catch (Exception $ex) { // If this fails for any reason, just drop the invite. In normal // circumstances, we gave them a detailed explanation of any error // before they jumped into this workflow. return null; } } protected function renderInviteHeader(PhabricatorAuthInvite $invite) { $viewer = $this->getViewer(); // Since the user hasn't registered yet, they may not be able to see other // user accounts. Load the inviting user with the omnipotent viewer. $omnipotent_viewer = PhabricatorUser::getOmnipotentUser(); $invite_author = id(new PhabricatorPeopleQuery()) ->setViewer($omnipotent_viewer) ->withPHIDs(array($invite->getAuthorPHID())) ->needProfileImage(true) ->executeOne(); // If we can't load the author for some reason, just drop this message. // We lose the value of contextualizing things without author details. if (!$invite_author) { return null; } $invite_item = id(new PHUIObjectItemView()) ->setHeader( pht( 'Welcome to %s!', PlatformSymbols::getPlatformServerName())) ->setImageURI($invite_author->getProfileImageURI()) ->addAttribute( pht( '%s has invited you to join %s.', $invite_author->getFullName(), PlatformSymbols::getPlatformServerName())); $invite_list = id(new PHUIObjectItemListView()) ->addItem($invite_item) ->setFlush(true); return id(new PHUIBoxView()) ->addMargin(PHUI::MARGIN_LARGE) ->appendChild($invite_list); } final protected function newCustomStartMessage() { $viewer = $this->getViewer(); $text = PhabricatorAuthMessage::loadMessageText( $viewer, PhabricatorAuthLoginMessageType::MESSAGEKEY); if ($text === null || !strlen($text)) { return null; } $remarkup_view = new PHUIRemarkupView($viewer, $text); return phutil_tag( 'div', array( 'class' => 'auth-custom-message', ), $remarkup_view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthStartController.php
src/applications/auth/controller/PhabricatorAuthStartController.php
<?php final class PhabricatorAuthStartController extends PhabricatorAuthController { public function shouldRequireLogin() { return false; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getUser(); if ($viewer->isLoggedIn()) { // Kick the user home if they are already logged in. return id(new AphrontRedirectResponse())->setURI('/'); } if ($request->isAjax()) { return $this->processAjaxRequest(); } if ($request->isConduit()) { return $this->processConduitRequest(); } // If the user gets this far, they aren't logged in, so if they have a // user session token we can conclude that it's invalid: if it was valid, // they'd have been logged in above and never made it here. Try to clear // it and warn the user they may need to nuke their cookies. $session_token = $request->getCookie(PhabricatorCookies::COOKIE_SESSION); $did_clear = $request->getStr('cleared'); if ($session_token !== null && strlen($session_token)) { $kind = PhabricatorAuthSessionEngine::getSessionKindFromToken( $session_token); switch ($kind) { case PhabricatorAuthSessionEngine::KIND_ANONYMOUS: // If this is an anonymous session. It's expected that they won't // be logged in, so we can just continue. break; default: // The session cookie is invalid, so try to clear it. $request->clearCookie(PhabricatorCookies::COOKIE_USERNAME); $request->clearCookie(PhabricatorCookies::COOKIE_SESSION); // We've previously tried to clear the cookie but we ended up back // here, so it didn't work. Hard fatal instead of trying again. if ($did_clear) { return $this->renderError( pht( 'Your login session is invalid, and clearing the session '. 'cookie was unsuccessful. Try clearing your browser cookies.')); } $redirect_uri = $request->getRequestURI(); $redirect_uri->replaceQueryParam('cleared', 1); return id(new AphrontRedirectResponse())->setURI($redirect_uri); } } // If we just cleared the session cookie and it worked, clean up after // ourselves by redirecting to get rid of the "cleared" parameter. The // the workflow will continue normally. if ($did_clear) { $redirect_uri = $request->getRequestURI(); $redirect_uri->removeQueryParam('cleared'); return id(new AphrontRedirectResponse())->setURI($redirect_uri); } $providers = PhabricatorAuthProvider::getAllEnabledProviders(); foreach ($providers as $key => $provider) { if (!$provider->shouldAllowLogin()) { unset($providers[$key]); } } $configs = array(); foreach ($providers as $provider) { $configs[] = $provider->getProviderConfig(); } if (!$providers) { if ($this->isFirstTimeSetup()) { // If this is a fresh install, let the user register their admin // account. return id(new AphrontRedirectResponse()) ->setURI($this->getApplicationURI('/register/')); } return $this->renderError( pht( 'This server is not configured with any enabled authentication '. 'providers which can be used to log in. If you have accidentally '. 'locked yourself out by disabling all providers, you can use `%s` '. 'to recover access to an account.', './bin/auth recover <username>')); } $next_uri = $request->getStr('next'); if (phutil_nonempty_string($next_uri)) { if ($this->getDelegatingController()) { // Only set a next URI from the request path if this controller was // delegated to, which happens when a user tries to view a page which // requires them to login. // If this controller handled the request directly, we're on the main // login page, and never want to redirect the user back here after they // login. $next_uri = (string)$this->getRequest()->getRequestURI(); } } if (!$request->isFormPost()) { if (phutil_nonempty_string($next_uri)) { PhabricatorCookies::setNextURICookie($request, $next_uri); } PhabricatorCookies::setClientIDCookie($request); } $auto_response = $this->tryAutoLogin($providers); if ($auto_response) { return $auto_response; } $invite = $this->loadInvite(); $not_buttons = array(); $are_buttons = array(); $providers = msort($providers, 'getLoginOrder'); foreach ($providers as $provider) { if ($invite) { $form = $provider->buildInviteForm($this); } else { $form = $provider->buildLoginForm($this); } if ($provider->isLoginFormAButton()) { $are_buttons[] = $form; } else { $not_buttons[] = $form; } } $out = array(); $out[] = $not_buttons; if ($are_buttons) { require_celerity_resource('auth-css'); foreach ($are_buttons as $key => $button) { $are_buttons[$key] = phutil_tag( 'div', array( 'class' => 'phabricator-login-button mmb', ), $button); } // If we only have one button, add a second pretend button so that we // always have two columns. This makes it easier to get the alignments // looking reasonable. if (count($are_buttons) == 1) { $are_buttons[] = null; } $button_columns = id(new AphrontMultiColumnView()) ->setFluidLayout(true); $are_buttons = array_chunk($are_buttons, ceil(count($are_buttons) / 2)); foreach ($are_buttons as $column) { $button_columns->addColumn($column); } $out[] = phutil_tag( 'div', array( 'class' => 'phabricator-login-buttons', ), $button_columns); } $invite_message = null; if ($invite) { $invite_message = $this->renderInviteHeader($invite); } $custom_message = $this->newCustomStartMessage(); $email_login = $this->newEmailLoginView($configs); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Login')); $crumbs->setBorder(true); $title = pht('Login'); $view = array( $invite_message, $custom_message, $out, $email_login, ); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($view); } private function processAjaxRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); // We end up here if the user clicks a workflow link that they need to // login to use. We give them a dialog saying "You need to login...". if ($request->isDialogFormPost()) { return id(new AphrontRedirectResponse())->setURI( $request->getRequestURI()); } // Often, users end up here by clicking a disabled action link in the UI // (for example, they might click "Edit Subtasks" on a Maniphest task // page). After they log in we want to send them back to that main object // page if we can, since it's confusing to end up on a standalone page with // only a dialog (particularly if that dialog is another error, // like a policy exception). $via_header = AphrontRequest::getViaHeaderName(); $via_uri = AphrontRequest::getHTTPHeader($via_header); if ($via_uri !== null && strlen($via_uri)) { PhabricatorCookies::setNextURICookie($request, $via_uri, $force = true); } return $this->newDialog() ->setTitle(pht('Login Required')) ->appendParagraph(pht('You must log in to take this action.')) ->addSubmitButton(pht('Log In')) ->addCancelButton('/'); } private function processConduitRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); // A common source of errors in Conduit client configuration is getting // the request path wrong. The client will end up here, so make some // effort to give them a comprehensible error message. $request_path = $this->getRequest()->getPath(); $conduit_path = '/api/<method>'; $example_path = '/api/conduit.ping'; $message = pht( 'ERROR: You are making a Conduit API request to "%s", but the correct '. 'HTTP request path to use in order to access a Conduit method is "%s" '. '(for example, "%s"). Check your configuration.', $request_path, $conduit_path, $example_path); return id(new AphrontPlainTextResponse())->setContent($message); } protected function renderError($message) { return $this->renderErrorPage( pht('Authentication Failure'), array($message)); } private function tryAutoLogin(array $providers) { $request = $this->getRequest(); // If the user just logged out, don't immediately log them in again. if ($request->getURIData('loggedout')) { return null; } // If we have more than one provider, we can't autologin because we // don't know which one the user wants. if (count($providers) != 1) { return null; } $provider = head($providers); if (!$provider->supportsAutoLogin()) { return null; } $config = $provider->getProviderConfig(); if (!$config->getShouldAutoLogin()) { return null; } $auto_uri = $provider->getAutoLoginURI($request); return id(new AphrontRedirectResponse()) ->setIsExternal(true) ->setURI($auto_uri); } private function newEmailLoginView(array $configs) { assert_instances_of($configs, 'PhabricatorAuthProviderConfig'); // Check if password auth is enabled. If it is, the password login form // renders a "Forgot password?" link, so we don't need to provide a // supplemental link. $has_password = false; foreach ($configs as $config) { $provider = $config->getProvider(); if ($provider instanceof PhabricatorPasswordAuthProvider) { $has_password = true; } } if ($has_password) { return null; } $view = array( pht('Trouble logging in?'), ' ', phutil_tag( 'a', array( 'href' => '/login/email/', ), pht('Send a login link to your email address.')), ); return phutil_tag( 'div', array( 'class' => 'auth-custom-message', ), $view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/PhabricatorAuthSSHKeyRevokeController.php
src/applications/auth/controller/PhabricatorAuthSSHKeyRevokeController.php
<?php final class PhabricatorAuthSSHKeyRevokeController extends PhabricatorAuthSSHKeyController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $key = id(new PhabricatorAuthSSHKeyQuery()) ->setViewer($viewer) ->withIDs(array($request->getURIData('id'))) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$key) { return new Aphront404Response(); } $cancel_uri = $key->getURI(); $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( $viewer, $request, $cancel_uri); if ($request->isFormPost()) { $xactions = array(); $xactions[] = id(new PhabricatorAuthSSHKeyTransaction()) ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_DEACTIVATE) ->setNewValue(true); id(new PhabricatorAuthSSHKeyEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->applyTransactions($key, $xactions); return id(new AphrontRedirectResponse())->setURI($cancel_uri); } $name = phutil_tag('strong', array(), $key->getName()); return $this->newDialog() ->setTitle(pht('Revoke SSH Public Key')) ->appendParagraph( pht( 'The key "%s" will be permanently revoked, and you will no '. 'longer be able to use the corresponding private key to '. 'authenticate.', $name)) ->addSubmitButton(pht('Revoke Public Key')) ->addCancelButton($cancel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderViewController.php
src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderViewController.php
<?php final class PhabricatorAuthFactorProviderViewController extends PhabricatorAuthFactorProviderController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $provider = id(new PhabricatorAuthFactorProviderQuery()) ->setViewer($viewer) ->withIDs(array($request->getURIData('id'))) ->executeOne(); if (!$provider) { return new Aphront404Response(); } $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb($provider->getObjectName()) ->setBorder(true); $header = $this->buildHeaderView($provider); $properties = $this->buildPropertiesView($provider); $curtain = $this->buildCurtain($provider); $timeline = $this->buildTransactionTimeline( $provider, new PhabricatorAuthFactorProviderTransactionQuery()); $timeline->setShouldTerminate(true); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->setMainColumn( array( $timeline, )) ->addPropertySection(pht('Details'), $properties); return $this->newPage() ->setTitle($provider->getDisplayName()) ->setCrumbs($crumbs) ->setPageObjectPHIDs( array( $provider->getPHID(), )) ->appendChild($view); } private function buildHeaderView(PhabricatorAuthFactorProvider $provider) { $viewer = $this->getViewer(); $view = id(new PHUIHeaderView()) ->setViewer($viewer) ->setHeader($provider->getDisplayName()) ->setPolicyObject($provider); $status = $provider->newStatus(); $header_icon = $status->getStatusHeaderIcon(); $header_color = $status->getStatusHeaderColor(); $header_name = $status->getName(); if ($header_icon !== null) { $view->setStatus($header_icon, $header_color, $header_name); } return $view; } private function buildPropertiesView( PhabricatorAuthFactorProvider $provider) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView()) ->setViewer($viewer); $view->addProperty( pht('Factor Type'), $provider->getFactor()->getFactorName()); $custom_enroll = $provider->getEnrollMessage(); if ($custom_enroll !== null && strlen($custom_enroll)) { $view->addSectionHeader( pht('Custom Enroll Message'), PHUIPropertyListView::ICON_SUMMARY); $view->addTextContent( new PHUIRemarkupView($viewer, $custom_enroll)); } return $view; } private function buildCurtain(PhabricatorAuthFactorProvider $provider) { $viewer = $this->getViewer(); $id = $provider->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $provider, PhabricatorPolicyCapability::CAN_EDIT); $curtain = $this->newCurtainView($provider); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit MFA Provider')) ->setIcon('fa-pencil') ->setHref($this->getApplicationURI("mfa/edit/{$id}/")) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Customize Enroll Message')) ->setIcon('fa-commenting-o') ->setHref($this->getApplicationURI("mfa/message/{$id}/")) ->setDisabled(!$can_edit) ->setWorkflow(true)); return $curtain; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderController.php
src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderController.php
<?php abstract class PhabricatorAuthFactorProviderController extends PhabricatorAuthProviderController { protected function buildApplicationCrumbs() { return parent::buildApplicationCrumbs() ->addTextCrumb(pht('Multi-Factor'), $this->getApplicationURI('mfa/')); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/mfa/PhabricatorAuthChallengeStatusController.php
src/applications/auth/controller/mfa/PhabricatorAuthChallengeStatusController.php
<?php final class PhabricatorAuthChallengeStatusController extends PhabricatorAuthController { public function shouldAllowPartialSessions() { // We expect that users may request the status of an MFA challenge when // they hit the session upgrade gate on login. return true; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); $now = PhabricatorTime::getNow(); $result = new PhabricatorAuthChallengeUpdate(); $challenge = id(new PhabricatorAuthChallengeQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->withUserPHIDs(array($viewer->getPHID())) ->withChallengeTTLBetween($now, null) ->executeOne(); if ($challenge) { $config = id(new PhabricatorAuthFactorConfigQuery()) ->setViewer($viewer) ->withPHIDs(array($challenge->getFactorPHID())) ->executeOne(); if ($config) { $provider = $config->getFactorProvider(); $factor = $provider->getFactor(); $result = $factor->newChallengeStatusView( $config, $provider, $viewer, $challenge); } } return id(new AphrontAjaxResponse()) ->setContent($result->newContent()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderListController.php
src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderListController.php
<?php final class PhabricatorAuthFactorProviderListController extends PhabricatorAuthProviderController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $can_manage = $this->hasApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $providers = id(new PhabricatorAuthFactorProviderQuery()) ->setViewer($viewer) ->execute(); $list = new PHUIObjectItemListView(); foreach ($providers as $provider) { $item = id(new PHUIObjectItemView()) ->setObjectName($provider->getObjectName()) ->setHeader($provider->getDisplayName()) ->setHref($provider->getURI()); $status = $provider->newStatus(); $icon = $status->getListIcon(); $color = $status->getListColor(); if ($icon !== null) { $item->setStatusIcon("{$icon} {$color}", $status->getName()); } $item->setDisabled(!$status->isActive()); $list->addItem($item); } $list->setNoDataString( pht('You have not configured any multi-factor providers yet.')); $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb(pht('Multi-Factor')) ->setBorder(true); $button = id(new PHUIButtonView()) ->setTag('a') ->setButtonType(PHUIButtonView::BUTTONTYPE_SIMPLE) ->setHref($this->getApplicationURI('mfa/edit/')) ->setIcon('fa-plus') ->setDisabled(!$can_manage) ->setWorkflow(true) ->setText(pht('Add MFA Provider')); $list->setFlush(true); $list = id(new PHUIObjectBoxView()) ->setHeaderText(pht('MFA Providers')) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->appendChild($list); $title = pht('MFA Providers'); $header = id(new PHUIHeaderView()) ->setHeader($title) ->setHeaderIcon('fa-mobile') ->addActionLink($button); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter( array( $list, )); $nav = $this->newNavigation() ->setCrumbs($crumbs) ->appendChild($view); $nav->selectFilter('mfa'); return $this->newPage() ->setTitle($title) ->appendChild($nav); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderMessageController.php
src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderMessageController.php
<?php final class PhabricatorAuthFactorProviderMessageController extends PhabricatorAuthFactorProviderController { public function handleRequest(AphrontRequest $request) { $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $viewer = $request->getViewer(); $id = $request->getURIData('id'); $provider = id(new PhabricatorAuthFactorProviderQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$provider) { return new Aphront404Response(); } $cancel_uri = $provider->getURI(); $enroll_key = PhabricatorAuthFactorProviderEnrollMessageTransaction::TRANSACTIONTYPE; $message = $provider->getEnrollMessage(); if ($request->isFormOrHisecPost()) { $message = $request->getStr('message'); $xactions = array(); $xactions[] = id(new PhabricatorAuthFactorProviderTransaction()) ->setTransactionType($enroll_key) ->setNewValue($message); $editor = id(new PhabricatorAuthFactorProviderEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->setCancelURI($cancel_uri); $editor->applyTransactions($provider, $xactions); return id(new AphrontRedirectResponse())->setURI($cancel_uri); } $default_message = $provider->getEnrollDescription($viewer); $default_message = new PHUIRemarkupView($viewer, $default_message); $form = id(new AphrontFormView()) ->setViewer($viewer) ->appendRemarkupInstructions( pht( 'When users add a factor for this provider, they are given this '. 'enrollment guidance by default:')) ->appendControl( id(new AphrontFormMarkupControl()) ->setLabel(pht('Default Message')) ->setValue($default_message)) ->appendRemarkupInstructions( pht( 'You may optionally customize the enrollment message users are '. 'presented with by providing a replacement message below:')) ->appendControl( id(new PhabricatorRemarkupControl()) ->setLabel(pht('Custom Message')) ->setName('message') ->setValue($message)); return $this->newDialog() ->setTitle(pht('Change Enroll Message')) ->setWidth(AphrontDialogView::WIDTH_FORM) ->appendForm($form) ->addCancelButton($cancel_uri) ->addSubmitButton(pht('Save')); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderEditController.php
src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderEditController.php
<?php final class PhabricatorAuthFactorProviderEditController extends PhabricatorAuthFactorProviderController { public function handleRequest(AphrontRequest $request) { $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $engine = id(new PhabricatorAuthFactorProviderEditEngine()) ->setController($this); $id = $request->getURIData('id'); if (!$id) { $factor_key = $request->getStr('providerFactorKey'); $map = PhabricatorAuthFactor::getAllFactors(); $factor = idx($map, $factor_key); if (!$factor) { return $this->buildFactorSelectionResponse(); } $engine ->addContextParameter('providerFactorKey', $factor_key) ->setProviderFactor($factor); } return $engine->buildResponse(); } private function buildFactorSelectionResponse() { $request = $this->getRequest(); $viewer = $this->getViewer(); $cancel_uri = $this->getApplicationURI('mfa/'); $factors = PhabricatorAuthFactor::getAllFactors(); $menu = id(new PHUIObjectItemListView()) ->setUser($viewer) ->setBig(true) ->setFlush(true); $factors = msortv($factors, 'newSortVector'); foreach ($factors as $factor_key => $factor) { $factor_uri = id(new PhutilURI('/mfa/edit/')) ->replaceQueryParam('providerFactorKey', $factor_key); $factor_uri = $this->getApplicationURI($factor_uri); $is_enabled = $factor->canCreateNewProvider(); $item = id(new PHUIObjectItemView()) ->setHeader($factor->getFactorName()) ->setImageIcon($factor->newIconView()) ->addAttribute($factor->getFactorCreateHelp()); if ($is_enabled) { $item ->setHref($factor_uri) ->setClickable(true); } else { $item->setDisabled(true); } $create_description = $factor->getProviderCreateDescription(); if ($create_description) { $item->appendChild($create_description); } $menu->addItem($item); } return $this->newDialog() ->setTitle(pht('Choose Provider Type')) ->appendChild($menu) ->addCancelButton($cancel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/message/PhabricatorAuthMessageViewController.php
src/applications/auth/controller/message/PhabricatorAuthMessageViewController.php
<?php final class PhabricatorAuthMessageViewController extends PhabricatorAuthMessageController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); // The "id" in the URI may either be an actual storage record ID (if a // message has already been created) or a message type key (for a message // type which does not have a record yet). // This flow allows messages which have not been set yet to have a detail // page (so users can get detailed information about the message and see // any default value). $id = $request->getURIData('id'); if (ctype_digit($id)) { $message = id(new PhabricatorAuthMessageQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$message) { return new Aphront404Response(); } } else { $types = PhabricatorAuthMessageType::getAllMessageTypes(); if (!isset($types[$id])) { return new Aphront404Response(); } // If this message type already has a storage record, redirect to the // canonical page for the record. $message = id(new PhabricatorAuthMessageQuery()) ->setViewer($viewer) ->withMessageKeys(array($id)) ->executeOne(); if ($message) { $message_uri = $message->getURI(); return id(new AphrontRedirectResponse())->setURI($message_uri); } // Otherwise, create an empty placeholder message object with the // appropriate message type. $message = PhabricatorAuthMessage::initializeNewMessage($types[$id]); } $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb($message->getMessageType()->getDisplayName()) ->setBorder(true); $header = $this->buildHeaderView($message); $properties = $this->buildPropertiesView($message); $curtain = $this->buildCurtain($message); if ($message->getID()) { $timeline = $this->buildTransactionTimeline( $message, new PhabricatorAuthMessageTransactionQuery()); $timeline->setShouldTerminate(true); } else { $timeline = null; } $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->setMainColumn( array( $timeline, )) ->addPropertySection(pht('Details'), $properties); return $this->newPage() ->setTitle($message->getMessageTypeDisplayName()) ->setCrumbs($crumbs) ->setPageObjectPHIDs( array( $message->getPHID(), )) ->appendChild($view); } private function buildHeaderView(PhabricatorAuthMessage $message) { $viewer = $this->getViewer(); $view = id(new PHUIHeaderView()) ->setViewer($viewer) ->setHeader($message->getMessageTypeDisplayName()); return $view; } private function buildPropertiesView(PhabricatorAuthMessage $message) { $viewer = $this->getViewer(); $message_type = $message->getMessageType(); $view = id(new PHUIPropertyListView()) ->setViewer($viewer); $full_description = $message_type->getFullDescription(); if (strlen($full_description)) { $view->addTextContent(new PHUIRemarkupView($viewer, $full_description)); } else { $short_description = $message_type->getShortDescription(); $view->addProperty(pht('Description'), $short_description); } $message_text = $message->getMessageText(); if (strlen($message_text)) { $view->addSectionHeader( pht('Message Preview'), PHUIPropertyListView::ICON_SUMMARY); $view->addTextContent(new PHUIRemarkupView($viewer, $message_text)); } $default_text = $message_type->getDefaultMessageText(); if (strlen($default_text)) { $view->addSectionHeader( pht('Default Message'), PHUIPropertyListView::ICON_SUMMARY); $view->addTextContent(new PHUIRemarkupView($viewer, $default_text)); } return $view; } private function buildCurtain(PhabricatorAuthMessage $message) { $viewer = $this->getViewer(); $id = $message->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $message, PhabricatorPolicyCapability::CAN_EDIT); if ($id) { $edit_uri = urisprintf('message/edit/%s/', $id); $edit_name = pht('Edit Message'); } else { $edit_uri = urisprintf('message/edit/'); $params = array( 'messageKey' => $message->getMessageKey(), ); $edit_uri = new PhutilURI($edit_uri, $params); $edit_name = pht('Customize Message'); } $edit_uri = $this->getApplicationURI($edit_uri); $curtain = $this->newCurtainView($message); $curtain->addAction( id(new PhabricatorActionView()) ->setName($edit_name) ->setIcon('fa-pencil') ->setHref($edit_uri) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); return $curtain; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/message/PhabricatorAuthMessageEditController.php
src/applications/auth/controller/message/PhabricatorAuthMessageEditController.php
<?php final class PhabricatorAuthMessageEditController extends PhabricatorAuthMessageController { public function handleRequest(AphrontRequest $request) { $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $engine = id(new PhabricatorAuthMessageEditEngine()) ->setController($this); $id = $request->getURIData('id'); if (!$id) { $message_key = $request->getStr('messageKey'); $message_types = PhabricatorAuthMessageType::getAllMessageTypes(); $message_type = idx($message_types, $message_key); if (!$message_type) { return new Aphront404Response(); } $engine ->addContextParameter('messageKey', $message_key) ->setMessageType($message_type); } return $engine->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/message/PhabricatorAuthMessageController.php
src/applications/auth/controller/message/PhabricatorAuthMessageController.php
<?php abstract class PhabricatorAuthMessageController extends PhabricatorAuthProviderController { protected function buildApplicationCrumbs() { return parent::buildApplicationCrumbs() ->addTextCrumb(pht('Messages'), $this->getApplicationURI('message/')); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/message/PhabricatorAuthMessageListController.php
src/applications/auth/controller/message/PhabricatorAuthMessageListController.php
<?php final class PhabricatorAuthMessageListController extends PhabricatorAuthProviderController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $can_manage = $this->hasApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $types = PhabricatorAuthMessageType::getAllMessageTypes(); $messages = id(new PhabricatorAuthMessageQuery()) ->setViewer($viewer) ->execute(); $messages = mpull($messages, null, 'getMessageKey'); $list = new PHUIObjectItemListView(); foreach ($types as $type) { $message = idx($messages, $type->getMessageTypeKey()); if ($message) { $href = $message->getURI(); $name = $message->getMessageTypeDisplayName(); } else { $href = urisprintf( '/auth/message/%s/', $type->getMessageTypeKey()); $name = $type->getDisplayName(); } $item = id(new PHUIObjectItemView()) ->setHeader($name) ->setHref($href) ->addAttribute($type->getShortDescription()); if ($message) { $item->addIcon('fa-circle', pht('Customized')); } else { $item->addIcon('fa-circle-o grey', pht('Default')); } $list->addItem($item); } $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb(pht('Messages')) ->setBorder(true); $list->setFlush(true); $list = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Auth Messages')) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->appendChild($list); $title = pht('Auth Messages'); $header = id(new PHUIHeaderView()) ->setHeader($title) ->setHeaderIcon('fa-commenting-o'); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter( array( $list, )); $nav = $this->newNavigation() ->setCrumbs($crumbs) ->appendChild($view); $nav->selectFilter('message'); return $this->newPage() ->setTitle($title) ->appendChild($nav); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/config/PhabricatorAuthNewController.php
src/applications/auth/controller/config/PhabricatorAuthNewController.php
<?php final class PhabricatorAuthNewController extends PhabricatorAuthProviderConfigController { public function handleRequest(AphrontRequest $request) { $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $viewer = $this->getViewer(); $cancel_uri = $this->getApplicationURI(); $locked_config_key = 'auth.lock-config'; $is_locked = PhabricatorEnv::getEnvConfig($locked_config_key); if ($is_locked) { $message = pht( 'Authentication provider configuration is locked, and can not be '. 'changed without being unlocked. See the configuration setting %s '. 'for details.', phutil_tag( 'a', array( 'href' => '/config/edit/'.$locked_config_key, ), $locked_config_key)); return $this->newDialog() ->setUser($viewer) ->setTitle(pht('Authentication Config Locked')) ->appendChild($message) ->addCancelButton($cancel_uri); } $providers = PhabricatorAuthProvider::getAllBaseProviders(); $configured = PhabricatorAuthProvider::getAllProviders(); $configured_classes = array(); foreach ($configured as $configured_provider) { $configured_classes[get_class($configured_provider)] = true; } // Sort providers by login order, and move disabled providers to the // bottom. $providers = msort($providers, 'getLoginOrder'); $providers = array_diff_key($providers, $configured_classes) + $providers; $menu = id(new PHUIObjectItemListView()) ->setViewer($viewer) ->setBig(true) ->setFlush(true); foreach ($providers as $provider_key => $provider) { $provider_class = get_class($provider); $provider_uri = id(new PhutilURI('/config/edit/')) ->replaceQueryParam('provider', $provider_class); $provider_uri = $this->getApplicationURI($provider_uri); $already_exists = isset($configured_classes[get_class($provider)]); $item = id(new PHUIObjectItemView()) ->setHeader($provider->getNameForCreate()) ->setImageIcon($provider->newIconView()) ->addAttribute($provider->getDescriptionForCreate()); if (!$already_exists) { $item ->setHref($provider_uri) ->setClickable(true); } else { $item->setDisabled(true); } if ($already_exists) { $messages = array(); $messages[] = pht('You already have a provider of this type.'); $info = id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_WARNING) ->setErrors($messages); $item->appendChild($info); } $menu->addItem($item); } return $this->newDialog() ->setTitle(pht('Add Auth Provider')) ->setWidth(AphrontDialogView::WIDTH_FORM) ->appendChild($menu) ->addCancelButton($cancel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/config/PhabricatorAuthProviderConfigController.php
src/applications/auth/controller/config/PhabricatorAuthProviderConfigController.php
<?php abstract class PhabricatorAuthProviderConfigController extends PhabricatorAuthProviderController {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/config/PhabricatorAuthListController.php
src/applications/auth/controller/config/PhabricatorAuthListController.php
<?php final class PhabricatorAuthListController extends PhabricatorAuthProviderConfigController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $configs = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer($viewer) ->execute(); $list = new PHUIObjectItemListView(); $can_manage = $this->hasApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $is_locked = PhabricatorEnv::getEnvConfig('auth.lock-config'); foreach ($configs as $config) { $item = new PHUIObjectItemView(); $id = $config->getID(); $view_uri = $config->getURI(); $provider = $config->getProvider(); $name = $provider->getProviderName(); $item ->setHeader($name) ->setHref($view_uri); $domain = $provider->getProviderDomain(); if ($domain !== 'self') { $item->addAttribute($domain); } if ($config->getShouldAllowRegistration()) { $item->addAttribute(pht('Allows Registration')); } else { $item->addAttribute(pht('Does Not Allow Registration')); } if ($config->getIsEnabled()) { $item->setStatusIcon('fa-check-circle green'); } else { $item->setStatusIcon('fa-ban red'); $item->addIcon('fa-ban grey', pht('Disabled')); } $list->addItem($item); } $list->setNoDataString( pht( '%s You have not added authentication providers yet. Use "%s" to add '. 'a provider, which will let users register new accounts and log in.', phutil_tag( 'strong', array(), pht('No Providers Configured:')), phutil_tag( 'a', array( 'href' => $this->getApplicationURI('config/new/'), ), pht('Add Provider')))); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Login and Registration')); $crumbs->setBorder(true); $guidance_context = id(new PhabricatorAuthProvidersGuidanceContext()) ->setCanManage($can_manage); $guidance = id(new PhabricatorGuidanceEngine()) ->setViewer($viewer) ->setGuidanceContext($guidance_context) ->newInfoView(); $is_disabled = (!$can_manage || $is_locked); $button = id(new PHUIButtonView()) ->setTag('a') ->setButtonType(PHUIButtonView::BUTTONTYPE_SIMPLE) ->setIcon('fa-plus') ->setDisabled($is_disabled) ->setWorkflow($is_disabled) ->setHref($this->getApplicationURI('config/new/')) ->setText(pht('Add Provider')); $list->setFlush(true); $list = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Providers')) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->appendChild($list); $title = pht('Login and Registration Providers'); $header = id(new PHUIHeaderView()) ->setHeader($title) ->setHeaderIcon('fa-key') ->addActionLink($button); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter( array( $guidance, $list, )); $nav = $this->newNavigation() ->setCrumbs($crumbs) ->appendChild($view); $nav->selectFilter('login'); return $this->newPage() ->setTitle($title) ->appendChild($nav); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/config/PhabricatorAuthProviderController.php
src/applications/auth/controller/config/PhabricatorAuthProviderController.php
<?php abstract class PhabricatorAuthProviderController extends PhabricatorAuthController { protected function newNavigation() { $viewer = $this->getViewer(); $nav = id(new AphrontSideNavFilterView()) ->setBaseURI(new PhutilURI($this->getApplicationURI())) ->setViewer($viewer); $nav->addMenuItem( id(new PHUIListItemView()) ->setName(pht('Authentication')) ->setType(PHUIListItemView::TYPE_LABEL)); $nav->addMenuItem( id(new PHUIListItemView()) ->setKey('login') ->setName(pht('Login and Registration')) ->setType(PHUIListItemView::TYPE_LINK) ->setHref($this->getApplicationURI('/')) ->setIcon('fa-key')); $nav->addMenuItem( id(new PHUIListItemView()) ->setKey('mfa') ->setName(pht('Multi-Factor')) ->setType(PHUIListItemView::TYPE_LINK) ->setHref($this->getApplicationURI('mfa/')) ->setIcon('fa-mobile')); $nav->addMenuItem( id(new PHUIListItemView()) ->setName(pht('Onboarding')) ->setType(PHUIListItemView::TYPE_LABEL)); $nav->addMenuItem( id(new PHUIListItemView()) ->setKey('message') ->setName(pht('Customize Messages')) ->setType(PHUIListItemView::TYPE_LINK) ->setHref($this->getApplicationURI('message/')) ->setIcon('fa-commenting-o')); $nav->selectFilter(null); return $nav; } public function buildApplicationMenu() { return $this->newNavigation()->getMenu(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/config/PhabricatorAuthDisableController.php
src/applications/auth/controller/config/PhabricatorAuthDisableController.php
<?php final class PhabricatorAuthDisableController extends PhabricatorAuthProviderConfigController { public function handleRequest(AphrontRequest $request) { $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $viewer = $this->getViewer(); $config_id = $request->getURIData('id'); $action = $request->getURIData('action'); $config = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->withIDs(array($config_id)) ->executeOne(); if (!$config) { return new Aphront404Response(); } $is_enable = ($action === 'enable'); $done_uri = $config->getURI(); if ($request->isDialogFormPost()) { $xactions = array(); $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE) ->setNewValue((int)$is_enable); $editor = id(new PhabricatorAuthProviderConfigEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->applyTransactions($config, $xactions); return id(new AphrontRedirectResponse())->setURI($done_uri); } if ($is_enable) { $title = pht('Enable Provider?'); if ($config->getShouldAllowRegistration()) { $body = pht( 'Do you want to enable this provider? Users will be able to use '. 'their existing external accounts to register new accounts and '. 'log in using linked accounts.'); } else { $body = pht( 'Do you want to enable this provider? Users will be able to log '. 'in using linked accounts.'); } $button = pht('Enable Provider'); } else { // TODO: We could tailor this a bit more. In particular, we could // check if this is the last provider and either prevent if from // being disabled or force the user through like 35 prompts. We could // also check if it's the last provider linked to the acting user's // account and pop a warning like "YOU WILL NO LONGER BE ABLE TO LOGIN // YOU GOOF, YOU PROBABLY DO NOT MEAN TO DO THIS". None of this is // critical and we can wait to see how users manage to shoot themselves // in the feet. // `bin/auth` can recover from these types of mistakes. $title = pht('Disable Provider?'); $body = pht( 'Do you want to disable this provider? Users will not be able to '. 'register or log in using linked accounts. If there are any users '. 'without other linked authentication mechanisms, they will no longer '. 'be able to log in. If you disable all providers, no one will be '. 'able to log in.'); $button = pht('Disable Provider'); } return $this->newDialog() ->setTitle($title) ->appendChild($body) ->addCancelButton($done_uri) ->addSubmitButton($button); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/config/PhabricatorAuthEditController.php
src/applications/auth/controller/config/PhabricatorAuthEditController.php
<?php final class PhabricatorAuthEditController extends PhabricatorAuthProviderConfigController { public function handleRequest(AphrontRequest $request) { $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $viewer = $this->getViewer(); $provider_class = $request->getStr('provider'); $config_id = $request->getURIData('id'); if ($config_id) { $config = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->withIDs(array($config_id)) ->executeOne(); if (!$config) { return new Aphront404Response(); } $provider = $config->getProvider(); if (!$provider) { return new Aphront404Response(); } $is_new = false; } else { $provider = null; $providers = PhabricatorAuthProvider::getAllBaseProviders(); foreach ($providers as $candidate_provider) { if (get_class($candidate_provider) === $provider_class) { $provider = $candidate_provider; break; } } if (!$provider) { return new Aphront404Response(); } // TODO: When we have multi-auth providers, support them here. $configs = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer($viewer) ->withProviderClasses(array(get_class($provider))) ->execute(); if ($configs) { $id = head($configs)->getID(); $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setMethod('GET') ->setSubmitURI($this->getApplicationURI('config/edit/'.$id.'/')) ->setTitle(pht('Provider Already Configured')) ->appendChild( pht( 'This provider ("%s") already exists, and you can not add more '. 'than one instance of it. You can edit the existing provider, '. 'or you can choose a different provider.', $provider->getProviderName())) ->addCancelButton($this->getApplicationURI('config/new/')) ->addSubmitButton(pht('Edit Existing Provider')); return id(new AphrontDialogResponse())->setDialog($dialog); } $config = $provider->getDefaultProviderConfig(); $provider->attachProviderConfig($config); $is_new = true; } $errors = array(); $validation_exception = null; $v_login = $config->getShouldAllowLogin(); $v_registration = $config->getShouldAllowRegistration(); $v_link = $config->getShouldAllowLink(); $v_unlink = $config->getShouldAllowUnlink(); $v_trust_email = $config->getShouldTrustEmails(); $v_auto_login = $config->getShouldAutoLogin(); if ($request->isFormPost()) { $properties = $provider->readFormValuesFromRequest($request); list($errors, $issues, $properties) = $provider->processEditForm( $request, $properties); $xactions = array(); if (!$errors) { if ($is_new) { if (!strlen($config->getProviderType())) { $config->setProviderType($provider->getProviderType()); } if (!strlen($config->getProviderDomain())) { $config->setProviderDomain($provider->getProviderDomain()); } } $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN) ->setNewValue($request->getInt('allowLogin', 0)); $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION) ->setNewValue($request->getInt('allowRegistration', 0)); $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( PhabricatorAuthProviderConfigTransaction::TYPE_LINK) ->setNewValue($request->getInt('allowLink', 0)); $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK) ->setNewValue($request->getInt('allowUnlink', 0)); $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS) ->setNewValue($request->getInt('trustEmails', 0)); if ($provider->supportsAutoLogin()) { $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN) ->setNewValue($request->getInt('autoLogin', 0)); } foreach ($properties as $key => $value) { $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY) ->setMetadataValue('auth:property', $key) ->setNewValue($value); } if ($is_new) { $config->save(); } $editor = id(new PhabricatorAuthProviderConfigEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); try { $editor->applyTransactions($config, $xactions); $next_uri = $config->getURI(); return id(new AphrontRedirectResponse())->setURI($next_uri); } catch (Exception $ex) { $validation_exception = $ex; } } } else { $properties = $provider->readFormValuesFromProvider(); $issues = array(); } if ($is_new) { if ($provider->hasSetupStep()) { $button = pht('Next Step'); } else { $button = pht('Add Provider'); } $crumb = pht('Add Provider'); $title = pht('Add Auth Provider'); $header_icon = 'fa-plus-square'; $cancel_uri = $this->getApplicationURI('/config/new/'); } else { $button = pht('Save'); $crumb = pht('Edit Provider'); $title = pht('Edit Auth Provider'); $header_icon = 'fa-pencil'; $cancel_uri = $config->getURI(); } $header = id(new PHUIHeaderView()) ->setHeader(pht('%s: %s', $title, $provider->getProviderName())) ->setHeaderIcon($header_icon); if (!$is_new) { if ($config->getIsEnabled()) { $status_name = pht('Enabled'); $status_color = 'green'; $status_icon = 'fa-check'; $header->setStatus($status_icon, $status_color, $status_name); } else { $status_name = pht('Disabled'); $status_color = 'indigo'; $status_icon = 'fa-ban'; $header->setStatus($status_icon, $status_color, $status_name); } } $config_name = 'auth.email-domains'; $config_href = '/config/edit/'.$config_name.'/'; $email_domains = PhabricatorEnv::getEnvConfig($config_name); if ($email_domains) { $registration_warning = pht( 'Users will only be able to register with a verified email address '. 'at one of the configured [[ %s | %s ]] domains: **%s**', $config_href, $config_name, implode(', ', $email_domains)); } else { $registration_warning = pht( "NOTE: Any user who can browse to this install's login page will be ". "able to register an account. To restrict who can register ". "an account, configure [[ %s | %s ]].", $config_href, $config_name); } $str_login = array( phutil_tag('strong', array(), pht('Allow Login:')), ' ', pht( 'Allow users to log in using this provider. If you disable login, '. 'users can still use account integrations for this provider.'), ); $str_registration = array( phutil_tag('strong', array(), pht('Allow Registration:')), ' ', pht( 'Allow users to register new accounts using this provider. If you '. 'disable registration, users can still use this provider to log in '. 'to existing accounts, but will not be able to create new accounts.'), ); $str_link = hsprintf( '<strong>%s:</strong> %s', pht('Allow Linking Accounts'), pht( 'Allow users to link account credentials for this provider to '. 'existing accounts. There is normally no reason to disable this '. 'unless you are trying to move away from a provider and want to '. 'stop users from creating new account links.')); $str_unlink = hsprintf( '<strong>%s:</strong> %s', pht('Allow Unlinking Accounts'), pht( 'Allow users to unlink account credentials for this provider from '. 'existing accounts. If you disable this, accounts will be '. 'permanently bound to provider accounts.')); $str_trusted_email = hsprintf( '<strong>%s:</strong> %s', pht('Trust Email Addresses'), pht( 'Skip email verification for accounts registered '. 'through this provider.')); $str_auto_login = hsprintf( '<strong>%s:</strong> %s', pht('Allow Auto Login'), pht( 'Automatically log in with this provider if it is '. 'the only available provider.')); $form = id(new AphrontFormView()) ->setUser($viewer) ->addHiddenInput('provider', $provider_class) ->appendChild( id(new AphrontFormCheckboxControl()) ->setLabel(pht('Allow')) ->addCheckbox( 'allowLogin', 1, $str_login, $v_login)) ->appendChild( id(new AphrontFormCheckboxControl()) ->addCheckbox( 'allowRegistration', 1, $str_registration, $v_registration)) ->appendRemarkupInstructions($registration_warning) ->appendChild( id(new AphrontFormCheckboxControl()) ->addCheckbox( 'allowLink', 1, $str_link, $v_link)) ->appendChild( id(new AphrontFormCheckboxControl()) ->addCheckbox( 'allowUnlink', 1, $str_unlink, $v_unlink)); if ($provider->shouldAllowEmailTrustConfiguration()) { $form->appendChild( id(new AphrontFormCheckboxControl()) ->addCheckbox( 'trustEmails', 1, $str_trusted_email, $v_trust_email)); } if ($provider->supportsAutoLogin()) { $form->appendChild( id(new AphrontFormCheckboxControl()) ->addCheckbox( 'autoLogin', 1, $str_auto_login, $v_auto_login)); } $provider->extendEditForm($request, $form, $properties, $issues); $locked_config_key = 'auth.lock-config'; $is_locked = PhabricatorEnv::getEnvConfig($locked_config_key); $locked_warning = null; if ($is_locked && !$validation_exception) { $message = pht( 'Authentication provider configuration is locked, and can not be '. 'changed without being unlocked. See the configuration setting %s '. 'for details.', phutil_tag( 'a', array( 'href' => '/config/edit/'.$locked_config_key, ), $locked_config_key)); $locked_warning = id(new PHUIInfoView()) ->setViewer($viewer) ->setSeverity(PHUIInfoView::SEVERITY_WARNING) ->setErrors(array($message)); } $form ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($cancel_uri) ->setDisabled($is_locked) ->setValue($button)); $help = $provider->getConfigurationHelp(); if ($help) { $form->appendChild(id(new PHUIFormDividerControl())); $form->appendRemarkupInstructions($help); } $footer = $provider->renderConfigurationFooter(); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($crumb); $crumbs->setBorder(true); $form_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Provider')) ->setFormErrors($errors) ->setValidationException($validation_exception) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setForm($form); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter(array( $locked_warning, $form_box, $footer, )); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/config/PhabricatorAuthProviderViewController.php
src/applications/auth/controller/config/PhabricatorAuthProviderViewController.php
<?php final class PhabricatorAuthProviderViewController extends PhabricatorAuthProviderConfigController { public function handleRequest(AphrontRequest $request) { $this->requireApplicationCapability( AuthManageProvidersCapability::CAPABILITY); $viewer = $this->getViewer(); $id = $request->getURIData('id'); $config = id(new PhabricatorAuthProviderConfigQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->withIDs(array($id)) ->executeOne(); if (!$config) { return new Aphront404Response(); } $header = $this->buildHeaderView($config); $properties = $this->buildPropertiesView($config); $curtain = $this->buildCurtain($config); $timeline = $this->buildTransactionTimeline( $config, new PhabricatorAuthProviderConfigTransactionQuery()); $timeline->setShouldTerminate(true); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->addPropertySection(pht('Details'), $properties) ->setMainColumn($timeline); $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb($config->getObjectName()) ->setBorder(true); return $this->newPage() ->setTitle(pht('Auth Provider: %s', $config->getDisplayName())) ->setCrumbs($crumbs) ->appendChild($view); } private function buildHeaderView(PhabricatorAuthProviderConfig $config) { $viewer = $this->getViewer(); $view = id(new PHUIHeaderView()) ->setViewer($viewer) ->setHeader($config->getDisplayName()); if ($config->getIsEnabled()) { $view->setStatus('fa-check', 'bluegrey', pht('Enabled')); } else { $view->setStatus('fa-ban', 'red', pht('Disabled')); } return $view; } private function buildCurtain(PhabricatorAuthProviderConfig $config) { $viewer = $this->getViewer(); $id = $config->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $config, PhabricatorPolicyCapability::CAN_EDIT); $curtain = $this->newCurtainView($config); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Auth Provider')) ->setIcon('fa-pencil') ->setHref($this->getApplicationURI("config/edit/{$id}/")) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); if ($config->getIsEnabled()) { $disable_uri = $this->getApplicationURI('config/disable/'.$id.'/'); $disable_icon = 'fa-ban'; $disable_text = pht('Disable Provider'); } else { $disable_uri = $this->getApplicationURI('config/enable/'.$id.'/'); $disable_icon = 'fa-check'; $disable_text = pht('Enable Provider'); } $curtain->addAction( id(new PhabricatorActionView()) ->setName($disable_text) ->setIcon($disable_icon) ->setHref($disable_uri) ->setDisabled(!$can_edit) ->setWorkflow(true)); return $curtain; } private function buildPropertiesView(PhabricatorAuthProviderConfig $config) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView()) ->setViewer($viewer); $view->addProperty( pht('Provider Type'), $config->getProvider()->getProviderName()); $status = $this->buildStatus($config); $view->addProperty(pht('Status'), $status); return $view; } private function buildStatus(PhabricatorAuthProviderConfig $config) { $viewer = $this->getViewer(); $view = id(new PHUIStatusListView()) ->setViewer($viewer); $icon_enabled = PHUIStatusItemView::ICON_ACCEPT; $icon_disabled = PHUIStatusItemView::ICON_REJECT; $icon_map = array( true => $icon_enabled, false => $icon_disabled, ); $color_map = array( true => 'green', false => 'red', ); $provider = $config->getProvider(); $view->addItem( id(new PHUIStatusItemView()) ->setIcon( $icon_map[$config->getIsEnabled()], $color_map[$config->getIsEnabled()]) ->setTarget(pht('Provider Enabled'))); $view->addItem( id(new PHUIStatusItemView()) ->setIcon( $icon_map[$config->getShouldAllowLogin()], $color_map[$config->getShouldAllowLogin()]) ->setTarget(pht('Allow Logins'))); $view->addItem( id(new PHUIStatusItemView()) ->setIcon( $icon_map[$config->getShouldAllowRegistration()], $color_map[$config->getShouldAllowRegistration()]) ->setTarget(pht('Allow Registration'))); $view->addItem( id(new PHUIStatusItemView()) ->setIcon( $icon_map[$config->getShouldAllowLink()], $color_map[$config->getShouldAllowLink()]) ->setTarget(pht('Allow Account Linking'))); $view->addItem( id(new PHUIStatusItemView()) ->setIcon( $icon_map[$config->getShouldAllowUnlink()], $color_map[$config->getShouldAllowUnlink()]) ->setTarget(pht('Allow Account Unlinking'))); if ($provider->shouldAllowEmailTrustConfiguration()) { $view->addItem( id(new PHUIStatusItemView()) ->setIcon( $icon_map[$config->getShouldTrustEmails()], $color_map[$config->getShouldTrustEmails()]) ->setTarget(pht('Trust Email Addresses'))); } if ($provider->supportsAutoLogin()) { $view->addItem( id(new PHUIStatusItemView()) ->setIcon( $icon_map[$config->getShouldAutoLogin()], $color_map[$config->getShouldAutoLogin()]) ->setTarget(pht('Allow Auto Login'))); } return $view; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/contact/PhabricatorAuthContactNumberEditController.php
src/applications/auth/controller/contact/PhabricatorAuthContactNumberEditController.php
<?php final class PhabricatorAuthContactNumberEditController extends PhabricatorAuthContactNumberController { public function handleRequest(AphrontRequest $request) { return id(new PhabricatorAuthContactNumberEditEngine()) ->setController($this) ->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/contact/PhabricatorAuthContactNumberPrimaryController.php
src/applications/auth/controller/contact/PhabricatorAuthContactNumberPrimaryController.php
<?php final class PhabricatorAuthContactNumberPrimaryController extends PhabricatorAuthContactNumberController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $number = id(new PhabricatorAuthContactNumberQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$number) { return new Aphront404Response(); } $id = $number->getID(); $cancel_uri = $number->getURI(); if ($number->isDisabled()) { return $this->newDialog() ->setTitle(pht('Number Disabled')) ->appendParagraph( pht( 'You can not make a disabled number your primary contact number.')) ->addCancelButton($cancel_uri); } if ($number->getIsPrimary()) { return $this->newDialog() ->setTitle(pht('Number Already Primary')) ->appendParagraph( pht( 'This contact number is already your primary contact number.')) ->addCancelButton($cancel_uri); } if ($request->isFormOrHisecPost()) { $xactions = array(); $xactions[] = id(new PhabricatorAuthContactNumberTransaction()) ->setTransactionType( PhabricatorAuthContactNumberPrimaryTransaction::TRANSACTIONTYPE) ->setNewValue(true); $editor = id(new PhabricatorAuthContactNumberEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->setCancelURI($cancel_uri); try { $editor->applyTransactions($number, $xactions); } catch (PhabricatorApplicationTransactionValidationException $ex) { // This happens when you try to make a number into your primary // number, but you have contact number MFA on your account. return $this->newDialog() ->setTitle(pht('Unable to Make Primary')) ->setValidationException($ex) ->addCancelButton($cancel_uri); } return id(new AphrontRedirectResponse())->setURI($cancel_uri); } $number_display = phutil_tag( 'strong', array(), $number->getDisplayName()); return $this->newDialog() ->setTitle(pht('Set Primary Contact Number')) ->appendParagraph( pht( 'Designate %s as your primary contact number?', $number_display)) ->addSubmitButton(pht('Make Primary')) ->addCancelButton($cancel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/contact/PhabricatorAuthContactNumberTestController.php
src/applications/auth/controller/contact/PhabricatorAuthContactNumberTestController.php
<?php final class PhabricatorAuthContactNumberTestController extends PhabricatorAuthContactNumberController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $number = id(new PhabricatorAuthContactNumberQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$number) { return new Aphront404Response(); } $id = $number->getID(); $cancel_uri = $number->getURI(); // NOTE: This is a global limit shared by all users. PhabricatorSystemActionEngine::willTakeAction( array(id(new PhabricatorAuthApplication())->getPHID()), new PhabricatorAuthTestSMSAction(), 1); if ($request->isFormPost()) { $uri = PhabricatorEnv::getURI('/'); $uri = new PhutilURI($uri); $mail = id(new PhabricatorMetaMTAMail()) ->setMessageType(PhabricatorMailSMSMessage::MESSAGETYPE) ->addTos(array($viewer->getPHID())) ->setSensitiveContent(false) ->setBody( pht( 'This is a terse test text message (from "%s").', $uri->getDomain())) ->save(); return id(new AphrontRedirectResponse())->setURI($mail->getURI()); } $number_display = phutil_tag( 'strong', array(), $number->getDisplayName()); return $this->newDialog() ->setTitle(pht('Set Test Message')) ->appendParagraph( pht( 'Send a test message to %s?', $number_display)) ->addSubmitButton(pht('Send SMS')) ->addCancelButton($cancel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/contact/PhabricatorAuthContactNumberController.php
src/applications/auth/controller/contact/PhabricatorAuthContactNumberController.php
<?php abstract class PhabricatorAuthContactNumberController extends PhabricatorAuthController { // Users may need to access these controllers to enroll in SMS MFA during // account setup. public function shouldRequireMultiFactorEnrollment() { return false; } public function shouldRequireEnabledUser() { return false; } public function shouldRequireEmailVerification() { return false; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $crumbs->addTextCrumb( pht('Contact Numbers'), pht('/settings/panel/contact/')); return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/contact/PhabricatorAuthContactNumberDisableController.php
src/applications/auth/controller/contact/PhabricatorAuthContactNumberDisableController.php
<?php final class PhabricatorAuthContactNumberDisableController extends PhabricatorAuthContactNumberController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $number = id(new PhabricatorAuthContactNumberQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$number) { return new Aphront404Response(); } $is_disable = ($request->getURIData('action') == 'disable'); $id = $number->getID(); $cancel_uri = $number->getURI(); if ($request->isFormOrHisecPost()) { $xactions = array(); if ($is_disable) { $new_status = PhabricatorAuthContactNumber::STATUS_DISABLED; } else { $new_status = PhabricatorAuthContactNumber::STATUS_ACTIVE; } $xactions[] = id(new PhabricatorAuthContactNumberTransaction()) ->setTransactionType( PhabricatorAuthContactNumberStatusTransaction::TRANSACTIONTYPE) ->setNewValue($new_status); $editor = id(new PhabricatorAuthContactNumberEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->setCancelURI($cancel_uri); try { $editor->applyTransactions($number, $xactions); } catch (PhabricatorApplicationTransactionValidationException $ex) { // This happens when you enable a number which collides with another // number. return $this->newDialog() ->setTitle(pht('Changing Status Failed')) ->setValidationException($ex) ->addCancelButton($cancel_uri); } return id(new AphrontRedirectResponse())->setURI($cancel_uri); } $number_display = phutil_tag( 'strong', array(), $number->getDisplayName()); if ($is_disable) { $title = pht('Disable Contact Number'); $body = pht( 'Disable the contact number %s?', $number_display); $button = pht('Disable Number'); } else { $title = pht('Enable Contact Number'); $body = pht( 'Enable the contact number %s?', $number_display); $button = pht('Enable Number'); } return $this->newDialog() ->setTitle($title) ->appendParagraph($body) ->addSubmitButton($button) ->addCancelButton($cancel_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/auth/controller/contact/PhabricatorAuthContactNumberViewController.php
src/applications/auth/controller/contact/PhabricatorAuthContactNumberViewController.php
<?php final class PhabricatorAuthContactNumberViewController extends PhabricatorAuthContactNumberController { public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $number = id(new PhabricatorAuthContactNumberQuery()) ->setViewer($viewer) ->withIDs(array($request->getURIData('id'))) ->executeOne(); if (!$number) { return new Aphront404Response(); } $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb($number->getObjectName()) ->setBorder(true); $header = $this->buildHeaderView($number); $properties = $this->buildPropertiesView($number); $curtain = $this->buildCurtain($number); $timeline = $this->buildTransactionTimeline( $number, new PhabricatorAuthContactNumberTransactionQuery()); $timeline->setShouldTerminate(true); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->setMainColumn( array( $timeline, )) ->addPropertySection(pht('Details'), $properties); return $this->newPage() ->setTitle($number->getDisplayName()) ->setCrumbs($crumbs) ->setPageObjectPHIDs( array( $number->getPHID(), )) ->appendChild($view); } private function buildHeaderView(PhabricatorAuthContactNumber $number) { $viewer = $this->getViewer(); $view = id(new PHUIHeaderView()) ->setViewer($viewer) ->setHeader($number->getObjectName()) ->setPolicyObject($number); if ($number->isDisabled()) { $view->setStatus('fa-ban', 'red', pht('Disabled')); } else if ($number->getIsPrimary()) { $view->setStatus('fa-certificate', 'blue', pht('Primary')); } return $view; } private function buildPropertiesView( PhabricatorAuthContactNumber $number) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView()) ->setViewer($viewer); $view->addProperty( pht('Owner'), $viewer->renderHandle($number->getObjectPHID())); $view->addProperty(pht('Contact Number'), $number->getDisplayName()); return $view; } private function buildCurtain(PhabricatorAuthContactNumber $number) { $viewer = $this->getViewer(); $id = $number->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $number, PhabricatorPolicyCapability::CAN_EDIT); $curtain = $this->newCurtainView($number); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Contact Number')) ->setIcon('fa-pencil') ->setHref($this->getApplicationURI("contact/edit/{$id}/")) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Send Test Message')) ->setIcon('fa-envelope-o') ->setHref($this->getApplicationURI("contact/test/{$id}/")) ->setDisabled(!$can_edit) ->setWorkflow(true)); if ($number->isDisabled()) { $disable_uri = $this->getApplicationURI("contact/enable/{$id}/"); $disable_name = pht('Enable Contact Number'); $disable_icon = 'fa-check'; $can_primary = false; } else { $disable_uri = $this->getApplicationURI("contact/disable/{$id}/"); $disable_name = pht('Disable Contact Number'); $disable_icon = 'fa-ban'; $can_primary = !$number->getIsPrimary(); } $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Make Primary Number')) ->setIcon('fa-certificate') ->setHref($this->getApplicationURI("contact/primary/{$id}/")) ->setDisabled(!$can_primary) ->setWorkflow(true)); $curtain->addAction( id(new PhabricatorActionView()) ->setName($disable_name) ->setIcon($disable_icon) ->setHref($disable_uri) ->setWorkflow(true)); return $curtain; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false