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 */ 12a4337320SAndreas Gohrclass action_plugin_authad extends DokuWiki_Action_Plugin 13a4337320SAndreas Gohr{ 14741b8a48SAndreas Gohr 15741b8a48SAndreas Gohr /** 16741b8a48SAndreas Gohr * Registers a callback function for a given event 17741b8a48SAndreas Gohr */ 18a4337320SAndreas Gohr public function register(Doku_Event_Handler $controller) 19a4337320SAndreas Gohr { 20a4337320SAndreas Gohr $controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE', $this, 'handleAuthLoginCheck'); 21903616edSSatoshi Sahara $controller->register_hook('HTMLFORM_LOGIN_OUTPUT', 'BEFORE', $this, 'handleHtmlFormLoginOutput'); 22741b8a48SAndreas Gohr } 23741b8a48SAndreas Gohr 24741b8a48SAndreas Gohr /** 25741b8a48SAndreas Gohr * Adds the selected domain as user postfix when attempting a login 26741b8a48SAndreas Gohr * 27741b8a48SAndreas Gohr * @param Doku_Event $event 28741b8a48SAndreas Gohr * @param array $param 29741b8a48SAndreas Gohr */ 30a4337320SAndreas Gohr public function handleAuthLoginCheck(Doku_Event $event, $param) 31a4337320SAndreas Gohr { 32741b8a48SAndreas Gohr global $INPUT; 33741b8a48SAndreas Gohr 34741b8a48SAndreas Gohr /** @var auth_plugin_authad $auth */ 35741b8a48SAndreas Gohr global $auth; 36741b8a48SAndreas Gohr if (!is_a($auth, 'auth_plugin_authad')) return; // AD not even used 37741b8a48SAndreas Gohr 38741b8a48SAndreas Gohr if ($INPUT->str('dom')) { 39741b8a48SAndreas Gohr $usr = $auth->cleanUser($event->data['user']); 40a4337320SAndreas Gohr $dom = $auth->getUserDomain($usr); 41741b8a48SAndreas Gohr if (!$dom) { 42741b8a48SAndreas Gohr $usr = "$usr@".$INPUT->str('dom'); 43741b8a48SAndreas Gohr } 44741b8a48SAndreas Gohr $INPUT->post->set('u', $usr); 45741b8a48SAndreas Gohr $event->data['user'] = $usr; 46741b8a48SAndreas Gohr } 47741b8a48SAndreas Gohr } 48741b8a48SAndreas Gohr 49741b8a48SAndreas Gohr /** 50741b8a48SAndreas Gohr * Shows a domain selection in the login form when more than one domain is configured 51741b8a48SAndreas Gohr * 52741b8a48SAndreas Gohr * @param Doku_Event $event 53741b8a48SAndreas Gohr * @param array $param 54741b8a48SAndreas Gohr */ 55903616edSSatoshi Sahara public function handleHtmlFormLoginOutput(Doku_Event $event, $param) 56a4337320SAndreas Gohr { 57741b8a48SAndreas Gohr global $INPUT; 58741b8a48SAndreas Gohr /** @var auth_plugin_authad $auth */ 59741b8a48SAndreas Gohr global $auth; 60741b8a48SAndreas Gohr if (!is_a($auth, 'auth_plugin_authad')) return; // AD not even used 61a4337320SAndreas Gohr $domains = $auth->getConfiguredDomains(); 62741b8a48SAndreas Gohr if (count($domains) <= 1) return; // no choice at all 63741b8a48SAndreas Gohr 64*bde2a644SSatoshi Sahara /** @var dokuwiki\Form\Form $form */ 65741b8a48SAndreas Gohr $form =& $event->data; 66741b8a48SAndreas Gohr 67*bde2a644SSatoshi Sahara // find the username input box 68*bde2a644SSatoshi Sahara $pos = $form->findPositionByAttribute('name', 'u'); 69*bde2a644SSatoshi Sahara if ($pos === false) return; 70*bde2a644SSatoshi Sahara 71741b8a48SAndreas Gohr // any default? 72741b8a48SAndreas Gohr $dom = ''; 73741b8a48SAndreas Gohr if ($INPUT->has('u')) { 74741b8a48SAndreas Gohr $usr = $auth->cleanUser($INPUT->str('u')); 75a4337320SAndreas Gohr $dom = $auth->getUserDomain($usr); 76741b8a48SAndreas Gohr 77741b8a48SAndreas Gohr // update user field value 78741b8a48SAndreas Gohr if ($dom) { 79a4337320SAndreas Gohr $usr = $auth->getUserName($usr); 808549e2b5SSatoshi Sahara $element = $form->getElementAt($pos); 818549e2b5SSatoshi Sahara $element->val($usr); 82741b8a48SAndreas Gohr } 838549e2b5SSatoshi Sahara } 84741b8a48SAndreas Gohr 85903616edSSatoshi Sahara // add locate domain selector just after the username input box 86903616edSSatoshi Sahara $element = $form->addDropdown('dom', $domains, $this->getLang('domain'), $pos +1); 878549e2b5SSatoshi Sahara $element->addClass('block'); 88741b8a48SAndreas Gohr } 898549e2b5SSatoshi Sahara} 90741b8a48SAndreas Gohr 91741b8a48SAndreas Gohr// vim:ts=4:sw=4:et: 92