Skip to content

Commit

Permalink
Merge pull request #1 from gustavo2804/main
Browse files Browse the repository at this point in the history
correccion error de login
  • Loading branch information
mucholove authored Mar 12, 2024
2 parents fc2e02d + 7b55c53 commit ccda06e
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 20 deletions.
57 changes: 45 additions & 12 deletions src/Model/Base/DataAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -265,6 +296,11 @@ public function __construct($p_db, $options = null)
if ($this->isSqlite())
{
$this->createTable();
if ($debug)
{
error_log("Did create table");
}

}

}
Expand All @@ -276,10 +312,7 @@ public function __construct($p_db, $options = null)
}
}

if ($debug)
{
error_log("Did create table");
}


if (method_exists($this, "migrate"))
{
Expand Down
8 changes: 6 additions & 2 deletions src/Model/Base/DataAccessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 8 additions & 1 deletion src/Model/User/LoginPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}

Expand Down
17 changes: 14 additions & 3 deletions src/Model/User/PersonaDataAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down
5 changes: 3 additions & 2 deletions src/Model/User/SessionDataAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,17 @@ 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);

$session_value = uniqid();

$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));
Expand Down
78 changes: 78 additions & 0 deletions tests/testAislado.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
$dataAccessPath=dirname(__FILE__,2)."/src/Model/Base/DataAccess.php";
$dataAccessMPath=dirname(__FILE__,2)."/src/Model/Base/DataAccessManager.php";
$gtkColumnVirtualPath=dirname(__FILE__,2)."/src/Model/Base/GTKColumnVirtual.php";
$gtkColumnMappingPath=dirname(__FILE__,2)."/src/Model/Base/GTKColumnMapping.php";
$gtkColumnBasePath=dirname(__FILE__,2)."/src/Model/Base/GTKColumnBase.php";
$gtkDataSetPath=dirname(__FILE__,2)."/src/Model/Base/GTKDataSetMapping.php";
$personaDataAccessPath=dirname(__FILE__,2)."/src/Model/User/PersonaDataAccess.php";
$dataAccessActionPath=dirname(__FILE__,2)."/src/Model/Base/DataAccessAction.php";
$glangPath=dirname(__FILE__,2)."/src/Translations/Glang.php";
$langPath=dirname(__FILE__,2)."/configure/lang.php";
$arrayHelpersPath=dirname(__FILE__,2)."/vendor/gtk/gtk-helpers/src/lib/ArrayHelpers.php";
$ifRespondsPath=dirname(__FILE__,2)."/vendor/gtk/gtk-helpers/src/lib/ifResponds.php";
error_log($dataAccessPath);
require_once($arrayHelpersPath);
require_once($ifRespondsPath);
require_once($dataAccessPath);
require_once($dataAccessMPath);
require_once($personaDataAccessPath);
require_once($dataAccessActionPath);
require_once($gtkColumnBasePath);
require_once($gtkColumnMappingPath);
require_once($gtkColumnVirtualPath);
require_once($gtkDataSetPath);
require_once($glangPath);
require_once($langPath);

// $autoloadPath = dirname(__FILE__,2)."/vendor/autoload.php";
// require_once($autoloadPath);

$db_path = "sqlite:C:\proyectos\stonewood-app\Data\AppStonewood-Production.db";
$agencyAdminPermissions = [
"delete" => [
"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
17 changes: 17 additions & 0 deletions tests/testLogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
require_once(dirname(__FILE__, 2)."/vendor/autoload.php");

$envpath = dirname(__FILE__,2)."/.secret/env.php";
echo $envpath."\n";
$_GLOBALS["SECRET_ENV_PATH"] = $envpath;

class StonewoodPersona {





}


DataAccessManager::get("persona");

0 comments on commit ccda06e

Please sign in to comment.