From 0e7d0d00f1e27d492c79ba1d0c0babdf11eb083b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 May 2011 13:45:51 +0000 Subject: [PATCH] Qual: Clean code of login methods Fix: Share same method for point of sale and rest of dolibarr --- htdocs/cashdesk/class/Auth.class.php | 146 ++++++++----------- htdocs/cashdesk/css/style.css | 5 +- htdocs/cashdesk/index.php | 11 +- htdocs/cashdesk/index_verif.php | 10 +- htdocs/includes/login/functions_dolibarr.php | 29 ++-- htdocs/langs/fr_FR/cashdesk.lang | 2 +- htdocs/lib/security.lib.php | 10 +- htdocs/main.inc.php | 5 +- 8 files changed, 102 insertions(+), 116 deletions(-) diff --git a/htdocs/cashdesk/class/Auth.class.php b/htdocs/cashdesk/class/Auth.class.php index 53c3d0cae32..fed4771d528 100644 --- a/htdocs/cashdesk/class/Auth.class.php +++ b/htdocs/cashdesk/class/Auth.class.php @@ -56,102 +56,82 @@ class Auth { } - /** - * Authentification d'un demandeur - * @return (int) 0 = Ok; -1 = login incorrect; -2 = login ok, mais compte desactive; -10 = aucune entree trouvee dans la base - */ - function verif_utilisateurs () { + function verif ($aLogin, $aPasswd) + { + global $conf,$dolibarr_main_authentication,$langs; - global $conf; + $ret=-1; - // Verification des informations dans la base - $resql = $this->db->query ($this->sqlQuery); - if ($resql) - { - $num = $this->db->num_rows ($resql); + $login=''; - if ( $num ) { + // Authentication mode + if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr'; + // Authentication mode: forceuser + if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto'; - // fetchFirst - $ret=array(); - $tab = $this->db->fetch_array($resql); - foreach ( $tab as $cle => $valeur ) - { - $ret[$cle] = $valeur; - } - $tab=$ret; + // Set authmode + $authmode=explode(',',$dolibarr_main_authentication); - if ( ($tab['pass_crypted'] == md5 ($this->passwd)) || (($tab['pass'] == $this->passwd) && ($tab['pass'] != ''))) { + // No authentication mode + if (! sizeof($authmode) && empty($conf->login_method_modules)) + { + $langs->load('main'); + dol_print_error('',$langs->trans("ErrorConfigParameterNotDefined",'dolibarr_main_authentication')); + exit; + } - // On verifie que le compte soit bien actif - if ( $tab['statut'] ) { - $this->reponse(0); + $test=true; - } else { + // Validation of third party module login method + if (is_array($conf->login_method_modules) && !empty($conf->login_method_modules)) + { + include_once(DOL_DOCUMENT_ROOT . "/lib/security.lib.php"); + $login = getLoginMethod(); + if ($login) $test=false; + } - $this->reponse(-2); + // Validation tests user / password + // If ok, the variable will be initialized login + // If error, we will put error message in session under the name dol_loginmesg + $goontestloop=false; + if (isset($_SERVER["REMOTE_USER"]) && in_array('http',$authmode)) $goontestloop=true; + if (isset($aLogin) || GETPOST('openid_mode','alpha',1)) $goontestloop=true; - } + if ($test && $goontestloop) + { + foreach($authmode as $mode) + { + if ($test && $mode && ! $login) + { + $authfile=DOL_DOCUMENT_ROOT.'/includes/login/functions_'.$mode.'.php'; + $result=include_once($authfile); + if ($result) + { + $this->login ($aLogin); + $this->passwd ($aPasswd); + $entitytotest=$conf->entity; - } else { - - $this->reponse(-1); - - } - - } else { - - $this->reponse(-10); - - } - } - else - { - - } - - } - - function verif ($aLogin, $aPasswd) { - global $conf; - - $this->login ($aLogin); - $this->passwd ($aPasswd); - - $this->sqlQuery = "SELECT rowid, pass_crypted, statut"; - $this->sqlQuery.= " FROM ".MAIN_DB_PREFIX."user"; - $this->sqlQuery.= " WHERE login = '".$this->login."'"; - $this->sqlQuery.= " AND entity IN (0,".$conf->entity.")"; - - $this->verif_utilisateurs(); - - switch ($this->reponse) { - - default: - $ret = '-1'; - break; - - case 0: - $ret = '0'; - break; - - case -1: - $ret = '-1'; - break; - - case -2: - $ret = '-2'; - break; - - case -10: - $ret = '-10'; - break; - - } + $function='check_user_password_'.$mode; + $login=$function($aLogin,$aPasswd,$entitytotest); + if ($login) // Login is successfull + { + $test=false; + $dol_authmode=$mode; // This properties is defined only when logged to say what mode was successfully used + $ret=0; + } + } + else + { + dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR); + sleep(1); + $ret=-1; + } + } + } + } return $ret; - } } diff --git a/htdocs/cashdesk/css/style.css b/htdocs/cashdesk/css/style.css index 821e6caa9fa..ea193978fe6 100644 --- a/htdocs/cashdesk/css/style.css +++ b/htdocs/cashdesk/css/style.css @@ -23,7 +23,7 @@ body { margin: 0; padding: 0; text-align: center; - font: 0.7em Arial, Helvetica, sans-serif; + font: 0.7em verdana, arial, helvetica; } p { @@ -274,9 +274,10 @@ p.titre { position: absolute; } -/* --------------------- Listes d�roulantes ------------------- */ +/* --------------------- Combo lists ------------------- */ .select_design { width: 370px; + font-size: 12px verdana,arial,helvetica overflow: auto; } diff --git a/htdocs/cashdesk/index.php b/htdocs/cashdesk/index.php index d41b63ba3a4..cd5eb312ed5 100644 --- a/htdocs/cashdesk/index.php +++ b/htdocs/cashdesk/index.php @@ -1,6 +1,7 @@ - * Copyright (C) 2011 Juanjo Menent +/* Copyright (C) 2007-2008 Jeremie Ollivier + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2011 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,7 +68,7 @@ top_htmlhead('','',0,0,'',$arrayofcss);