Cakephp 3.8 - Authentication succeed, but I stay on the login page

Viewed 13

My cakephp 3 application works well. I wanted to duplicate my application into an other folder to have a development environment. I use the same deposit. My production folder is linked with the master branch. My developement folder is linked with the develop branch. The sources are the same in the two cases. The only differences are the database used (tests database for my environment folder) and the root folder. When I connect on the production version, all works well. When I connect on the developement version, login works well, I get the correct redirection information from $this->Auth->redirectUrl(), but I stay on the login page.

Anyone can help me please?

public function login()
{
    
    $this->log("UserController - login()", "debug");
    $this->Auth->allow();
    $this->viewBuilder()->layout('login');
    //return $this->redirect( ['controller' => 'Login', 'action' => 'index']);


    if ($this->request->is('post')) {

        $user = $this->Auth->identify();
        //debug($user); debug($this->Auth); die();

        if ($user) {
            
            //debug($user); die();
            $this->log("UserController - login(): ".$user["id"].' - '.$user["username"], "debug");

            $this->loadModel('Logs');
            $log = $this->Logs->newEntity();
            $log->log_userId = $user["id"];
            $log->log_action = "LOGIN";
            $log->log_srcip = $_SERVER["REMOTE_ADDR"];
            

            if ($this->Logs->save($log)) {
                //$this->Flash->success(__("L'utilisateur a été sauvegardé."));
            }

            $this->Auth->setUser($user);
            //debug($user); die();
            
            $this->log("UserController - login() - role = : ".$user['role'], "debug");
            
            
            switch($user['role']) {
                
                case "club_master":
                    return $this->redirect([
                        'controller' => 'candidats',
                        'action' => 'index'
                        ]);
                    break;
                    
                case "register_agent":
                    return $this->redirect([
                        'controller' => 'inscriptions',
                        'action' => 'index'
                        ]);
                    break;
                    
                default:
                    //debug($this->Auth->redirectUrl()); die();
                    return $this->redirect($this->Auth->redirectUrl());
            }
            
        }
        $this->Flash->error(__('Login ou mot de passe invalide, veuillez essayer de nouveau.'));
    }
}
0 Answers
Related