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(); } }