1741b8a48SAndreas Gohr<?php 2741b8a48SAndreas Gohr/** 3741b8a48SAndreas Gohr * DokuWiki Plugin addomain (Action Component) 4741b8a48SAndreas Gohr * 5741b8a48SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6741b8a48SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 7741b8a48SAndreas Gohr */ 8741b8a48SAndreas Gohr 9741b8a48SAndreas Gohr/** 10741b8a48SAndreas Gohr * Class action_plugin_addomain 11741b8a48SAndreas Gohr */ 12*a4337320SAndreas Gohrclass action_plugin_authad extends DokuWiki_Action_Plugin 13*a4337320SAndreas Gohr{ 14741b8a48SAndreas Gohr 15741b8a48SAndreas Gohr /** 16741b8a48SAndreas Gohr * Registers a callback function for a given event 17741b8a48SAndreas Gohr */ 18*a4337320SAndreas Gohr public function register(Doku_Event_Handler $controller) 19*a4337320SAndreas Gohr { 20741b8a48SAndreas Gohr 21*a4337320SAndreas Gohr $controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE', $this, 'handleAuthLoginCheck'); 22*a4337320SAndreas Gohr $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handleHtmlLoginformOutput'); 23741b8a48SAndreas Gohr } 24741b8a48SAndreas Gohr 25741b8a48SAndreas Gohr /** 26741b8a48SAndreas Gohr * Adds the selected domain as user postfix when attempting a login 27741b8a48SAndreas Gohr * 28741b8a48SAndreas Gohr * @param Doku_Event $event 29741b8a48SAndreas Gohr * @param array $param 30741b8a48SAndreas Gohr */ 31*a4337320SAndreas Gohr public function handleAuthLoginCheck(Doku_Event $event, $param) 32*a4337320SAndreas Gohr { 33741b8a48SAndreas Gohr global $INPUT; 34741b8a48SAndreas Gohr 35741b8a48SAndreas Gohr /** @var auth_plugin_authad $auth */ 36741b8a48SAndreas Gohr global $auth; 37741b8a48SAndreas Gohr if (!is_a($auth, 'auth_plugin_authad')) return; // AD not even used 38741b8a48SAndreas Gohr 39741b8a48SAndreas Gohr if ($INPUT->str('dom')) { 40741b8a48SAndreas Gohr $usr = $auth->cleanUser($event->data['user']); 41*a4337320SAndreas Gohr $dom = $auth->getUserDomain($usr); 42741b8a48SAndreas Gohr if (!$dom) { 43741b8a48SAndreas Gohr $usr = "$usr@".$INPUT->str('dom'); 44741b8a48SAndreas Gohr } 45741b8a48SAndreas Gohr $INPUT->post->set('u', $usr); 46741b8a48SAndreas Gohr $event->data['user'] = $usr; 47741b8a48SAndreas Gohr } 48741b8a48SAndreas Gohr } 49741b8a48SAndreas Gohr 50741b8a48SAndreas Gohr /** 51741b8a48SAndreas Gohr * Shows a domain selection in the login form when more than one domain is configured 52741b8a48SAndreas Gohr * 53741b8a48SAndreas Gohr * @param Doku_Event $event 54741b8a48SAndreas Gohr * @param array $param 55741b8a48SAndreas Gohr */ 56*a4337320SAndreas Gohr public function handleHtmlLoginformOutput(Doku_Event $event, $param) 57*a4337320SAndreas Gohr { 58741b8a48SAndreas Gohr global $INPUT; 59741b8a48SAndreas Gohr /** @var auth_plugin_authad $auth */ 60741b8a48SAndreas Gohr global $auth; 61741b8a48SAndreas Gohr if (!is_a($auth, 'auth_plugin_authad')) return; // AD not even used 62*a4337320SAndreas Gohr $domains = $auth->getConfiguredDomains(); 63741b8a48SAndreas Gohr if (count($domains) <= 1) return; // no choice at all 64741b8a48SAndreas Gohr 65741b8a48SAndreas Gohr /** @var Doku_Form $form */ 66741b8a48SAndreas Gohr $form =& $event->data; 67741b8a48SAndreas Gohr 68741b8a48SAndreas Gohr // any default? 69741b8a48SAndreas Gohr $dom = ''; 70741b8a48SAndreas Gohr if ($INPUT->has('u')) { 71741b8a48SAndreas Gohr $usr = $auth->cleanUser($INPUT->str('u')); 72*a4337320SAndreas Gohr $dom = $auth->getUserDomain($usr); 73741b8a48SAndreas Gohr 74741b8a48SAndreas Gohr // update user field value 75741b8a48SAndreas Gohr if ($dom) { 76*a4337320SAndreas Gohr $usr = $auth->getUserName($usr); 77741b8a48SAndreas Gohr $pos = $form->findElementByAttribute('name', 'u'); 78741b8a48SAndreas Gohr $ele =& $form->getElementAt($pos); 79741b8a48SAndreas Gohr $ele['value'] = $usr; 80741b8a48SAndreas Gohr } 81741b8a48SAndreas Gohr } 82741b8a48SAndreas Gohr 83741b8a48SAndreas Gohr // add select box 84741b8a48SAndreas Gohr $element = form_makeListboxField('dom', $domains, $dom, $this->getLang('domain'), '', 'block'); 85741b8a48SAndreas Gohr $pos = $form->findElementByAttribute('name', 'p'); 86741b8a48SAndreas Gohr $form->insertElement($pos + 1, $element); 87741b8a48SAndreas Gohr } 88741b8a48SAndreas Gohr} 89741b8a48SAndreas Gohr 90741b8a48SAndreas Gohr// vim:ts=4:sw=4:et: 91