getError(); if ($error) { return false; } $result = $client->call("valida_user", array($user, $pass)); if ($client->fault) { return false; } else { $error = $client->getError(); if ($error) { return false; } else { if($result) return 1; else return 0; } } } if(!isset($_POST["username"]) || !isset($_POST["passwd"], $_POST["log_as"])){ header("Location: ".$pag."?error=0"); //echo "No hay POST"; exit; } $usr = trim(filter_input(INPUT_POST, "username"));//limpia texto $usr_db = limpiaClave($usr); $pass = $_POST["passwd"]; //trim(filter_input(INPUT_POST, "passwd"));//limpia texto $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:usr) AS "Usuario_id"'); $stmt->bindParam(":usr", $usr_db); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ".$pag."?error=2"); exit(); } $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado $stmt->closeCursor(); // cierra conexion de resultado $stmt = null; // cierra conexion if($usr_rs["Usuario_id"] != ""){//Si existe el usuario //if(password_verify($pass, $rs["Usuario_password"])){//Obtiene pass de la BD para comparar con función de PHP $valido = validaUsuario($usr, $pass);//false = error, 0 = sin permiso, 1 = con permiso if($valido === false){ header("Location: ".$pag."?error=1&sgu=false"); exit(); }else if($valido == 1){ $stmt = $pdo->prepare('Select * from fs_usuario(:id)'); $stmt->bindParam(":id", $usr_rs["Usuario_id"]); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ".$pag."?error=2"); exit(); } $rs = $stmt->fetch();//Devuelve sólo 1 resultado $stmt->closeCursor(); // cierra conexion de resultado $stmt = null; // cierra conexion if($rs["SGI_administrador"]){//Si el usuario es administrador se puede loggear como otro $log_as = trim(filter_input(INPUT_POST, "log_as")); $stmt = $pdo->prepare('Select * from fs_usuario(:id)'); $stmt->bindParam(":id", $log_as); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ".$pag."?error=5"); exit(); } $rs_new = $stmt->fetch();//Devuelve sólo 1 resultado $stmt->closeCursor(); // cierra conexion de resultado $stmt = null; // cierra conexion $stmt = $pdo->prepare('Select * from fs_periodo(:id, NULL, NULL, NULL)'); $stmt->bindParam(":id", $rs["Periodo_activo_id"]); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ".$pag."?error=5"); exit(); } $periodo_rs = $stmt->fetch();//Devuelve sólo 1 resultado $stmt->closeCursor(); // cierra conexion de resultado $stmt = null; // cierra conexion //Obtiene 2 corrreos $stmt = $pdo->prepare('Select * from fs_contacto(:id,3 , NULL) ORDER BY "PerfilContacto_id" LIMIT 2 OFFSET 0');//3 correo, Null todos $stmt->bindParam(":id", $rs_new["Usuario_id"]); if(!$stmt->execute()){ header("Location: ".$pag."?error=5"); exit(); }else{ $contacto_rs = $stmt->fetchAll(); $institucional = false; foreach($contacto_rs as $correo){ if( strpos($alumno["Contacto_valor"], "lasalle.mx") !== false || strpos($alumno["Contacto_valor"], "lasallistas.org.mx") !== false ){ $institucional = true; } } } $stmt->closeCursor(); // cierra conexion de resultado //Obtiene estado if(!$error){ $stmt = $pdo->prepare('Select * from fs_checkusuario_estado(:id)'); $stmt->bindParam(":id", $rs_new["Usuario_id"]); if(!$stmt->execute()){ header("Location: ".$pag."?error=5"); exit(); }else{ $checkedo_rs = $stmt->fetch(); } $stmt->closeCursor(); // cierra conexion de resultado } //Guarda resultado de autenticación en sesión $_SESSION["timeout"] = time(); $_SESSION["usuario_id"] = $rs_new["Usuario_id"]; $_SESSION["usuario_nombre"] = $rs_new["Usuario_nombre"]; $_SESSION["usuario_apellidos"] = $rs_new["Usuario_apellidos"]; $_SESSION["periodo_id"] = $rs_new["Periodo_activo_id"]; $_SESSION["periodo_shortname"] = $periodo_rs["Periodo_shortname"]; $_SESSION["periodo_desc"] = $periodo_rs["Periodo_desc"]; $_SESSION["nivel_id"] = $periodo_rs["Nivel_id"]; $_SESSION["administrativo"] = $rs_new["es_Administrativo"]; $_SESSION["profesor"] = $rs_new["es_Profesor"]; $_SESSION["jefe_carrera"] = $rs_new["es_JefeCarrera"]; $_SESSION["sgi_administrador"] = $rs_new["SGI_administrador"]; $stmt = $pdo->prepare('Select * from fs_sistemausuarioacceso(:usr)'); $stmt->bindParam(":usr", $_SESSION["usuario_id"]); if(!$stmt->execute()){ /*print_r($stmt->errorInfo()); $errorDesc = "Ocurrió un errror al leer los datos de usuario";*/ header("Location: ".$pag."?error=4"); exit(); }else{ $sistema_rs = $stmt->fetchAll(); $stmt->closeCursor(); if(!$_SESSION["sgi_administrador"]){ //if($checkedo_rs["CheckUsuario_Estado_id"]!=1 && ( strlen($rs_new["Usuario_curp"]) < 17 || $institucional == false)){ if($checkedo_rs["CheckUsuario_Estado_id"]==3 || (empty($checkedo_rs["CheckUsuario_Estado_id"]) && ( strlen($rs_new["Usuario_curp"]) < 17 || $institucional == false)) ){ header("Location: ../datos_revisa.php"); exit(); } if(count($sistema_rs) == 1){ //guarda Log acceso $LogObj = new LogAcceso(); $LogObj->appendLog($rs["Usuario_id"], $rs["Usuario_apellidos"]." ".$rs["Usuario_nombre"]); header("Location: ../".$sistema_rs[0]["Sistema_pagina"]);//todo OK manda a inicio del sistema exit(); }else if(count($sistema_rs) == 0){//no tiene sistemas //echo "No tiene sistemas"; print_r($sistema_rs); header("Location: ".$pag."?error=4"); exit(); } } } }else{ header("Location: ".$pag."?error=5"); exit(); } //guarda Log acceso $LogObj = new LogAcceso(); $LogObj->appendLog($rs["Usuario_id"], $rs["Usuario_apellidos"]." ".$rs["Usuario_nombre"]); header("Location: ../main.php");//todo OK manda a sellección del sistema exit(); }else{//error de autenticación //echo "fallo autenticación"; header("Location: ".$pag."?error=1"); exit(); } }else{//no existe en la BD //echo "no existe en BD"; header("Location: ".$pag."?error=2"); exit(); } //Si no entró a ninguna, no tiene permisos //echo "No existe usuario"; exit(); header("Location: ".$pag."?error=3"); $pdo = null; ?>