[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/auth/controller/config/ -> PhabricatorAuthNewController.php (source)

   1  <?php
   2  
   3  final class PhabricatorAuthNewController
   4    extends PhabricatorAuthProviderConfigController {
   5  
   6    public function processRequest() {
   7      $request = $this->getRequest();
   8      $viewer = $request->getUser();
   9  
  10      $providers = PhabricatorAuthProvider::getAllBaseProviders();
  11  
  12      $e_provider = null;
  13      $errors = array();
  14  
  15      if ($request->isFormPost()) {
  16        $provider_string = $request->getStr('provider');
  17        if (!strlen($provider_string)) {
  18          $e_provider = pht('Required');
  19          $errors[] = pht('You must select an authentication provider.');
  20        } else {
  21          $found = false;
  22          foreach ($providers as $provider) {
  23            if (get_class($provider) === $provider_string) {
  24              $found = true;
  25              break;
  26            }
  27          }
  28          if (!$found) {
  29            $e_provider = pht('Invalid');
  30            $errors[] = pht('You must select a valid provider.');
  31          }
  32        }
  33  
  34        if (!$errors) {
  35          return id(new AphrontRedirectResponse())->setURI(
  36            $this->getApplicationURI('/config/new/'.$provider_string.'/'));
  37        }
  38      }
  39  
  40      $options = id(new AphrontFormRadioButtonControl())
  41        ->setLabel(pht('Provider'))
  42        ->setName('provider')
  43        ->setError($e_provider);
  44  
  45      $configured = PhabricatorAuthProvider::getAllProviders();
  46      $configured_classes = array();
  47      foreach ($configured as $configured_provider) {
  48        $configured_classes[get_class($configured_provider)] = true;
  49      }
  50  
  51      // Sort providers by login order, and move disabled providers to the
  52      // bottom.
  53      $providers = msort($providers, 'getLoginOrder');
  54      $providers = array_diff_key($providers, $configured_classes) + $providers;
  55  
  56      foreach ($providers as $provider) {
  57        if (isset($configured_classes[get_class($provider)])) {
  58          $disabled = true;
  59          $description = pht('This provider is already configured.');
  60        } else {
  61          $disabled = false;
  62          $description = $provider->getDescriptionForCreate();
  63        }
  64        $options->addButton(
  65          get_class($provider),
  66          $provider->getNameForCreate(),
  67          $description,
  68          $disabled ? 'disabled' : null,
  69          $disabled);
  70      }
  71  
  72      $form = id(new AphrontFormView())
  73        ->setUser($viewer)
  74        ->appendChild($options)
  75        ->appendChild(
  76          id(new AphrontFormSubmitControl())
  77            ->addCancelButton($this->getApplicationURI())
  78            ->setValue(pht('Continue')));
  79  
  80      $form_box = id(new PHUIObjectBoxView())
  81        ->setHeaderText(pht('Add Authentication Provider'))
  82        ->setFormErrors($errors)
  83        ->setForm($form);
  84  
  85      $crumbs = $this->buildApplicationCrumbs();
  86      $crumbs->addTextCrumb(pht('Add Provider'));
  87  
  88      return $this->buildApplicationPage(
  89        array(
  90          $crumbs,
  91          $form_box,
  92        ),
  93        array(
  94          'title' => pht('Add Authentication Provider'),
  95        ));
  96    }
  97  
  98  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1