Advertisement
Guest User

Untitled

a guest
May 11th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. $('#btnLogin').click(function(){
  2. if (frmLogin.valid()){
  3. var user = $('#frmLoginUser').val();
  4. var pass = $('#frmLoginPass').val();
  5. var sinLDAP = false;
  6.  
  7. var pos1 = user.indexOf('DOMINIO\');
  8. if(pos1==-1){
  9. user = 'DOMINIO'+'\'+user;
  10. }
  11.  
  12. console.log(user);
  13. console.log(pass);
  14. console.log(sinLDAP);
  15.  
  16. $.ajax({
  17. type:"POST",
  18. data: {'user':user,'pass':pass, 'sinLDAP':sinLDAP},
  19. url:"{{ path('check_ldap') }}"
  20. }).done(function(respuesta){
  21. console.log(respuesta.result);
  22. console.log(respuesta.mensaje);
  23. if (respuesta.result==9){
  24. notificaciones('info','Sin validar LDAP','')
  25. }
  26. if (respuesta.mensaje==1 && respuesta.result==-1)
  27. notificaciones(respuesta.tipo_msg,respuesta.msg,respuesta.title_msg);
  28. else{
  29. notificaciones('success','Se logueo correctamente','')
  30. }
  31. });
  32. }
  33. });
  34.  
  35. public function checkLdapAction()
  36. {
  37. $user = $request->request->get('user');
  38. $pass = $request->request->get('pass');
  39. $ldap = $request->request->get('sinLDAP');
  40.  
  41. if ($ldap){
  42. //********************************************************
  43. return new JsonResponse(array('mensaje' => '0','result' => '1'));
  44. //********************************************************
  45. }
  46.  
  47. $ldapServer = 'nombre.server.ldap';
  48. $ldapServerIP = 'XXX.XXX.XXX.XXX';
  49. $ldapServerPort = 'XXXX';
  50.  
  51. $hostip = @gethostbyname($ldapServer);
  52. $errorConx = ($hostip == $ldapServer || $hostip!=$ldapServerIP);
  53.  
  54. if ($errorConx){
  55. //********************************************************
  56. return new JsonResponse(array('mensaje' => '1',
  57. 'result' => '-1',
  58. 'tipo_msg' => 'error',
  59. 'title_msg' => 'Error en Conexión',
  60. 'msg' => 'Error de conexión con el servidor LDAP "'.$ldapServer.'"'));
  61. //********************************************************
  62. }
  63.  
  64. $ldap_conn = ldap_connect($ldapServer,$ldapServerPort);
  65. $binding = @ldap_bind($ldap_conn, $user, $pass);
  66.  
  67. if ($binding){
  68. ldap_close($ldap_conn);
  69. //********************************************************
  70. return new JsonResponse(array('mensaje' => '0','result' => '1'));
  71. //********************************************************
  72. }
  73. else{
  74. ldap_close($ldap_conn);
  75. //********************************************************
  76. return new JsonResponse(array('mensaje' => '1',
  77. 'result' => '-1',
  78. 'tipo_msg' => 'warning',
  79. 'title_msg' => 'Datos Incorrectos',
  80. 'msg' => 'Usuario o contraseña incorrecto'));
  81. //********************************************************
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement