Life is Really Short, Have Your Life!!

ござ先輩の主に技術的なメモ

AuthComponentにオリジナルの認証項目を設けたい

useridとpasswordの照合だけでなく、アカウントのロック状態等も踏まえてログインチェックを掛けたい場合のTipsです。AuthComponentにはその為のプロパティが用意されています。$userScopeです。

使い方はこんな感じです。

<?php 
class UsersController extends AppController {
	var $name= "user";
	var $components = array("Auth");

    function beforeFilter() {
		$this->Auth->fields = array(
		'username' => 'userid',
		'password' => 'password'
		);
                //ココ!
		$this->Auth->userScope= array("lock"=>'false');
	}

こうするとAuthComponentが「where userid = 'xxx' and password='yyy' and lock='false'」というWHERE句を追加してくれます。ただ、なぜか全角文字の場合はダメだった。AuthComponentのソースを読むとuserScopeが入っていればそれを条件に入れてidentify()というメソッドでチェック掛けてくれるだけみたいなのになぁ。

いじょ。