In a login page I want to click on the submit button to validate the entered data against an LDAP server and if everything is ok then proceed to the standard submit form.
In the button click event I have the following code in php ) I have the following:
public function checkLdapAction(Request $request)
{
$user = $request->request->get('user');
$pass = $request->request->get('pass');
$ldap = $request->request->get('sinLDAP');
if ($sinLdap=='true'){
//********************************************************
return new JsonResponse(array('mensaje' => '1',
'result' => '-1',
'tipo_msg' => 'info',
'title_msg' => '',
'msg' => 'No se esta validando contra el server LDAP'));
//********************************************************
}
$ldapServer = 'nombre.server.ldap';
$ldapServerIP = 'XXX.XXX.XXX.XXX';
$ldapServerPort = 'XXXX';
$hostip = @gethostbyname($ldapServer);
$errorConx = ($hostip == $ldapServer || $hostip!=$ldapServerIP);
if ($errorConx){
//********************************************************
return new JsonResponse(array('mensaje' => '1',
'result' => '-1',
'tipo_msg' => 'error',
'title_msg' => 'Error en Conexión',
'msg' => 'Error de conexión con el servidor LDAP "'.$ldapServer.'"'));
//********************************************************
}
$ldap_conn = ldap_connect($ldapServer,$ldapServerPort);
$binding = @ldap_bind($ldap_conn, $user, $pass);
if ($binding){
ldap_close($ldap_conn);
//********************************************************
return new JsonResponse(array('mensaje' => '0','result' => '1'));
//********************************************************
}
else{
ldap_close($ldap_conn);
//********************************************************
return new JsonResponse(array('mensaje' => '1',
'result' => '-1',
'tipo_msg' => 'warning',
'title_msg' => 'Datos Incorrectos',
'msg' => 'Usuario o contraseña incorrecto'));
//********************************************************
}
}