From 7b55c53ecd5698d1a9a5f04fd49f1c7b1d134a6a Mon Sep 17 00:00:00 2001 From: gustavo2804 <92757784+gustavo2804@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:43:45 -0400 Subject: [PATCH] correcion login, tableName en dataAccess y agregado de guardar cedula en sessionDataAccess --- src/Model/Base/DataAccess.php | 57 +++++++++++++++----- src/Model/Base/DataAccessManager.php | 8 ++- src/Model/User/LoginPage.php | 9 +++- src/Model/User/PersonaDataAccess.php | 17 ++++-- src/Model/User/SessionDataAccess.php | 5 +- tests/testAislado.php | 78 ++++++++++++++++++++++++++++ tests/testLogin.php | 17 ++++++ 7 files changed, 171 insertions(+), 20 deletions(-) create mode 100644 tests/testAislado.php create mode 100644 tests/testLogin.php diff --git a/src/Model/Base/DataAccess.php b/src/Model/Base/DataAccess.php index 76a6f31..35ba3c3 100644 --- a/src/Model/Base/DataAccess.php +++ b/src/Model/Base/DataAccess.php @@ -217,42 +217,73 @@ public static function initFromDataAccessManager(DataAccessManager $dataAccessMa } - public function __construct($p_db, $options = null) + public function __construct($p_db, $options) { - $debug = false; + $debug = true; $this->db = $p_db; $this->dataAccessorName = get_class($this); - + + if($debug) + { + error_log("esto es dataAccessorName: ".$this->dataAccessorName); + } $this->_actions = []; $this->_allowsCreation = true; - $this->register(); - + + + if($options["tableName"]) + { + $this->tableName=$options["tableName"]; + } + + $this->register();//no hace nada en DataAccess + $this->dataMapping->setDataAccessor($this); if ($this->tableName) { $this->dataMapping->tableName = $this->tableName; + + if($debug) + { + error_log("esto es dataMapping->tableName: ".$this->dataMapping->tableName); + } + } global $_GLOBALS; + + if (isset($_GLOBALS["RUN_CREATE_TABLE"])) { $runCreateTable = $_GLOBALS["RUN_CREATE_TABLE"]; + if($debug) + { + error_log("runCreateTable si es true: ".$runCreateTable); + } } else { - $runCreateTable = true; + $runCreateTable = false; + } - + { + error_log("valor de options: ".$options); + } + if ($options) { - $runCreateTable = arrayValueIfExists("runCreateTable", $options); + //$runCreateTable = arrayValueIfExists("runCreateTable", $options); } + if($debug) + { + error_log("runcreatetable si es false: ".$runCreateTable); + } if ($runCreateTable) { @@ -265,6 +296,11 @@ public function __construct($p_db, $options = null) if ($this->isSqlite()) { $this->createTable(); + if ($debug) + { + error_log("Did create table"); + } + } } @@ -276,10 +312,7 @@ public function __construct($p_db, $options = null) } } - if ($debug) - { - error_log("Did create table"); - } + if (method_exists($this, "migrate")) { diff --git a/src/Model/Base/DataAccessManager.php b/src/Model/Base/DataAccessManager.php index 59c12cf..47e8352 100644 --- a/src/Model/Base/DataAccessManager.php +++ b/src/Model/Base/DataAccessManager.php @@ -462,10 +462,14 @@ public function getDatabaseInstance($dbName) public function getDataAccessor($name, $throwException = true) { - if (!array_key_exists($name, $this->dataAccessors)) + $debug=true; + if (!array_key_exists($name, $this->dataAccessors)) { $key = $this->keyForDataAccessorConstructions($name); - + if($debug) + { + error_log($key); + } // if (!isset($this->dataAccessorConstructions[$name])) if (!$key) { diff --git a/src/Model/User/LoginPage.php b/src/Model/User/LoginPage.php index d190411..a4a8aa2 100644 --- a/src/Model/User/LoginPage.php +++ b/src/Model/User/LoginPage.php @@ -103,6 +103,9 @@ public function loginUser($userName, $password, $pDelegate = null) if (!$user) { $user = $user_data_access->getOne($key, $userName); + if($debug){ + error_log("el usuario ingresado fue: ".print_r($user,true)); + } } else { @@ -115,8 +118,12 @@ public function loginUser($userName, $password, $pDelegate = null) return $delegate->userDoesNotExist(); } - if (!$user_data_access->isActive($user)) + if ($user_data_access->isActive($user)) { + if($debug) + { + error_log("no esta activo"); + } return $delegate->userDoesNotExist(); } diff --git a/src/Model/User/PersonaDataAccess.php b/src/Model/User/PersonaDataAccess.php index c726056..87b8582 100644 --- a/src/Model/User/PersonaDataAccess.php +++ b/src/Model/User/PersonaDataAccess.php @@ -495,18 +495,29 @@ public function toggleUserActiveByUserAndUserItem($user, $item) public function isActive($user) { + $debug=1; if (!$user) { return false; } $activeValue = $this->valueForKey("estado", $user); - - if ($activeValue != "activo") + if ($debug) + { + error_log("este usuario esta: ".$activeValue); + } + if ($activeValue !== "activo") { + if($debug) + { + error_log("false"); + } return false; } - + if($debug) + { + error_log("true"); + } return true; } diff --git a/src/Model/User/SessionDataAccess.php b/src/Model/User/SessionDataAccess.php index 4eeace6..3ca2a49 100644 --- a/src/Model/User/SessionDataAccess.php +++ b/src/Model/User/SessionDataAccess.php @@ -252,9 +252,9 @@ function guidv4($data = null) { public function newSessionForUser($user) { $query = "INSERT INTO {$this->tableName()} - (session_guid, user_id, created_at, valid_until, canceled) + (cedula, session_guid, user_id, created_at, valid_until, canceled) VALUES - (:session_guid, :user_id, :created_at, :valid_until, :canceled)"; + (:cedula ,:session_guid, :user_id, :created_at, :valid_until, :canceled)"; $statement = $this->getDB()->prepare($query); @@ -262,6 +262,7 @@ public function newSessionForUser($user) $defaultSessionLength = 60 * 60 * 24 * 30; // 30 days + $statement->bindValue(':cedula', DataAccessManager::get("persona")->valueForKey("cedula", $user)); $statement->bindValue(':session_guid', $session_value); $statement->bindValue(':user_id', DataAccessManager::get("persona")->valueForKey("id", $user)); $statement->bindValue(':created_at', date(DATE_ATOM)); diff --git a/tests/testAislado.php b/tests/testAislado.php new file mode 100644 index 0000000..b31a5b0 --- /dev/null +++ b/tests/testAislado.php @@ -0,0 +1,78 @@ + [ + "DEV", + "AGENCY", + "SOFTWARE_ADMIN", + ], + "update" => [ + "DEV", + "AGENCY", + "SOFTWARE_ADMIN", + ], + "read" => [ + "SOFTWARE_ADMIN", + ], + "none" => [ + "ACCOUNTANTS", + "DISPATCHERS", + ], +]; +$config =[ + "class" => "StonewoodPersona", + "db" => "appDB", + "permissions" => $agencyAdminPermissions, + "tableName" => "personas", +]; +$sqlitePdo = new PDO($db_path); +$sqlitePdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +// SETUP + +$dataAccess = new DataAccess($sqlitePdo, $config); + +DataAccessManager::get('persona') + + +$tableName = $dataAccess->tableName; +//NOTE USE PDO DIRECTLY + +// ($resultado, $esperado, $mensaje) +// testIsNull($resultado, "el resultado es: ".$resultado) +IF ($tableName != "personas") +{ + die("no se asigno correctamente el valor de tablename se obtuvo: ". $tableName ); +}else +{ + error_log("tableName: ".$tableName); +} +//TEAR DOWN \ No newline at end of file diff --git a/tests/testLogin.php b/tests/testLogin.php new file mode 100644 index 0000000..b56785a --- /dev/null +++ b/tests/testLogin.php @@ -0,0 +1,17 @@ +