From 0dbef2d784fd4d91664cd60bc0d6438148b594db Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 3 Mar 2012 20:05:32 +0100 Subject: [PATCH] Try to add hook in main login page --- htdocs/core/lib/security2.lib.php | 49 ++++++++++--------------------- htdocs/core/tpl/login.tpl.php | 16 ++++++---- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index eb9156fd4b811..5a7c461dc1efb 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -162,7 +162,15 @@ function checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmod function dol_loginfunction($langs,$conf,$mysoc) { global $dolibarr_main_demo,$db; - global $smartphone,$mc; + global $smartphone,$hookmanager; + + // Instantiate hooks of thirdparty module only if not already define + if (! is_object($hookmanager)) + { + include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); + $hookmanager=new HookManager($db); + } + $hookmanager->initHooks(array('mainloginpage')); $langcode=(GETPOST('lang')?((is_object($langs)&&$langs->defaultlang)?$langs->defaultlang:'auto'):GETPOST('lang')); $langs->setDefaultLang($langcode); @@ -229,37 +237,18 @@ function dol_loginfunction($langs,$conf,$mysoc) $demologin=$tab[0]; $demopassword=$tab[1]; } - - // Entity cookie - if (! empty($conf->multicompany->enabled)) - { - $lastuser = ''; - $lastentity = $_POST['entity']; - - if (! empty($conf->global->MULTICOMPANY_COOKIE_ENABLED)) - { - $prefix=dol_getprefix(); - $entityCookieName = 'DOLENTITYID_'.$prefix; - if (isset($_COOKIE[$entityCookieName])) - { - include_once(DOL_DOCUMENT_ROOT . "/core/class/cookie.class.php"); - - $cryptkey = (! empty($conf->file->cookie_cryptkey) ? $conf->file->cookie_cryptkey : '' ); - - $entityCookie = new DolCookie($cryptkey); - $cookieValue = $entityCookie->_getCookie($entityCookieName); - list($lastuser, $lastentity) = explode('|', $cookieValue); - } - } - } + + // Execute hook getLoginPageOptions + // Should be an array with differents options in $hookmanager->resArray + $parameters=array('entity' => $_POST['entity']); + $hookmanager->executeHooks('getLoginPageOptions',$parameters); // Note that $action and $object may have been modified by some hooks // Login - $login = (!empty($lastuser)?$lastuser:(GETPOST("username","alpha",2)?GETPOST("username","alpha",2):$demologin)); + $login = (! empty($hookmanager->resArray['username']) ? $hookmanager->resArray['username'] : (GETPOST("username","alpha",2) ? GETPOST("username","alpha",2) : $demologin)); $password = $demopassword; // Show logo (search in order: small company logo, large company logo, theme logo, common logo) $width=0; - $rowspan=2; $urllogo=DOL_URL_ROOT.'/theme/login_logo.png'; if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) @@ -281,14 +270,6 @@ function dol_loginfunction($langs,$conf,$mysoc) } - // Entity field - $select_entity=''; - if (! empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_HIDE_LOGIN_COMBOBOX)) - { - $rowspan++; - $select_entity = $mc->select_entities($lastentity, 'entity', ' tabindex="3"', 1); - } - // Security graphical code $captcha=0; $captcha_refresh=''; diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index dfd8c2506d0f3..55a5f6f608de2 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -234,14 +234,18 @@ function FindDstSwitchDate(year, month) - -   trans('Entity'); ?>   - - - - +resArray['options'])) { + foreach ($hookmanager->resArray['options'] as $option) + { + echo ''; + echo $option; + } +} +?> +   trans('SecurityCode'); ?>