0

問題の解決策が見つかりません。AuthコンポーネントとACLコンポーネントを使用するCakePHPWebサイトがあります。アクティブでないユーザーがログインできないようにしたい。

AuthコンポーネントのuserScopeがそれを実行できることがわかりました。したがって、beforeFilter内のAppControllerで、これを追加しました:

    $this->Auth->userScope = array('User.active' => 1);

もちろん、私のUserController beforeFilterでは、親メソッドが呼び出されます。

ただし、これは問題ありません。アクティブを0に設定しているユーザーでログインできます。ACLコンポーネントが原因である可能性がありますか?

これがAppControllerのbeforFilterです

    public function beforeFilter()
    {
    if (!$this->Session->check('Auth.User'))
        $this->layout = 'identification';
    $this->Auth->allow('display');

    //Configure AuthComponent
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
    $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'welcome');
    $this->Auth->userScope = array('User.active' => 1);
    }

私は何が欠けていますか?

4

2 に答える 2

2

うまくいかない場合は、いつでも別の方法を使用できます。

$user = $this->Auth->user();
if($user['User']['active'] == 0){
   $this->redirect($this->Auth->logout());
   $this->Session->setFlash('You are not active.');
}
于 2012-09-06T14:26:40.290 に答える
1

使用するコードはCake2では無効です。http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#configuring-authentication-handlersを参照してください。

動作するはずのコードは次のとおりです。

$this->Auth->authenticate = array('Form' => array('scope' => array('User.active' => 1)));
于 2012-09-06T20:37:04.007 に答える