How to add the "active" field in authentication with AthenticationService? I use CakePHP 4.x

19 views Asked by At

I request help with the following please:

I need to add a field to the authentication system and allow me to validate it with the isValid() function when calling $result = $this->Authentication->getResult();

I have tried the following but it doesn't work:

 public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
    {
        
        // Crea una nueva instancia de servicio de autenticación, definiendo la URL donde se debe 
        // redireccionar en caso de que se pretenda entrar a una vista protegida.
        $authenticationService = new AuthenticationService([
            'unauthenticatedRedirect' => '/'.basename(ROOT).'/users/login',
            'queryParam' => 'redirect',
        ]);

        // Carga los campos identificadores (logueo). 
        // Asegúrese de relacionar los campos con los que se valida el logueo
        $authenticationService->loadIdentifier('Authentication.Password', [
            'fields' => [
                            'username' => 'usuario',
                            'password' => 'password',
                        ],
            'where' => [    'estado' => 'Activo'    ],
        ]);

        // Load the authenticators, you want session first
        $authenticationService->loadAuthenticator('Authentication.Session');

        // Configure form data check to pick email and password
        $authenticationService->loadAuthenticator('Authentication.Form', [
            'fields' => [
                            'username' => 'usuario',
                            'password' => 'password',
                        ],

            'loginUrl' => '/'.basename(ROOT).'/users/login',
        ]);


        return $authenticationService; 
    }

0

There are 0 answers