1<?php 2 3/** 4 * DokuWiki Plugin authcas (Action Component) 5 * 6 * Intercepts the 'login' action and redirects the user to the cas server login page 7 * instead of showing the login form. 8 * 9 * @author Mathieu Hetru <mathieu.hetru@univ-lille.fr> 10 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 11 * @link https://github.com/l3-team/dokuwiki-extensions-authcas 12 */ 13 14// must be run within Dokuwiki 15if (! defined('DOKU_INC')) 16 die(); 17 18if (! defined('DOKU_LF')) 19 define('DOKU_LF', "\n"); 20if (! defined('DOKU_TAB')) 21 define('DOKU_TAB', "\t"); 22if (! defined('DOKU_PLUGIN')) 23 define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 24 25require_once DOKU_PLUGIN . 'action.php'; 26require_once DOKU_PLUGIN . 'auth.php'; 27 28 29class action_plugin_authcas extends DokuWiki_Action_Plugin 30{ 31 32 var $authcasplugin = null; 33 34 function action_plugin_authcas() { 35 $this->authcasplugin = plugin_load('auth', 'authcas'); 36 } 37 38 public function register(Doku_Event_Handler $controller) 39 { 40 $this->authcasplugin = plugin_load('auth', 'authcas'); 41 if($this->getConf('displayDokuLoginForm')) { 42 $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'addCasToLoginForm', array()); 43 } else { 44 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'redirectToCasLogin'); 45 } 46 } 47 48 function addCasToLoginForm(&$event, $param) 49 { 50 $this->authcasplugin = plugin_load('auth', 'authcas'); 51 $caslink = '<p><br/><a href="'.$this->authcasplugin->getLoginURL().'">'.$this->getLang('connection').'</a></p>'; 52 $pos = $event->data->findElementById('form', 'dw__login'); 53 $event->data->insertElement($pos-1, $caslink); 54 55 } 56 57 58 public function redirectToCasLogin(&$event, $param) 59 { 60 $this->authcasplugin = plugin_load('auth', 'authcas'); 61 global $ACT; 62 if ($ACT == 'login') { 63 //used instead of $auth if use of authsplit or authchained 64 $this->authcasplugin->logIn(); 65 } 66 } 67} 68