ajax response variable returns undefined in symfony

2

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 ) 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'));
        //********************************************************
    }
}
    
asked by rlazom 11.05.2016 в 15:18
source

1 answer

1

Final solution to the problem:

In app / config / security.yml in the access_control section add the path that points to the controller's method so that before logging in, the user can access it.

access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/check_ldap, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/*, roles: IS_AUTHENTICATED_FULLY }

The rest of the code shown "above" is OK.

    
answered by 11.05.2016 / 21:02
source