123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?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("../../include/util.php");
- require_once("../../include/nusoap/nusoap.php");
- session_start();
- $_SESSION = array();
- define("NAVIDAD", 2020);
- 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 true;
- $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_addo", 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 = $_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: ../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
- $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
-
- //Guarda resultado de autenticación en sesión
- $_SESSION["n_timeout"] = time();
- $_SESSION["n_usuario_id"] = $rs["Usuario_id"];
- $_SESSION["n_usuario_nombre"] = $rs["Usuario_nombre"];
- $_SESSION["n_usuario_apellidos"] = $rs["Usuario_apellidos"];
- $_SESSION["n_sgi_administrador"] = $rs["SGI_administrador"];
- $_SESSION["n_navidad"] = NAVIDAD;
-
-
- $stmt = $pdo->prepare('Select * from fs_navidadusuario(:id, '.NAVIDAD.', NULL)');
- $stmt->bindParam(":id", $_SESSION["n_usuario_id"]);
- 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["NavidadUsuario_existe"]){
- if(!$usr_rs["NavidadUsuario_activo"]){
- $stmt = $pdo->prepare('Select * from fu_navidadusuario(:id, '.NAVIDAD.', true)');
- $stmt->bindParam(":id", $_SESSION["n_usuario_id"]);
- if(!$stmt->execute()){
- //print_r($stmt->errorInfo());
- header("Location: ../index.php?error=4");
- exit();
- }
- }
- }else{//no existe, darlo de alta
- $stmt = $pdo->prepare('Select * from fi_navidadusuario(:id, '.NAVIDAD.', true)');
- $stmt->bindParam(":id", $_SESSION["n_usuario_id"]);
- if(!$stmt->execute()){
- //print_r($stmt->errorInfo());
- header("Location: ../index.php?error=4");
- 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;
- ?>
|