Account : All request with Doctrine

This commit is contained in:
Michael RICOIS 2016-10-19 09:55:28 +02:00
parent ae57b0ba50
commit a2287cbabf

View File

@ -34,35 +34,35 @@ class Account extends Scores_Ws_Server
// --- Enregistrement authentification OK // --- Enregistrement authentification OK
try { try {
$authLogM = new Application_Model_Sdv1UtilisateursAuthLog(); $this->conn->insert('sdv1.utilisateurs_auth_log', array(
$authLogM->insert(array(
'login' => $login, 'login' => $login,
'authenticate' => 'OK', 'authenticate' => 'OK',
'ip' => $ip, 'ip' => $ip,
'dateInsert' => date('YmdHis'), 'dateInsert' => date('YmdHis'),
)); ));
} catch (Zend_Db_Exception $e) {} } catch (\Doctrine\DBAL\DBALException $e) {}
// --- Check App authorization - Find Service parameters // --- Check App authorization - Find Service parameters
$serviceM = new Application_Model_Sdv1ClientsServices(); $sql = "SELECT * FROM sdv1.clients_services
$sql = $serviceM->select() WHERE IdClient = :clientId AND Code = :serviceCode";
->where('IdClient=?', $this->User->idClient) $stmt = $this->conn->prepare($sql);
->where('Code=?', $this->User->serviceCode); $stmt->bindValue('clientId', $this->User->idClient);
$serviceParams = $serviceM->fetchRow($sql); $stmt->bindValue('serviceCode', $this->User->serviceCode);
$stmt->execute();
$serviceParams = $stmt->fetch(\PDO::FETCH_OBJ);
// --- Enregistrement informations navigateur uniquement si bien identifié // --- Enregistrement informations navigateur uniquement si bien identifié
if ($browser !== null) { if ($browser !== null) {
try { try {
$browserLogM = new Application_Model_Sdv1UtilisateursBrowserLog(); $this->conn->insert('sdv1.utilisateurs_browser_log', array(
$browserLogM->insert(array(
'clientId' => $this->User->idClient, 'clientId' => $this->User->idClient,
'userId' => $this->User->id, 'userId' => $this->User->id,
'service' => $this->User->serviceCode, 'service' => $this->User->serviceCode,
'login' => $this->User->login, 'login' => $this->User->login,
'userAgent' => $browser, 'userAgent' => $browser,
)); ));
} catch (Zend_Db_Exception $e) { } catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -136,16 +136,18 @@ class Account extends Scores_Ws_Server
* Extract login from database * Extract login from database
*/ */
try { try {
$userM = new Application_Model_Sdv1Utilisateurs(); $sql = "SELECT u.id, u.login, u.idClient, u.actif, c.actif AS clientActif,
$sql = $userM->select() s.Service AS serviceCode
->setIntegrityCheck(false) FROM sdv1.utilisateurs u, sdv1.clients c
->from(array('u'=>'utilisateurs'), array('u.id', 'u.login', 'u.idClient', 'u.actif',)) LEFT JOIN sdv1.utilisateurs_service ON u.login=s.login
->join(array('c'=>'clients'), 'u.idClient = c.id', array('c.actif AS clientActif')) WHERE u.login = :login AND c.id = :clientId";
->joinLeft(array('s'=>'sdv1.utilisateurs_service'), 'u.login=s.login', array('Service AS serviceCode')) $stmt = $this->conn->prepare($sql);
->where('u.login=?', $login) $stmt->bindValue('login', $login);
->where('c.id=?', $client); $stmt->bindValue('clientId', $client);
$result = $userM->fetchRow($sql); $stmt->execute();
} catch (Zend_Db_Exception $e) { $result = $stmt->fetch(\PDO::FETCH_OBJ);
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -209,10 +211,13 @@ class Account extends Scores_Ws_Server
//Generate random password //Generate random password
$hash = password_hash ( uniqid() , PASSWORD_BCRYPT ); $hash = password_hash ( uniqid() , PASSWORD_BCRYPT );
try { try {
$userM->update(array('password' => $hash), 'id='.$result->id); $this->conn->update('sdv1.utilisateurs',
} catch (Zend_Db_Exception $e) { array('password' => $hash), array('id' => $result->id));
}
catch (\Doctrine\DBAL\DBALException $e) {
throw new SoapFault('SSO', "Activation de l'utilisateur impossible"); throw new SoapFault('SSO', "Activation de l'utilisateur impossible");
} }
return $hash; return $hash;
} }
@ -232,18 +237,12 @@ class Account extends Scores_Ws_Server
throw new SoapFault('ERR', 'Accès non authorisé'); throw new SoapFault('ERR', 'Accès non authorisé');
} }
$clientM = new Application_Model_Sdv1Clients(); $sql = "SELECT nom AS Nom, LPAD(siren,9,0) AS Siren, LPAD(nic,5,0) AS Nic,
$sql = $clientM->select(true)->columns(array( IF(actif='Oui',1,0) AS Actif, IF(test='Oui',1,0) AS Test
'nom AS Nom', FROM sdv1.clients WHERE actif='Oui'";
'LPAD(siren,9,0) AS Siren', $stmt = $this->conn->executeQuery($sql);
'LPAD(nic,5,0) AS Nic', if ($stmt->rowCount() > 0) {
'IF(actif="Oui",1,0) AS Actif', while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
'IF(test="Oui",1,0) AS Test'
))->where('actif=?', 'Oui');
$result = $clientM->fetchAll($sql);
if ( count($result) > 0 ) {
foreach ( $result as $item ) {
$client = new Client(); $client = new Client();
$client->Nom = $item->Nom; $client->Nom = $item->Nom;
$client->Siren = $item->Siren; $client->Siren = $item->Siren;
@ -273,19 +272,17 @@ class Account extends Scores_Ws_Server
$id = $this->User->idClient; $id = $this->User->idClient;
} }
$clientM = new Application_Model_Sdv1Clients(); $sql = "SELECT nom AS Nom, LPAD(siren,9,0) AS Siren, LPAD(nic,5,0) AS Nic,
$sql = $clientM->select(true)->columns(array( IF(actif='Oui',1,0) AS Actif, IF(test='Oui',1,0) AS Test
'nom AS Nom', FROM sdv1.clients WHERE id= :id";
'LPAD(siren,9,0) AS Siren', $stmt = $this->conn->prepare($sql);
'LPAD(nic,5,0) AS Nic', $stmt->bindValue('id', $id);
'IF(actif="Oui",1,0) AS Actif', $stmt->execute();
'IF(test="Oui",1,0) AS Test'
))->where('id=?', $id);
$result = $clientM->fetchRow($sql);
if ( $result === null ) { if ($stmt->rowCount() == 0) {
throw new SoapFault('ERR', 'Information client introuvable.'); throw new SoapFault('ERR', 'Information client introuvable.');
} }
$result = $stmt->fetch(\PDO::FETCH_OBJ);
$client = new Client(); $client = new Client();
$client->Nom = $result->Nom; $client->Nom = $result->Nom;
@ -312,19 +309,17 @@ class Account extends Scores_Ws_Server
$id = $this->User->idClient; $id = $this->User->idClient;
} }
$clientM = new Application_Model_Sdv1Clients(); $sql = "SELECT nom AS Nom, LPAD(siren,9,0) AS Siren, LPAD(nic,5,0) AS Nic,
$sql = $clientM->select()->from($clientM, array( IF(actif='Oui',1,0) AS Actif, IF(test='Oui',1,0) AS Test
'nom AS Nom', FROM sdv1.clients WHERE id= :id";
'LPAD(siren,9,0) AS Siren', $stmt = $this->conn->prepare($sql);
'LPAD(nic,5,0) AS Nic', $stmt->bindValue('id', $id);
'IF(actif="Oui",1,0) AS Actif', $stmt->execute();
'IF(test="Oui",1,0) AS Test'
))->where('id=?', $id);
$result = $clientM->fetchRow($sql);
if ( $result === null ) { if ($stmt->rowCount() == 0) {
throw new SoapFault('ERR', 'Information client introuvable.'); throw new SoapFault('ERR', 'Information client introuvable.');
} }
$result = $stmt->fetch(\PDO::FETCH_OBJ);
$client = new ClientServices(); $client = new ClientServices();
$client->Nom = $result->Nom; $client->Nom = $result->Nom;
@ -334,16 +329,14 @@ class Account extends Scores_Ws_Server
$client->Test = $result->Test; $client->Test = $result->Test;
//Get Services //Get Services
$serviceM = new Application_Model_Sdv1ClientsServices(); $sql = "SELECT id, Code, Label, Editable, Active FROM sdv1.clients_services
$sql = $serviceM->select() WHERE Deleted = 0 AND Active = 1 AND IdClient = :clientId";
->from($serviceM, array('id', 'Code', 'Label', 'Editable', 'Active')) $stmt = $this->conn->prepare($sql);
->where('Deleted=?', 0) $stmt->bindValue('clientId', $id);
->where('Active=?', 1) $stmt->execute();
->where('IdClient=?', $id);
$result = $serviceM->fetchAll($sql);
$services = array(); $services = array();
if (count($result) > 0) { if ($stmt->rowCount() > 0) {
foreach ($result as $item) { while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$clientService = new ClientServicesList(); $clientService = new ClientServicesList();
$clientService->id = $item->id; $clientService->id = $item->id;
$clientService->Code = $item->Code; $clientService->Code = $item->Code;
@ -400,11 +393,12 @@ class Account extends Scores_Ws_Server
throw new SoapFault('ERR', 'Accès non authorisé'); throw new SoapFault('ERR', 'Accès non authorisé');
} }
$serviceM = new Application_Model_Sdv1ClientsServices();
try { try {
$serviceSql = $serviceM->select()->where('IdClient=?', $client) ->where('Deleted=?', 0); $sql = "SELECT * FROM sdv1.clients_services WHERE Deleted = 0 AND IdClient = :clientId";
$serviceResult = $serviceM->fetchAll($serviceSql); $stmt = $this->conn->prepare($sql);
} catch (Zend_Db_Exception $e) { $stmt->bindValue('clientId', $client);
$stmt->execute();
} catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -412,8 +406,8 @@ class Account extends Scores_Ws_Server
} }
} }
$services = array(); $services = array();
if ( count($serviceResult) > 0 ) { if ($stmt->rowCount() > 0) {
foreach ($serviceResult as $item) { while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$service = new ServiceList(); $service = new ServiceList();
$service->id = $item->id; $service->id = $item->id;
$service->IdClient = $item->IdClient; $service->IdClient = $item->IdClient;
@ -448,11 +442,15 @@ class Account extends Scores_Ws_Server
$client = $this->User->idClient; $client = $this->User->idClient;
// Détail d'un service // Détail d'un service
$serviceM = new Application_Model_Sdv1ClientsServices();
try { try {
$sql = $serviceM->select()->where('IdClient=?', $client)->where('Deleted=?', 0)->where('Code=?', $code); $sql = "SELECT * FROM sdv1.clients_services
$result = $serviceM->fetchRow($sql); WHERE Deleted = 0 AND IdClient = :clientId AND Code = :serviceCode";
} catch (Zend_Db_Exception $e) { $stmt = $this->conn->prepare($sql);
$stmt->bindValue('clientId', $client);
$stmt->bindValue('serviceCode', $code);
$stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -460,9 +458,10 @@ class Account extends Scores_Ws_Server
} }
} }
if ( $result === null ) { if ($stmt->rowCount() == 0) {
throw new SoapFault('ERR', 'Service introuvable.'); throw new SoapFault('ERR', 'Service introuvable.');
} }
$result = $stmt->fetch(\PDO::FETCH_OBJ);
$output = new Service(); $output = new Service();
$output->id = $result->id; $output->id = $result->id;
@ -482,19 +481,23 @@ class Account extends Scores_Ws_Server
// Droits // Droits
$output->Acces = array(); $output->Acces = array();
$serviceDroitsM = new Application_Model_Sdv1ClientsServicesDroits();
try { try {
$sql = $serviceDroitsM->select()->where('IdClient=?', $client)->where('Service=?', $serviceCode); $sql = "SELECT * FROM sdv1.clients_services_droits
$result = $serviceDroitsM->fetchAll($sql); WHERE IdClient = :clientId AND Service = :serviceCode";
} catch (Zend_Db_Exception $e) { $stmt = $this->conn->prepare($sql);
$stmt->bindValue('clientId', $client);
$stmt->bindValue('serviceCode', $serviceCode);
$stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', "Application error"); throw new SoapFault('ERR', "Application error");
} }
} }
if (count($result) > 0) { if ($stmt->rowCount() > 0) {
foreach ($result as $item) { while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$acces = new Acces(); $acces = new Acces();
$acces->Code = strtoupper($item->Acces); $acces->Code = strtoupper($item->Acces);
$acces->Label = $this->listeDroits[strtoupper($item->Acces)]; $acces->Label = $this->listeDroits[strtoupper($item->Acces)];
@ -504,19 +507,23 @@ class Account extends Scores_Ws_Server
// IP // IP
$output->IP = array(); $output->IP = array();
$serviceIPM = new Application_Model_Sdv1ClientsServicesIP();
try { try {
$sql = $serviceIPM->select()->where('IdClient=?', $client)->where('Service=?', $serviceCode); $sql = "SELECT * FROM sdv1.clients_services_ip
$result = $serviceIPM->fetchAll($sql); WHERE IdClient = :clientId AND Service = :serviceCode";
} catch (Zend_Db_Exception $e) { $stmt = $this->conn->prepare($sql);
$stmt->bindValue('clientId', $client);
$stmt->bindValue('serviceCode', $serviceCode);
$stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', "Application error"); throw new SoapFault('ERR', "Application error");
} }
} }
if (count($result) > 0) { if ($stmt->rowCount() > 0) {
foreach ($result as $item) { while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$output->IP[] = $item->IP; $output->IP[] = $item->IP;
} }
} }
@ -548,16 +555,26 @@ class Account extends Scores_Ws_Server
$client = $this->User->idClient; $client = $this->User->idClient;
// --- Définir les éléments du service // --- Définir les éléments du service
$serviceM = new Application_Model_Sdv1ClientsServices(); try {
$sql = $serviceM->select() $sql = "SELECT * FROM sdv1.clients_services
->where('IdClient=?', $client) WHERE Deleted = 0 AND IdClient = :clientId AND id = :id";
->where('Deleted=?', 0) $stmt = $this->conn->prepare($sql);
->where('id=?', $id); $stmt->bindValue('clientId', $client);
$result = $serviceM->fetchRow($sql); $stmt->bindValue('id', $id);
$stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
if ( $result === null ) { if ($stmt->rowCount() == 0) {
throw new SoapFault('ERR', "Service introuvable."); throw new SoapFault('ERR', "Service introuvable.");
} }
$result = $stmt->fetch(\PDO::FETCH_OBJ);
if ( $result->Editable == 0) { if ( $result->Editable == 0) {
throw new SoapFault('MSG', "Impossible d'éditer le service"); throw new SoapFault('MSG', "Impossible d'éditer le service");
@ -579,12 +596,13 @@ class Account extends Scores_Ws_Server
$dataToUpdate = array('Label' => $value); $dataToUpdate = array('Label' => $value);
} }
if ( count($dataToUpdate) > 0 ) { if (($dataToUpdate) > 0) {
$dataToUpdate['DateUpdate'] = date('YmdHis'); $dataToUpdate['DateUpdate'] = date('YmdHis');
try { try {
$serviceM->update($dataToUpdate, 'id='.$id); $this->conn->update('sdv1.clients_services', $dataToUpdate, array('id' => $id));
return true; return true;
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -622,13 +640,14 @@ class Account extends Scores_Ws_Server
$client = $this->User->idClient; $client = $this->User->idClient;
try { try {
$serviceM = new Application_Model_Sdv1ClientsServices(); $sql = "SELECT * FROM sdv1.clients_services
$sql = $serviceM->select() WHERE Deleted = 0 AND IdClient = :clientId AND id = :id";
->where('IdClient=?', $client) $stmt = $this->conn->prepare($sql);
->where('Deleted=?', 0) $stmt->bindValue('clientId', $client);
->where('id=?', $id); $stmt->bindValue('id', $id);
$result = $serviceM->fetchRow($sql); $stmt->execute();
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -636,9 +655,10 @@ class Account extends Scores_Ws_Server
} }
} }
if ( $result === null ) { if ($stmt->rowCount() == 0) {
throw new SoapFault('ERR', "Service introuvable."); throw new SoapFault('ERR', "Service introuvable.");
} }
$result = $stmt->fetch(\PDO::FETCH_OBJ);
if ( $result->Editable == 0) { if ( $result->Editable == 0) {
throw new SoapFault('MSG', "Impossible d'éditer le service"); throw new SoapFault('MSG', "Impossible d'éditer le service");
@ -647,25 +667,28 @@ class Account extends Scores_Ws_Server
// --- Acces // --- Acces
if ($type == 'acces') { if ($type == 'acces') {
if (array_key_exists($value, $this->listeDroits)) { if (array_key_exists($value, $this->listeDroits)) {
$accesM = new Application_Model_Sdv1ClientsServicesDroits();
if ($delete === true) { if ($delete === true) {
try { try {
$row = $accesM->delete(array( $row = $this->conn->delete('sdv1.clients_services_droits', array(
'IdClient="'.$result->IdClient.'"', 'IdClient' => $result->IdClient,
'Service="'.$result->Code.'"', 'Service' => $result->Code,
'Acces="'.$value.'"', 'Acces' => $value,
)); ));
if ($row > 0) { if ($row > 0) {
return true; return true;
} }
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
}
}
} else { } else {
throw new SoapFault('ERR', "Application error");
}
}
}
else {
try { try {
$row = $accesM->insert(array( $row = $this->conn->insert('sdv1.clients_services_droits', array(
'IdClient' => $result->IdClient, 'IdClient' => $result->IdClient,
'Service' => $result->Code, 'Service' => $result->Code,
'Acces' => $value, 'Acces' => $value,
@ -674,9 +697,12 @@ class Account extends Scores_Ws_Server
if ($row > 0 ) { if ($row > 0 ) {
return true; return true;
} }
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
} }
} }
} }
@ -685,14 +711,13 @@ class Account extends Scores_Ws_Server
// --- IP // --- IP
if ($type == 'ip') { if ($type == 'ip') {
$ipM = new Application_Model_Sdv1ClientsServicesIP();
if ($delete) { if ($delete) {
$row = $ipM->delete('id='.$id); $row = $this->conn->delete('sdv1.clients_services_ip', array('id' => $id));
} else { } else {
//Control de la plage IP ou de l'IP //Control de la plage IP ou de l'IP
$validate = new Zend_Validate_Ip(); $validate = new Zend_Validate_Ip();
if ( $validate->isValid($value) ) { if ( $validate->isValid($value) ) {
$row = $accessM->insert(array( $this->conn->insert('sdv1.clients_services_ip', array(
'IdClient' => $result->IdClient, 'IdClient' => $result->IdClient,
'Service' => $result->Code, 'Service' => $result->Code,
'IP' => $value, 'IP' => $value,
@ -736,26 +761,27 @@ class Account extends Scores_Ws_Server
} }
try { try {
$userM = new Application_Model_Sdv1Utilisateurs(); $qb = $this->conn->createQueryBuilder();
$sql = $userM->select() $qb->select(array('u.id', 'u.idClient', 'u.login', 'u.email', 'u.civilite', 'u.nom',
->setIntegrityCheck(false) 'u.prenom', 'u.actif', 'u.deleted', 's.Service', 'sd.Label'))
->from(array('u'=>'sdv1.utilisateurs'), array('id','idClient','login','email','civilite','nom','prenom','actif','deleted')) ->leftJoin('u', 'sdv1.utilisateurs_service', 's', 'u.login=s.login')
->joinLeft(array('s'=>'sdv1.utilisateurs_service'), 'u.login=s.login', array('Service')) ->leftJoin('u', 'sdv1.clients_services', 'sd', 'sd.Code=s.Service')
->joinLeft(array('sd'=>'sdv1.clients_services'), 'sd.Code=s.Service', array('Label')) ->from('sdv1.utilisateurs', 'u')
->where('u.idClient=?', $client); ->where('u.idClient = :clientId');
if ( $actif !== null && in_array($actif, array(0,1)) ) { if ( $actif !== null && in_array($actif, array(0,1)) ) {
$sql->where('u.actif=?', $actif); $qb->andWhere('u.actif = :actif')->setParameter('actif', $actif);
} }
$sql->where('u.deleted=?', 0); $qb->andWhere('u.deleted = 0');
if ($service == 'DEFAULT') { if ($service == 'DEFAULT') {
$sql->where('(s.Service IS NULL) OR (s.Service="DEFAULT" AND sd.idClient='.$client.')'); $qb->andWhere("(s.Service IS NULL) OR (s.Service='DEFAULT' AND sd.idClient=:clientId)");
} else { } else {
$sql->where('sd.Code=?', $service); $qb->andWhere('sd.Code = :serviceCode')->setParameter('serviceCode', $service);
} }
$result = $userM->fetchAll($sql); $qb->setParameter('clientId', $client);
} catch (Zend_Db_Exception $e) { $stmt = $qb->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -764,8 +790,8 @@ class Account extends Scores_Ws_Server
} }
$users = array(); $users = array();
if (count($result) > 0) { if ($stmt->rowCount() > 0) {
foreach ($result as $item) { while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$user = new UserList(); $user = new UserList();
$user->id = $item->id; $user->id = $item->id;
$user->IdClient = $item->idClient; $user->IdClient = $item->idClient;
@ -812,15 +838,16 @@ class Account extends Scores_Ws_Server
// Get Data // Get Data
try { try {
$userM = new Application_Model_Sdv1Utilisateurs(); $qb = $this->conn->createQueryBuilder();
$sql = $userM->select()->from(array('u'=>'utilisateurs')) $qb->select('*')
->setIntegrityCheck(false) ->leftJoin('u', 'sdv1.utilisateurs_service', 's', 'u.login=s.login')
->joinLeft(array('s'=>'sdv1.utilisateurs_service'), 'u.login=s.login', array('Service')) ->leftJoin('u', 'sdv1.clients_services', 'sd', 'sd.Code=s.Service')
->joinLeft(array('sd'=>'sdv1.clients_services'), 'sd.Code=s.Service', array('Label AS ServiceLabel')) ->from('sdv1.utilisateurs', 'u')
->where('u.id=?', $id); ->where('u.id = :id');
$qb->setParameter('id', $id);
$user = $userM->fetchRow($sql); $stmt = $qb->execute();
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -828,9 +855,11 @@ class Account extends Scores_Ws_Server
} }
} }
if ( $user === null ) {
if ($stmt->rowCount() == 0) {
throw new SoapFault('ERR', 'Utilisateur inexistant !'); throw new SoapFault('ERR', 'Utilisateur inexistant !');
} }
$user = $stmt->fetch(\PDO::FETCH_OBJ);
// Service // Service
$serviceCode = 'DEFAULT'; $serviceCode = 'DEFAULT';
@ -870,18 +899,23 @@ class Account extends Scores_Ws_Server
// Service - Droits // Service - Droits
if (count($output->Acces) == 0) { if (count($output->Acces) == 0) {
try { try {
$droitsM = new Application_Model_Sdv1ClientsServicesDroits(); $sql = "SELECT * FROM sdv1.clients_services_droits
$sql = $droitsM->select()->where('IdClient=?', $idClient)->where('Service=?', $serviceCode); WHERE IdClient = :clientId AND Service = :serviceCode";
$droits = $droitsM->fetchAll($sql); $stmt = $this->conn->prepare($sql);
} catch (Zend_Db_Exception $e) { $stmt->bindValue('clientId', $idClient);
$stmt->bindValue('serviceCode', $serviceCode);
$stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', "Application error"); throw new SoapFault('ERR', "Application error");
} }
} }
if ( count($droits) > 0 ) {
foreach ($droits as $item) { if ($stmt->rowCount() > 0) {
while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$acces = new Acces(); $acces = new Acces();
$acces->Code = strtoupper($item->Acces); $acces->Code = strtoupper($item->Acces);
$acces->Label = $this->listeDroits[strtoupper($item->Acces)]; $acces->Label = $this->listeDroits[strtoupper($item->Acces)];
@ -892,18 +926,22 @@ class Account extends Scores_Ws_Server
// Service - IP // Service - IP
try { try {
$ipM = new Application_Model_Sdv1ClientsServicesIP(); $sql = "SELECT * FROM sdv1.clients_services_ip
$sql = $ipM->select()->where('IdClient=?', $idClient)->where('Service=?', $serviceCode); WHERE IdClient = :clientId AND Service = :serviceCode";
$ips = $ipM->fetchAll($sql); $stmt = $this->conn->prepare($sql);
} catch (Zend_Db_Exception $e) { $stmt->bindValue('clientId', $idClient);
$stmt->bindValue('serviceCode', $serviceCode);
$stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', "Application error"); throw new SoapFault('ERR', "Application error");
} }
} }
if ( count($ips) > 0 ) { if ($stmt->rowCount() > 0) {
foreach ($ips as $item) { while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$output->IP[] = $item; $output->IP[] = $item;
} }
} }
@ -929,12 +967,14 @@ class Account extends Scores_Ws_Server
$idClient = $this->User->idClient; $idClient = $this->User->idClient;
try { try {
$emailsM = new Application_Model_Sdv1UtilisateursEmails(); $sql = "SELECT * FROM sdv1.utilisateurs_emails
$sql = $emailsM->select() WHERE IdClient = :clientId AND id = :id";
->where('id=?', $id) $stmt = $this->conn->prepare($sql);
->where('idClient=?', $idClient); $stmt->bindValue('clientId', $idClient);
$result = $emailsM->fetchAll($sql); $stmt->bindValue('id', $id);
} catch (Zend_Db_Exception $e) { $stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -943,8 +983,8 @@ class Account extends Scores_Ws_Server
} }
$emails = array(); $emails = array();
if ( count($result)>0 ) { if ($stmt->rowCount() > 0) {
foreach ( $result as $item ) { while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$email = new Email(); $email = new Email();
$email->id = $item->id; $email->id = $item->id;
$email->value = $item->email; $email->value = $item->email;
@ -977,20 +1017,19 @@ class Account extends Scores_Ws_Server
$item = 'identite'; $item = 'identite';
// --- Generate SQL
$logM = new Application_Model_Sdv1Logs();
$logSql = $logM->select(true)
->where('login=?', $this->User->login)
->where('page=?', $item)
->where('dateHeure BETWEEN "'.$selectedYear.'-'.$selectedMonth.'-00 00:00:00" AND "'.
$selectedYear.'-'.$selectedMonth.'-31 23:59:59"');
// --- Get total // --- Get total
try { try {
$cols = new Zend_Db_Expr("COUNT(*) AS NB"); $sql = "SELECT COUNT(*) AS NB FROM sdv1.logs
$logSql->columns($cols); WHERE login = :login AND page = :page AND dateHeure BETWEEN :begin AND :end";
$totalResult = $logM->fetchRow($logSql); $stmt = $this->conn->prepare($sql);
} catch (Zend_Db_Exception $e) { $stmt->bindValue('login', $this->User->login);
$stmt->bindValue('page', $item);
$stmt->bindValue('begin', $selectedYear.'-'.$selectedMonth.'-00 00:00:00');
$stmt->bindValue('end', $selectedYear.'-'.$selectedMonth.'-31 23:59:59');
$stmt->execute();
$totalResult = $stmt->fetch(\PDO::FETCH_OBJ);
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
@ -1005,17 +1044,27 @@ class Account extends Scores_Ws_Server
if ($totalResult->NB > 0) { if ($totalResult->NB > 0) {
// --- Get Row // --- Get Row
try { try {
$logSql->columns(array('LPAD(siren,9,0) AS siren', 'LPAD(nic,5,0) AS nic', 'raisonSociale')); $sql = "SELECT LPAD(siren,9,0) AS siren, LPAD(nic,5,0) AS nic, raisonSociale
$logSql->order('dateHeure DESC')->limitPage($p, $limit); FROM sdv1.logs
$logResult = $logM->fetchAll($logSql); WHERE login = :login AND page = :page AND dateHeure BETWEEN :begin AND :end
} catch (Zend_Db_Exception $e) { ORDER BY dateHeure DESC LIMIT $p, $limit";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('login', $this->User->login);
$stmt->bindValue('page', $item);
$stmt->bindValue('begin', $selectedYear.'-'.$selectedMonth.'-00 00:00:00');
$stmt->bindValue('end', $selectedYear.'-'.$selectedMonth.'-31 23:59:59');
$stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', "Application error"); throw new SoapFault('ERR', "Application error");
} }
} }
foreach ($logResult as $l) {
if ($stmt->rowCount() > 0) {
while($l = $stmt->fetch(\PDO::FETCH_OBJ)) {
$struct = new UserLogItem(); $struct = new UserLogItem();
$companyId = $l->siren; $companyId = $l->siren;
if (intval($l->nic) > 0) { if (intval($l->nic) > 0) {
@ -1028,6 +1077,7 @@ class Account extends Scores_Ws_Server
$output->List[] = $struct; $output->List[] = $struct;
} }
} }
}
return $output; return $output;
} }
@ -1055,10 +1105,8 @@ class Account extends Scores_Ws_Server
$logSql = "SELECT LPAD(x.siren,9,0) AS siren, LPAD(x.nic,5,0) AS nic, x.raisonSociale, x.dateHeure FROM logs x ". $logSql = "SELECT LPAD(x.siren,9,0) AS siren, LPAD(x.nic,5,0) AS nic, x.raisonSociale, x.dateHeure FROM logs x ".
"JOIN (".$logSubquery.") y ON y.siren = x.siren AND y.MaxDateHeure = x.dateHeure ". "JOIN (".$logSubquery.") y ON y.siren = x.siren AND y.MaxDateHeure = x.dateHeure ".
"ORDER BY x.dateHeure DESC LIMIT 0,".$limit; "ORDER BY x.dateHeure DESC LIMIT 0,".$limit;
$db = Zend_Db_Table_Abstract::getDefaultAdapter(); $stmt = $this->conn->executeQuery($logSql);
$db->setFetchMode(Zend_Db::FETCH_OBJ); while ($l = $stmt->fetch(\PDO::FETCH_OBJ)) {
$logResult = $db->fetchAll($logSql);
foreach ($logResult as $l) {
$struct = new UserLogItem(); $struct = new UserLogItem();
$companyId = $l->siren; $companyId = $l->siren;
if (intval($l->nic) > 0) { if (intval($l->nic) > 0) {
@ -1070,11 +1118,12 @@ class Account extends Scores_Ws_Server
$struct->Date = $l->dateHeure; $struct->Date = $l->dateHeure;
$output[] = $struct; $output[] = $struct;
} }
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', 'Application Error.'); throw new SoapFault('ERR', "Application error");
} }
} }
@ -1102,22 +1151,22 @@ class Account extends Scores_Ws_Server
$dateStart = $month.'-01 00:00:00'; $dateStart = $month.'-01 00:00:00';
$dateEnd = $month.'-31 23:59:59'; $dateEnd = $month.'-31 23:59:59';
// --- Generate SQL
$logM = new Application_Model_Sdv1UtilisateursAuthLog();
// --- Get total // --- Get total
$logSql = $logM->select()->from($logM, array())
->where('login=?', $this->User->login)
->where('authenticate=?', 'OK')
->where('dateInsert BETWEEN "'.$dateStart.'" AND "'.$dateEnd.'"');
$cols = new Zend_Db_Expr("COUNT(*) AS NB");
$logSql->columns($cols);
try { try {
$totalResult = $logM->fetchRow($logSql); $sql = "SELECT COUNT(*) AS NB FROM sdv1.utilisateurs_auth_log
} catch (Zend_Db_Exception $e) { WHERE login = :login AND authenticate = 'OK' AND dateInsert BETWEEN :begin AND :end";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('login', $this->User->login);
$stmt->bindValue('begin', $dateStart);
$stmt->bindValue('end', $dateEnd);
$stmt->execute();
$totalResult = $stmt->fetch(\PDO::FETCH_OBJ);
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', 'Application Error.'); throw new SoapFault('ERR', "Application error");
} }
} }
@ -1127,28 +1176,33 @@ class Account extends Scores_Ws_Server
if ($totalResult->NB > 0) { if ($totalResult->NB > 0) {
// --- Get Row // --- Get Row
$logSql = $logM->select()->from($logM, array())
->where('login=?', $this->User->login)
->where('authenticate=?', 'OK')
->where('dateInsert BETWEEN "'.$dateStart.'" AND "'.$dateEnd.'"');
$logSql->columns(array('IP', 'dateInsert AS Date'));
$logSql->order('dateInsert DESC')->limit($limit, $limit * $p);
try { try {
$logResult = $logM->fetchAll($logSql); $sql = "SELECT IP, dateInsert AS Date FROM sdv1.utilisateurs_auth_logs
} catch (Zend_Db_Exception $e) { WHERE login = :login AND authenticate = 'OK' AND dateInsert BETWEEN :begin AND :end
ORDER BY dateInsert DESC";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('login', $this->User->login);
$stmt->bindValue('begin', $dateStart);
$stmt->bindValue('end', $dateEnd);
$stmt->execute();
}
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', 'Application Error.'); throw new SoapFault('ERR', "Application error");
} }
} }
foreach ($logResult as $item) {
if ($stmt->rowCount() > 0) {
while($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
$struct = new AuthLogItem(); $struct = new AuthLogItem();
$struct->IP = $item->IP; $struct->IP = $item->IP;
$struct->Date = $item->Date; $struct->Date = $item->Date;
$output->List[] = $struct; $output->List[] = $struct;
} }
} }
}
return $output; return $output;
} }
@ -1172,8 +1226,6 @@ class Account extends Scores_Ws_Server
$values = json_decode($data); $values = json_decode($data);
$userM = new Application_Model_Sdv1Utilisateurs();
// --- Création // --- Création
if ( $id === null ) { if ( $id === null ) {
@ -1201,12 +1253,15 @@ class Account extends Scores_Ws_Server
'listeEven' => '', 'listeEven' => '',
); );
$sql = $userM->select()->where('login=?', $values->login);
$row = $userM->fetchRow($sql);
// --- Utilisateur existant // --- Utilisateur existant
if ( null !== $row ) { $sql = "SELECT id FROM sdv1.utilisateurs WHERE login = :login";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('login', $values->login);
$stmt->execute();
if ($stmt->rowCount() > 0) {
throw new SoapFault('ERR', "User exist"); throw new SoapFault('ERR', "User exist");
} }
// --- Prepare data to insert // --- Prepare data to insert
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
if (array_key_exists($key, $userData)) { if (array_key_exists($key, $userData)) {
@ -1216,28 +1271,29 @@ class Account extends Scores_Ws_Server
$userData['dateInsert'] = date('YmdHis'); $userData['dateInsert'] = date('YmdHis');
try { try {
$userM->insert($userData); $this->conn->insert('sdv1.utilisateurs', $userData);
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', 'Application Error.'); throw new SoapFault('ERR', "Application error");
} }
} }
//Définition du service //Définition du service
$serviceM = new Application_Model_Sdv1UtilisateursService();
try { try {
$serviceM->insert(array( $this->conn->insert('sdv1.utilisateurs_service', array(
'login' => $infos->login, 'login' => $infos->login,
'idClient'=> $infos->idClient, 'idClient'=> $infos->idClient,
'Service'=> $infos->Service 'Service'=> $infos->Service
)); ));
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', 'Application Error.'); throw new SoapFault('ERR', "Application error");
} }
} }
@ -1249,9 +1305,12 @@ class Account extends Scores_Ws_Server
$userData = array(); $userData = array();
$sql = $userM->select()->where('id=?', $id); $sql = "SELECT id FROM sdv1.utilisateurs WHERE id = :id";
$row = $userM->fetchRow($sql); $stmt = $this->conn->prepare($sql);
if ( null === $row ) { $stmt->bindValue('id', $id);
$stmt->execute();
if ($stmt->rowCount() == 0) {
throw new SoapFault('ERR', "User doesn't exist"); throw new SoapFault('ERR', "User doesn't exist");
} }
// --- Prepare data to update // --- Prepare data to update
@ -1260,12 +1319,13 @@ class Account extends Scores_Ws_Server
} }
try { try {
$nb = $userM->update($userData, 'id='.$id); $nb = $this->conn->update('sdv1.utilisateurs', $userData, array('id' => $id));
} catch (Zend_Db_Exception $e) { }
catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) { if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} else { } else {
throw new SoapFault('ERR', 'Application Error.'); throw new SoapFault('ERR', "Application error");
} }
} }
@ -1342,15 +1402,19 @@ class Account extends Scores_Ws_Server
); );
//Définition du service //Définition du service
$serviceM = new Application_Model_Sdv1UtilisateursService();
try { try {
$serviceM->insert(array( $this->conn->insert('sdv1.utilisateurs_service', array(
'login' => $infos->login, 'login' => $infos->login,
'idClient'=> $infos->idClient, 'idClient'=> $infos->idClient,
'Service'=> $infos->Service 'Service'=> $infos->Service
)); ));
} catch ( Zend_Db_Exception $e ) { }
return false; catch (\Doctrine\DBAL\DBALException $e) {
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
} }
//Prepare data to insert //Prepare data to insert
@ -1365,9 +1429,10 @@ class Account extends Scores_Ws_Server
//Insertion dans la base de données //Insertion dans la base de données
try { try {
$userM = new Application_Model_Sdv1Utilisateurs(); $this->conn->insert('sdv1.utilisateurs', $userData);
$userM->insert($userData);
} catch ( Zend_Db_Exception $e ) { }
catch (\Doctrine\DBAL\DBALException $e) {
return false; return false;
} }
@ -1409,15 +1474,16 @@ class Account extends Scores_Ws_Server
if ( $id === null ) { if ( $id === null ) {
$id = $this->User->id; $id = $this->User->id;
} elseif ( $id !== null && $this->User->profil != 'Administrateur' ) { }
elseif ( $id !== null && $this->User->profil != 'Administrateur' ) {
throw new SoapFault('ERR', 'Accès non authorisé'); throw new SoapFault('ERR', 'Accès non authorisé');
} }
//@todo : Prise en compte de la version //@todo : Prise en compte de la version
//Changer le mot de passe //Changer le mot de passe
$userM = new Application_Model_Sdv1Utilisateurs(); $result = $this->conn->update('sdv1.utilisateurs',
$result = $userM->update(array('password'=>$password), 'id='.$id); array('password'=>$password), array('id' => $id));
if ( $result == 1 ) { if ( $result == 1 ) {
return true; return true;
} }
@ -1479,13 +1545,14 @@ class Account extends Scores_Ws_Server
$id = $this->User->id; $id = $this->User->id;
try { try {
$userM = new Application_Model_Sdv1Utilisateurs(); $result = $this->conn->update('sdv1.utilisateurs', $data, array('id' => $id));
$data = array('acceptationCGU' => date('YmdHis')); }
$result = $userM->update($data, 'id='.$idUser); catch (\Doctrine\DBAL\DBALException $e) {
} catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) {
throw new SoapFault('Erreur', $e->getMessage()); throw new SoapFault('ERR', $e->getMessage());
} catch (Zend_Exception $e) { } else {
throw new SoapFault('Erreur', $e->getMessage()); throw new SoapFault('ERR', "Application error");
}
} }
if ( 1 == $result ) { if ( 1 == $result ) {
return true; return true;
@ -1496,7 +1563,7 @@ class Account extends Scores_Ws_Server
protected function setUserEnable($id) protected function setUserEnable($id)
{ {
//Un administrateur force l'activation d'un utilisateur ? //Un administrateur force l'activation d'un utilisateur ?
$userM = new Application_Model_Sdv1Utilisateurs();
//actif = 1 //actif = 1
/** /**
@ -1520,7 +1587,7 @@ class Account extends Scores_Ws_Server
{ {
//Un utilisateur valide son compte pour la première connexion et déclenche l'envoi de validation de l'email //Un utilisateur valide son compte pour la première connexion et déclenche l'envoi de validation de l'email
//Doit-on demander un nouveau mot de passe ? Est ce que le mot de passe a été générer et envoyé par email . //Doit-on demander un nouveau mot de passe ? Est ce que le mot de passe a été générer et envoyé par email .
$userM = new Application_Model_Sdv1Utilisateurs();
//actif = 0 //actif = 0
//dateValidation pour email //dateValidation pour email