Fix: uniformize code
This commit is contained in:
parent
b320208d3a
commit
1411cbf9ca
@ -19,25 +19,18 @@
|
|||||||
|
|
||||||
class Auth {
|
class Auth {
|
||||||
|
|
||||||
|
protected $db;
|
||||||
|
|
||||||
protected $login;
|
protected $login;
|
||||||
protected $passwd;
|
protected $passwd;
|
||||||
|
|
||||||
protected $host;
|
|
||||||
protected $user;
|
|
||||||
protected $name;
|
|
||||||
protected $base;
|
|
||||||
|
|
||||||
protected $reponse;
|
protected $reponse;
|
||||||
|
|
||||||
protected $sql;
|
protected $sqlQuery;
|
||||||
|
|
||||||
public function __construct ($aHost, $aUser, $aPass, $aBase) {
|
public function __construct ($DB) {
|
||||||
|
|
||||||
$this->host = $aHost;
|
|
||||||
$this->user = $aUser;
|
|
||||||
$this->pass = $aPass;
|
|
||||||
$this->base = $aBase;
|
|
||||||
|
|
||||||
|
$this->db = $DB;
|
||||||
$this->reponse (null);
|
$this->reponse (null);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -53,34 +46,6 @@
|
|||||||
$this->passwd = $aPasswd;
|
$this->passwd = $aPasswd;
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function host ($aHost) {
|
|
||||||
|
|
||||||
$this->host = $aHost;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function user ($aUser) {
|
|
||||||
|
|
||||||
$this->user = $aUser;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function pass ($aPass) {
|
|
||||||
|
|
||||||
$this->pass = $aPass;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function base ($aBase) {
|
|
||||||
|
|
||||||
$this->base = $aBase;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reponse ($aReponse) {
|
public function reponse ($aReponse) {
|
||||||
@ -91,27 +56,23 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Authentification d'un demandeur
|
* Authentification d'un demandeur
|
||||||
* @return (int) 0 = Ok; -1 = login incorrect; -2 = login ok, mais compte d<EFBFBD>sactiv<EFBFBD>; -10 = aucune entr<EFBFBD>e trouv<EFBFBD>e dans la base
|
* @return (int) 0 = Ok; -1 = login incorrect; -2 = login ok, mais compte desactive; -10 = aucune entree trouvee dans la base
|
||||||
*/
|
*/
|
||||||
protected function verif_utilisateurs () {
|
protected function verif_utilisateurs () {
|
||||||
|
|
||||||
global $conf, $db;
|
global $conf;
|
||||||
|
|
||||||
//var_dump($conf->db);
|
|
||||||
//$sql = new Sql ($conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name);
|
|
||||||
$sql = $db;
|
|
||||||
|
|
||||||
// Verification des informations dans la base
|
// Verification des informations dans la base
|
||||||
$resql = $sql->query ($this->sql);
|
$resql = $this->db->query ($this->sqlQuery);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num = $sql->num_rows ($resql);
|
$num = $this->db->num_rows ($resql);
|
||||||
|
|
||||||
if ( $num ) {
|
if ( $num ) {
|
||||||
|
|
||||||
// fetchFirst
|
// fetchFirst
|
||||||
$ret=array();
|
$ret=array();
|
||||||
$tab = $sql->fetch_array($resql);
|
$tab = $this->db->fetch_array($resql);
|
||||||
foreach ( $tab as $cle => $valeur )
|
foreach ( $tab as $cle => $valeur )
|
||||||
{
|
{
|
||||||
$ret[$cle] = $valeur;
|
$ret[$cle] = $valeur;
|
||||||
@ -156,10 +117,10 @@
|
|||||||
$this->login ($aLogin);
|
$this->login ($aLogin);
|
||||||
$this->passwd ($aPasswd);
|
$this->passwd ($aPasswd);
|
||||||
|
|
||||||
$this->sql = "SELECT rowid, pass_crypted, statut
|
$this->sqlQuery = "SELECT rowid, pass_crypted, statut";
|
||||||
FROM ".MAIN_DB_PREFIX."user
|
$this->sqlQuery.= " FROM ".MAIN_DB_PREFIX."user";
|
||||||
WHERE login = '".$this->login."' and entity IN (0,".$conf->entity.")";
|
$this->sqlQuery.= " WHERE login = '".$this->login."'";
|
||||||
|
$this->sqlQuery.= " AND entity IN (0,".$conf->entity.")";
|
||||||
|
|
||||||
$this->verif_utilisateurs();
|
$this->verif_utilisateurs();
|
||||||
|
|
||||||
|
|||||||
@ -24,15 +24,12 @@ require ('classes/Auth.class.php');
|
|||||||
$username = $_POST['txtUsername'];
|
$username = $_POST['txtUsername'];
|
||||||
$password = $_POST['pwdPassword'];
|
$password = $_POST['pwdPassword'];
|
||||||
|
|
||||||
$auth = new Auth ($conf_db_host,$conf_db_user, $conf_db_pass, $conf_db_base );
|
$auth = new Auth($db);
|
||||||
|
|
||||||
$retour = $auth->verif ($username, $password);
|
$retour = $auth->verif ($username, $password);
|
||||||
|
|
||||||
if ( $retour >= 0 ) {
|
if ( $retour >= 0 ) {
|
||||||
|
|
||||||
// $db = mysql_connect ($conf_db_host,$conf_db_user, $conf_db_pass);
|
|
||||||
// mysql_select_db ($conf_db_base, $db);
|
|
||||||
|
|
||||||
$res=$sql->query (
|
$res=$sql->query (
|
||||||
"SELECT rowid, name, firstname
|
"SELECT rowid, name, firstname
|
||||||
FROM ".MAIN_DB_PREFIX."user
|
FROM ".MAIN_DB_PREFIX."user
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user