123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- /*
- * Valida usuario con la BD y devuelve contraseña para validar con PHP
- *
- * Recibe:
- * POST: usuario, password
- *
- * Error:
- * 0 - No se recibieron datos
- * 1 - Usuario/Contraseña incorrectos
- * 2 - Usuario no esta en BD
- * 3 - No existe usuario
- *
- * Success:
- * Redirecciona a inicio.php
- */
- include_once("../include/nocache.php");//continue on error
- require_once("../include/bd_pdo.php");//die on error
- require_once("../classes/LogAcceso.php");
- require_once("../include/util.php");
- require_once("../include/nusoap/nusoap.php");
- session_start();
- $_SESSION = array();
- $pag = "../index_bypass.php";
- function limpiaClave($clave){
- return intval(str_ireplace(array("ad", "al", "do"), array("","",""), $clave));
- }
- //Valida usuario, regresa falso con error, 1 si es aceptado, 0 si es rechazado
- function validaUsuario($user, $pass){
-
- $client = new nusoap_client('http://200.13.89.2/validacion.php?wsdl', 'wsdl');
- $error = $client->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;
- ?>
|