1<?php 2/** 3 * CAS authentication plugin 4 * 5 * @licence GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Xylle, Fabian Bircher 7 * @version 0.0.3 8 * 9 */ 10 11 12use dokuwiki\Extension\ActionPlugin; 13 14class action_plugin_authssocas extends ActionPlugin 15{ 16 // https://www.dokuwiki.org/devel:plugins 17 // https://www.dokuwiki.org/devel:plugin_file_structure 18 // https://www.dokuwiki.org/devel:plugin_info 19 // https://www.dokuwiki.org/devel:auth_plugins 20 // https://www.dokuwiki.org/devel:events_list 21 // https://www.dokuwiki.org/devel:common_plugin_functions 22 // https://www.dokuwiki.org/devel:metadata 23 24 25 26 public function register(Doku_Event_Handler $controller): void 27 { 28 // Gestion des événements 29 // Création du formulaire de connexion 30 $controller->register_hook('FORM_LOGIN_OUTPUT', 'BEFORE', $this, 'handle_login_form'); 31 // Connexion et déconnexion 32 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action'); 33 } 34 35 /** 36 * 37 * Suppression du formulaire par défaut et création de celui pour le CAS 38 * 39 * @param Doku_Event $event 40 * @return void 41 */ 42 public function handle_login_form(Doku_Event $event): void 43 { 44 global $auth; 45 global $lang; 46 global $ID; 47 48 if (!is_a($auth, 'auth_plugin_authssocas')) return; 49 50 // Création du lien avec le logo. 51 if ($this->getConf('logourl') != '') { 52 $caslogo = '<img src="' . $this->getConf('logourl') . '" alt="" style="vertical-align: middle;" width="100"/> '; 53 } else { 54 $caslogo = ''; 55 } 56 57 /** @var dokuwiki\Form\Form $form */ 58 /** @noinspection PhpUndefinedFieldInspection */ 59 $form =& $event->data; 60 61 62 // Suppression du formulaire de base 63 for($i = $form->elementCount(); $i >= 0;){ 64 $form->removeElement($i); 65 $i--; 66 } 67 $login = wl($ID, 'do=caslogin', true, '&'); 68 69 // Ajout du lien d'authentification pour le CAS 70 $form->addFieldsetOpen($this->getConf('name')); 71 $form->addHTML('<p style="text-align: center;"><a href="' . $login . '"><div>' . $caslogo . '</div>' . $lang['btn_login'] . '</a></p>'); 72 $form->addFieldsetClose(); 73 } 74 75 76 /** 77 * 78 * Gestion des actions connexion et déconnexion 79 * 80 * @param Doku_Event $event 81 * @return void 82 */ 83 public function handle_action(Doku_Event $event): void 84 { 85 global $auth; 86 global $ID; 87 88 /** @noinspection PhpUndefinedFieldInspection */ 89 if ($event->data == 'caslogin') { 90 $auth->logIn(); 91 } 92 93 /** @noinspection PhpUndefinedFieldInspection */ 94 if ($event->data == 'logout') { 95 $auth->logOff(); 96 // Redirige vers la page d'acceuil du wiki, sinon le lien d'administration du wiki reste visible (pour les administrateurs). 97 header('Location: '. wl($ID,'',true)); 98 } 99 } 100 101} 102