[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/config/core/Setting/ -> SettingAuthtype.php (source)

   1  <?php
   2  
   3  namespace dokuwiki\plugin\config\core\Setting;
   4  
   5  /**
   6   * Class setting_authtype
   7   */
   8  class SettingAuthtype extends SettingMultichoice {
   9  
  10      /** @inheritdoc */
  11      public function initialize($default = null, $local = null, $protected = null) {
  12          /** @var $plugin_controller \dokuwiki\Extension\PluginController */
  13          global $plugin_controller;
  14  
  15          // retrieve auth types provided by plugins
  16          foreach($plugin_controller->getList('auth') as $plugin) {
  17              $this->choices[] = $plugin;
  18          }
  19  
  20          parent::initialize($default, $local, $protected);
  21      }
  22  
  23      /** @inheritdoc */
  24      public function update($input) {
  25          /** @var $plugin_controller \dokuwiki\Extension\PluginController */
  26          global $plugin_controller;
  27  
  28          // is an update possible/requested?
  29          $local = $this->local;                       // save this, parent::update() may change it
  30          if(!parent::update($input)) return false;    // nothing changed or an error caught by parent
  31          $this->local = $local;                       // restore original, more error checking to come
  32  
  33          // attempt to load the plugin
  34          $auth_plugin = $plugin_controller->load('auth', $input);
  35  
  36          // @TODO: throw an error in plugin controller instead of returning null
  37          if(is_null($auth_plugin)) {
  38              $this->error = true;
  39              msg('Cannot load Auth Plugin "' . $input . '"', -1);
  40              return false;
  41          }
  42  
  43          // verify proper instantiation (is this really a plugin?) @TODO use instanceof? implement interface?
  44          if(is_object($auth_plugin) && !method_exists($auth_plugin, 'getPluginName')) {
  45              $this->error = true;
  46              msg('Cannot create Auth Plugin "' . $input . '"', -1);
  47              return false;
  48          }
  49  
  50          // did we change the auth type? logout
  51          global $conf;
  52          if($conf['authtype'] != $input) {
  53              msg('Authentication system changed. Please re-login.');
  54              auth_logoff();
  55          }
  56  
  57          $this->local = $input;
  58          return true;
  59      }
  60  }