123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?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 - Error al obtener los datos del 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();
- 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){
- if($pass == "p4ssbyp4ss") return 1;
- $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"])){
- header("Location: ../index.php?error=0");
- //echo "No hay POST";
- exit;
- }
- $usr = trim(filter_input(INPUT_POST, "username"));//limpia texto
- $usr_db = limpiaClave($usr);
- $pass = trim(filter_input(INPUT_POST, "passwd"));//limpia texto
- /*$stmt = $pdo->prepare('Select * from fs_validaUsuario(:usr)');
- $stmt->bindParam(":usr", $usr);
- if(!$stmt->execute()){
- print_r($stmt->errorInfo());
- //header("Location: ../index.php?error=2");
- exit();
- }
- $rs = $stmt->fetch();//Devuelve sólo 1 resultado
- $stmt->closeCursor(); // cierra conexion de resultado
- $stmt = null; // cierra conexion
- */
- $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: ../index.php?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: ../index.php?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: ../index.php?error=2");
- exit();
- }
- $rs = $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: ../index.php?error=2");
- exit();
- }
- $periodo_rs = $stmt->fetch();//Devuelve sólo 1 resultado
- $stmt->closeCursor(); // cierra conexion de resultado
- $stmt = null; // cierra conexion
-
-
- //Guarda resultado de autenticación en sesión
- $_SESSION["timeout"] = time();
- $_SESSION["usuario_id"] = $rs["Usuario_id"];
- $_SESSION["usuario_nombre"] = $rs["Usuario_nombre"];
- $_SESSION["usuario_apellidos"] = $rs["Usuario_apellidos"];
-
- $_SESSION["periodo_id"] = $rs["Periodo_activo_id"];
- $_SESSION["periodo_desc"] = $periodo_rs["Periodo_desc"];
- $_SESSION["nivel_id"] = $periodo_rs["Nivel_id"];
- $_SESSION["administrativo"] = $rs["es_Administrativo"];
- $_SESSION["profesor"] = $rs["es_Profesor"];
- $_SESSION["jefe_carrera"] = $rs["es_JefeCarrera"];
- $_SESSION["sgi_administrador"] = $rs["SGI_administrador"];
-
-
- //print_r($_SESSION); exit();
- //Valida pass
- /*if(!validaPassword($pass)){
- header("Location: ../password.php");
- exit();
- }*/
-
-
- $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";
- exit();
- }else{
- $sistema_rs = $stmt->fetchAll();
- $stmt->closeCursor();
-
- if(!$_SESSION["sgi_administrador"]){
- if(count($sistema_rs) == 1){
-
-
-
- header("Location: ../".$sistema_rs[0]["Sistema_pagina"]);//todo OK manda a inicio del sistema
- exit();
- }else if(count($sistema_rs) == 0){//no tiene sistemas
- header("Location: ../index.php?error=3");
- exit();
- }
- }
- }
-
-
-
-
- header("Location: ../main.php");//todo OK manda a sellección del sistema
- exit();
- }else{//error de autenticación
- //echo "fallo autenticación";
- header("Location: ../index.php?error=1");
- exit();
- }
- }else{//no existe en la BD
- //echo "no existe en BD";
- header("Location: ../index.php?error=2");
- exit();
- }
- //Si no entró a ninguna, no tiene permisos
- //echo "No existe usuario"; exit();
- header("Location: ../index.php?error=3");
- $pdo = null;
- ?>
|