LoginSignup
2
3

More than 5 years have passed since last update.

CakePHP、Authコンポーネントでログインの条件を追加

Posted at

CakePHP、ログイン処理はAuthComponentにおまかせ、ってのが定石だが、そういえば、ログインできる条件がある場合はどうしたらいいだろう?
ログインIDとパスワードがあって、他にそのメンバーのステータスが「有効」な時のみログインできる、というような場合だ。
結論、 scope というのを追加すればよい。

app/Controller/LoginController.php
    public $components = array('Paginator', 'Session', 'Auth' => array(
        'authenticate' => array(
            'Form' => array(
                'userModel' => 'Member',
                'fields' => array('username' => 'login_id', 'passeord' => 'password'),
                'scope' => array('status' => 1)
            )    
        )
    ));
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3