CakePHP - authentication component, using a different table name and column name

前端 未结 2 401
暖寄归人
暖寄归人 2021-01-17 01:42

Just for organization sake, I wanted to use a different table for the authentication component to check, but it doesn\'t quite work. While I can initially state:

2条回答
  •  天命终不由人
    2021-01-17 02:06

    Make sure your database table "core_users" and model "CoreUser" exists.

    When you setup component you can put login/logout redirect here.

    var $components = array(
            "Auth" => array(
                 'loginRedirect' => array('controller' => 'dashboard', 'action' => 'index'),
                 'logoutRedirect' => array('controller' => 'core_users', 'action' => 'login')
                  ),
           "Session");
    

    Now in beforeFilter medhod you can put the following

    function beforeFilter(){
          $this->Auth->authenticate = array(
             AuthComponent::ALL => array('userModel' => 'CoreUser', 'scope' => array("CoreUser.status" => 1), "fields" => array("username" => "email", "password" => "your_password_field"), 'Form', 'Basic'
                                            );
    }
    

    Above example you can ignore status, if you need to pass any other info on the login verification u can use that. Now about you can remove 'Basic' if you only need form validation. I hope this would work .

提交回复
热议问题