Skip to content

Commit

Permalink
Try to add hook in main login page
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Mar 3, 2012
1 parent 585f386 commit 0dbef2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 40 deletions.
49 changes: 15 additions & 34 deletions htdocs/core/lib/security2.lib.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand All @@ -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='';
Expand Down
16 changes: 10 additions & 6 deletions htdocs/core/tpl/login.tpl.php
Expand Up @@ -234,14 +234,18 @@ function FindDstSwitchDate(year, month)
<input id="password" name="password" class="flat" type="password" size="15" maxlength="30" value="<?php echo $password; ?>" tabindex="2" />
</td></tr>

<?php if ($select_entity) { ?>
<tr><td valign="top" nowrap="nowrap"> &nbsp; <strong><?php echo $langs->trans('Entity'); ?></strong> &nbsp; </td>
<td valign="top" nowrap="nowrap">
<?php echo $select_entity; ?>
</td></tr>
<?php } ?>
<?php
if (! empty($hookmanager->resArray['options'])) {
foreach ($hookmanager->resArray['options'] as $option)
{
echo '<!-- Option by hook -->';
echo $option;
}
}
?>

<?php if ($captcha) { ?>
<!-- Captcha -->
<tr><td valign="middle" nowrap="nowrap"> &nbsp; <b><?php echo $langs->trans('SecurityCode'); ?></b></td>
<td valign="top" nowrap="nowrap" align="left" class="none">

Expand Down

0 comments on commit 0dbef2d

Please sign in to comment.