Path: blob/master/src/applications/auth/controller/PhabricatorAuthLinkController.php
12256 views
<?php12final class PhabricatorAuthLinkController3extends PhabricatorAuthController {45public function handleRequest(AphrontRequest $request) {6$viewer = $this->getViewer();7$action = $request->getURIData('action');89$id = $request->getURIData('id');1011$config = id(new PhabricatorAuthProviderConfigQuery())12->setViewer($viewer)13->withIDs(array($id))14->withIsEnabled(true)15->executeOne();16if (!$config) {17return new Aphront404Response();18}1920$provider = $config->getProvider();2122switch ($action) {23case 'link':24if (!$provider->shouldAllowAccountLink()) {25return $this->renderErrorPage(26pht('Account Not Linkable'),27array(28pht('This provider is not configured to allow linking.'),29));30}31break;32case 'refresh':33if (!$provider->shouldAllowAccountRefresh()) {34return $this->renderErrorPage(35pht('Account Not Refreshable'),36array(37pht('This provider does not allow refreshing.'),38));39}40break;41default:42return new Aphront400Response();43}4445$accounts = id(new PhabricatorExternalAccountQuery())46->setViewer($viewer)47->withUserPHIDs(array($viewer->getPHID()))48->withProviderConfigPHIDs(array($config->getPHID()))49->execute();5051switch ($action) {52case 'link':53if ($accounts) {54return $this->renderErrorPage(55pht('Account Already Linked'),56array(57pht(58'Your account is already linked to an external account for '.59'this provider.'),60));61}62break;63case 'refresh':64if (!$accounts) {65return $this->renderErrorPage(66pht('No Account Linked'),67array(68pht(69'You do not have a linked account on this provider, and thus '.70'can not refresh it.'),71));72}73break;74default:75return new Aphront400Response();76}7778$panel_uri = '/settings/panel/external/';7980PhabricatorCookies::setClientIDCookie($request);8182switch ($action) {83case 'link':84$form = $provider->buildLinkForm($this);85break;86case 'refresh':87$form = $provider->buildRefreshForm($this);88break;89default:90return new Aphront400Response();91}9293if ($provider->isLoginFormAButton()) {94require_celerity_resource('auth-css');95$form = phutil_tag(96'div',97array(98'class' => 'phabricator-link-button pl',99),100$form);101}102103switch ($action) {104case 'link':105$name = pht('Link Account');106$title = pht('Link %s Account', $provider->getProviderName());107break;108case 'refresh':109$name = pht('Refresh Account');110$title = pht('Refresh %s Account', $provider->getProviderName());111break;112default:113return new Aphront400Response();114}115116$crumbs = $this->buildApplicationCrumbs();117$crumbs->addTextCrumb(pht('Link Account'), $panel_uri);118$crumbs->addTextCrumb($provider->getProviderName($name));119$crumbs->setBorder(true);120121return $this->newPage()122->setTitle($title)123->setCrumbs($crumbs)124->appendChild($form);125}126127}128129130