Path: blob/master/src/applications/auth/controller/config/PhabricatorAuthNewController.php
12261 views
<?php12final class PhabricatorAuthNewController3extends PhabricatorAuthProviderConfigController {45public function handleRequest(AphrontRequest $request) {6$this->requireApplicationCapability(7AuthManageProvidersCapability::CAPABILITY);89$viewer = $this->getViewer();10$cancel_uri = $this->getApplicationURI();11$locked_config_key = 'auth.lock-config';12$is_locked = PhabricatorEnv::getEnvConfig($locked_config_key);1314if ($is_locked) {15$message = pht(16'Authentication provider configuration is locked, and can not be '.17'changed without being unlocked. See the configuration setting %s '.18'for details.',19phutil_tag(20'a',21array(22'href' => '/config/edit/'.$locked_config_key,23),24$locked_config_key));2526return $this->newDialog()27->setUser($viewer)28->setTitle(pht('Authentication Config Locked'))29->appendChild($message)30->addCancelButton($cancel_uri);31}3233$providers = PhabricatorAuthProvider::getAllBaseProviders();3435$configured = PhabricatorAuthProvider::getAllProviders();36$configured_classes = array();37foreach ($configured as $configured_provider) {38$configured_classes[get_class($configured_provider)] = true;39}4041// Sort providers by login order, and move disabled providers to the42// bottom.43$providers = msort($providers, 'getLoginOrder');44$providers = array_diff_key($providers, $configured_classes) + $providers;4546$menu = id(new PHUIObjectItemListView())47->setViewer($viewer)48->setBig(true)49->setFlush(true);5051foreach ($providers as $provider_key => $provider) {52$provider_class = get_class($provider);5354$provider_uri = id(new PhutilURI('/config/edit/'))55->replaceQueryParam('provider', $provider_class);56$provider_uri = $this->getApplicationURI($provider_uri);5758$already_exists = isset($configured_classes[get_class($provider)]);5960$item = id(new PHUIObjectItemView())61->setHeader($provider->getNameForCreate())62->setImageIcon($provider->newIconView())63->addAttribute($provider->getDescriptionForCreate());6465if (!$already_exists) {66$item67->setHref($provider_uri)68->setClickable(true);69} else {70$item->setDisabled(true);71}7273if ($already_exists) {74$messages = array();75$messages[] = pht('You already have a provider of this type.');7677$info = id(new PHUIInfoView())78->setSeverity(PHUIInfoView::SEVERITY_WARNING)79->setErrors($messages);8081$item->appendChild($info);82}8384$menu->addItem($item);85}8687return $this->newDialog()88->setTitle(pht('Add Auth Provider'))89->setWidth(AphrontDialogView::WIDTH_FORM)90->appendChild($menu)91->addCancelButton($cancel_uri);92}9394}959697