Login Script in 2.4.2 is not working

后端 未结 2 1296
终归单人心
终归单人心 2020-12-07 06:13

I am new to cakephp. I have a problom while login. With wrong name and password redirects to login home page.

UsersController.php

public function          


        
2条回答
  •  不知归路
    2020-12-07 07:00

    usercontroller
    
    public function beforeFilter() {
            parent::beforeFilter();
            $this->Auth->allow('login','logout');
        }
    
    
    
    public function login()
        {
           $this->layout= 'login';
    
           if ($this->request->is('post')) {
    
                if ($this->Auth->login()) {
    
                            $this->redirect('/users');
                            else {
    
                    $this->Session->setFlash(__('Invalid email or password, please try again'));
    
                }
            }
            else{
                if($this->Auth->loggedIn())
                    $this->redirect('index');
            }
        }
    }
    

    AppController

    class AppController extends Controller {
    
    public $components = array(
    
        'Session',
        'Auth' => array(
            'authenticate' => array(
                'Form' => array( 
                    'userModel' => 'User',
                     'fields' => array(
                        'username' => 'user_name',
                        'password' => 'password'
                        )
                    )
                ),
            'loginAction' => array('controller' => 'users', 'action' => 'login'),
                        'loginRedirect' => array('controller' => 'users', 'action' => 'dashboard'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
            'authError' => 'You don\'t have access here.',
                    /*
                    'loginAction' => array('controller' => 'users', 'action' => 'forgot_password'),
                    'loginRedirect' => array('controller' => 'users', 'action' => 'dashboard'),
                    'logoutRedirect' => array('controller' => 'users', 'action' => 'forgot_password'),
                    'authError' => 'You don\'t have access here.',
                    */
            ),
    
    );
    

提交回复
热议问题