index_action.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
  3. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  4. header('Cache-Control: no-store, no-cache, must-revalidate');
  5. header('Cache-Control: post-check=0, pre-check=0', false);
  6. header('Pragma: no-cache');
  7. require_once("./include/bd_pdo.php");//die on error
  8. require_once("./include/nusoap/nusoap.php");
  9. require_once("./include/util.php");
  10. define("COOKIE_N", "checador");
  11. //Valida usuario en windows, regresa falso con error, 1 si es aceptado, 0 si es rechazado
  12. function validaUsuario($user, $pass){
  13. $client = new nusoap_client('http://200.13.89.2/validacion.php?wsdl', 'wsdl');
  14. //$client = new nusoap_client('http://validacion.lci.ulsa.mx/validacion.php?wsdl', 'wsdl');#Azure
  15. $error = $client->getError();
  16. if ($error) {
  17. return false;
  18. }
  19. $pass = utf8_decode($pass);
  20. $result = $client->call("valida_user_addo", array($user, $pass));
  21. if ($client->fault) {
  22. return false;
  23. } else {
  24. $error = $client->getError();
  25. if ($error) {
  26. return false;
  27. } else {
  28. if($result) return 1;
  29. else return 0;
  30. }
  31. }
  32. }
  33. $auth = false;
  34. if (!isset($_COOKIE[COOKIE_N])){
  35. if(!empty($_POST["username"]) && !empty($_POST["passwd"])){
  36. //Existe usuario y contraseña
  37. $usr = trim(filter_input(INPUT_POST, "username"));//limpia texto
  38. $usr_db = limpiaClave($usr);
  39. $pass = $_POST["passwd"]; //trim(filter_input(INPUT_POST, "passwd"));//limpia texto
  40. $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:usr) AS "Usuario_id"');
  41. $stmt->bindParam(":usr", $usr_db);
  42. if(!$stmt->execute()){
  43. //print_r($stmt->errorInfo());
  44. header("Location: index.php?error=2");
  45. exit();
  46. }
  47. $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  48. $stmt->closeCursor(); // cierra conexion de resultado
  49. $stmt = null; // cierra conexion
  50. $usr_id = $usr_rs["Usuario_id"];
  51. if(!empty($usr_id)){//Si existe el usuario
  52. $valido = validaUsuario($usr, $pass);//false = error, 0 = sin permiso, 1 = con permiso
  53. if($valido === false){
  54. //$errorDesc = "El usuario/contraseña son incorrectos";
  55. header("Location: index.php?error=0");
  56. exit();
  57. }else if($valido === 1){
  58. $auth = true;
  59. setcookie(COOKIE_N, encripta($usr_id), strtotime('today 23:59'), "/");
  60. }else{
  61. //$errorDesc = "El usuario/contraseña son incorrectos";
  62. header("Location: index.php?error=0");
  63. exit();
  64. }
  65. }else{
  66. //$errorDesc = "El usuario no está registrado en el sistema";
  67. header("Location: index.php?error=1");
  68. exit();
  69. }
  70. }else{
  71. header("Location: index.php?error=0");
  72. exit();
  73. }
  74. }
  75. header("Location: index.php");
  76. ?>