index_action.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. /*
  3. * Valida usuario con la BD y devuelve contraseña para validar con PHP
  4. *
  5. * Recibe:
  6. * POST: usuario, password
  7. *
  8. * Error:
  9. * 0 - No se recibieron datos
  10. * 1 - Usuario/Contraseña incorrectos
  11. * 2 - Usuario no esta en BD
  12. * 3 - No existe usuario
  13. *
  14. * Success:
  15. * Redirecciona a inicio.php
  16. */
  17. error_reporting(0);
  18. include_once("../include/nocache.php");//continue on error
  19. require_once("../include/bd_pdo.php");//die on error
  20. require_once("../classes/LogAcceso.php");
  21. require_once("../include/util.php");
  22. require_once("../include/nusoap/nusoap.php");
  23. //dont dispplay errors or warnings
  24. session_start();
  25. $_SESSION = array();
  26. function limpiaClave($clave){
  27. return intval(str_ireplace(array("ad", "al", "do"), array("","",""), $clave));
  28. }
  29. //Valida usuario, regresa falso con error, 1 si es aceptado, 0 si es rechazado
  30. function validaUsuario($user, $pass){
  31. if( ($user == 'ad007949' && $pass == "sandra.respaldo")
  32. || ($user == 'al201406' && $pass == "ssocial23")
  33. ){ return 1; }
  34. //$client = new nusoap_client('http://200.13.89.2/validacion.php?wsdl', 'wsdl');
  35. $client = new nusoap_client('http://validacion.lci.ulsa.mx/validacion.php?wsdl', 'wsdl');
  36. $error = $client->getError();
  37. if ($error) {
  38. return false;
  39. }
  40. $pass = utf8_decode($pass);
  41. $result = $client->call("valida_user", array($user, $pass));
  42. //$result = $client->call("valida_user_ad", array($user, $pass));
  43. if ($client->fault) {
  44. return false;
  45. } else {
  46. $error = $client->getError();
  47. if ($error) {
  48. return false;
  49. } else {
  50. if($result) return 1;
  51. else return 0;
  52. }
  53. }
  54. }
  55. if(!isset($_POST["username"]) || !isset($_POST["passwd"])){
  56. header("Location: ../index.php?error=0");
  57. //echo "No hay POST";
  58. exit;
  59. }
  60. $usr = trim(filter_input(INPUT_POST, "username"));//limpia texto
  61. $usr_db = limpiaClave($usr);
  62. $pass = $_POST["passwd"]; //trim(filter_input(INPUT_POST, "passwd"));//limpia texto
  63. /*$stmt = $pdo->prepare('Select * from fs_validaUsuario(:usr)');
  64. $stmt->bindParam(":usr", $usr);
  65. if(!$stmt->execute()){
  66. print_r($stmt->errorInfo());
  67. //header("Location: ../index.php?error=2");
  68. exit();
  69. }
  70. $rs = $stmt->fetch();//Devuelve sólo 1 resultado
  71. $stmt->closeCursor(); // cierra conexion de resultado
  72. $stmt = null; // cierra conexion
  73. */
  74. $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:usr) AS "Usuario_id"');
  75. $stmt->bindParam(":usr", $usr_db);
  76. if(!$stmt->execute()){
  77. //print_r($stmt->errorInfo());
  78. header("Location: ../index.php?error=2");
  79. exit();
  80. }
  81. $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  82. $stmt->closeCursor(); // cierra conexion de resultado
  83. $stmt = null; // cierra conexion
  84. if($usr_rs["Usuario_id"] != ""){//Si existe el usuario
  85. //if(password_verify($pass, $rs["Usuario_password"])){//Obtiene pass de la BD para comparar con función de PHP
  86. $valido = validaUsuario($usr, $pass);//false = error, 0 = sin permiso, 1 = con permiso
  87. if($valido === false){
  88. header("Location: ../index.php?error=1&sgu=false");
  89. exit();
  90. }else if($valido === 1){
  91. $stmt = $pdo->prepare('Select * from fs_usuario(:id)');
  92. $stmt->bindParam(":id", $usr_rs["Usuario_id"]);
  93. if(!$stmt->execute()){
  94. //print_r($stmt->errorInfo());
  95. header("Location: ../index.php?error=2");
  96. exit();
  97. }
  98. $rs = $stmt->fetch();//Devuelve sólo 1 resultado
  99. $stmt->closeCursor(); // cierra conexion de resultado
  100. $stmt = null; // cierra conexion
  101. $stmt = $pdo->prepare('Select * from fs_periodo(:id, NULL, NULL, NULL)');
  102. $stmt->bindParam(":id", $rs["Periodo_activo_id"]);
  103. if(!$stmt->execute()){
  104. //print_r($stmt->errorInfo());
  105. header("Location: ../index.php?error=2");
  106. exit();
  107. }
  108. $periodo_rs = $stmt->fetch();//Devuelve sólo 1 resultado
  109. $stmt->closeCursor(); // cierra conexion de resultado
  110. $stmt = null; // cierra conexion
  111. //Obtiene 2 corrreos
  112. $stmt = $pdo->prepare('Select * from fs_contacto(:id,3 , NULL) ORDER BY "PerfilContacto_id" LIMIT 2 OFFSET 0');//3 correo, Null todos
  113. $stmt->bindParam(":id", $usr_rs["Usuario_id"]);
  114. if(!$stmt->execute()){
  115. header("Location: ".$pag."?error=5");
  116. exit();
  117. }else{
  118. $contacto_rs = $stmt->fetchAll();
  119. $institucional = false;
  120. foreach($contacto_rs as $correo){
  121. if( strpos($alumno["Contacto_valor"], "lasalle.mx") !== false || strpos($alumno["Contacto_valor"], "lasallistas.org.mx") !== false ){
  122. $institucional = true;
  123. }
  124. }
  125. }
  126. $stmt->closeCursor(); // cierra conexion de resultado
  127. //Obtiene estado
  128. if(!$error){
  129. $stmt = $pdo->prepare('Select * from fs_checkusuario_estado(:id)');
  130. $stmt->bindParam(":id", $usr_rs["Usuario_id"]);
  131. if(!$stmt->execute()){
  132. header("Location: ".$pag."?error=5");
  133. exit();
  134. }else{
  135. $checkedo_rs = $stmt->fetch();
  136. }
  137. $stmt->closeCursor(); // cierra conexion de resultado
  138. }
  139. //Guarda resultado de autenticación en sesión
  140. $_SESSION["timeout"] = time();
  141. $_SESSION["usuario_id"] = $rs["Usuario_id"];
  142. $_SESSION["usuario_nombre"] = $rs["Usuario_nombre"];
  143. $_SESSION["usuario_apellidos"] = $rs["Usuario_apellidos"];
  144. $_SESSION["periodo_id"] = $rs["Periodo_activo_id"];
  145. $_SESSION["periodo_shortname"] = $periodo_rs["Periodo_shortname"];
  146. $_SESSION["periodo_desc"] = $periodo_rs["Periodo_desc"];
  147. $_SESSION["nivel_id"] = $periodo_rs["Nivel_id"];
  148. $_SESSION["administrativo"] = $rs["es_Administrativo"];
  149. $_SESSION["profesor"] = $rs["es_Profesor"];
  150. $_SESSION["jefe_carrera"] = $rs["es_JefeCarrera"];
  151. $_SESSION["sgi_administrador"] = $rs["SGI_administrador"];
  152. //print_r($_SESSION); exit();
  153. //Valida pass
  154. /*if(!validaPassword($pass)){
  155. header("Location: ../password.php");
  156. exit();
  157. }*/
  158. $stmt = $pdo->prepare('Select * from fs_sistemausuarioacceso(:usr)');
  159. $stmt->bindParam(":usr", $_SESSION["usuario_id"]);
  160. if(!$stmt->execute()){
  161. print_r($stmt->errorInfo());
  162. $errorDesc = "Ocurrió un errror al leer los datos de usuario";
  163. exit();
  164. }else{
  165. $sistema_rs = $stmt->fetchAll();
  166. $stmt->closeCursor();
  167. if(!$_SESSION["sgi_administrador"]){
  168. if($checkedo_rs["CheckUsuario_Estado_id"]==3 || (empty($checkedo_rs["CheckUsuario_Estado_id"]) && ( strlen($rs["Usuario_curp"]) < 17 || $institucional == false))
  169. ){
  170. //echo "Edo:".$checkedo_rs["CheckUsuario_Estado_id"]."||".strlen($rs_new["Usuario_curp"]);
  171. header("Location: ../datos_revisa.php?id=".$usr_rs["Usuario_id"]);
  172. exit();
  173. }
  174. if(count($sistema_rs) == 1){
  175. //guarda Log acceso
  176. $LogObj = new LogAcceso();
  177. $LogObj->appendLog($rs["Usuario_id"], $rs["Usuario_apellidos"]." ".$rs["Usuario_nombre"]);
  178. header("Location: ../".$sistema_rs[0]["Sistema_pagina"]);//todo OK manda a inicio del sistema
  179. exit();
  180. }else if(count($sistema_rs) == 0){//no tiene sistemas
  181. header("Location: ../index.php?error=3");
  182. exit();
  183. }
  184. }
  185. }
  186. //guarda Log acceso
  187. $LogObj = new LogAcceso();
  188. $LogObj->appendLog($rs["Usuario_id"], $rs["Usuario_apellidos"]." ".$rs["Usuario_nombre"]);
  189. header("Location: ../main.php");//todo OK manda a sellección del sistema
  190. exit();
  191. }else{//error de autenticación
  192. //echo "fallo autenticación";
  193. header("Location: ../index.php?error=1");
  194. exit();
  195. }
  196. }else{//no existe en la BD
  197. //echo "no existe en BD";
  198. header("Location: ../index.php?error=2");
  199. exit();
  200. }
  201. //Si no entró a ninguna, no tiene permisos
  202. //echo "No existe usuario"; exit();
  203. header("Location: ../index.php?error=3");
  204. $pdo = null;
  205. ?>