2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

2
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?