Added 'recursive' settings option to BaseAuthenticate and BasicAuthenticate to have a bit more fine grained control in custom Authenticate objects.

This commit is contained in:
Thomas Ploch 2011-10-19 17:54:08 +02:00
parent 485c15d55d
commit 521dff8468
3 changed files with 7 additions and 2 deletions

View file

@ -29,6 +29,7 @@ abstract class BaseAuthenticate {
* - `userModel` The model name of the User, defaults to User. * - `userModel` The model name of the User, defaults to User.
* - `scope` Additional conditions to use when looking up and authenticating users, * - `scope` Additional conditions to use when looking up and authenticating users,
* i.e. `array('User.is_active' => 1).` * i.e. `array('User.is_active' => 1).`
* - `recursive` The value of the recursive key passed to find(). Defaults to 0.
* *
* @var array * @var array
*/ */
@ -38,7 +39,8 @@ abstract class BaseAuthenticate {
'password' => 'password' 'password' => 'password'
), ),
'userModel' => 'User', 'userModel' => 'User',
'scope' => array() 'scope' => array(),
'recursive' => 0
); );
/** /**
@ -80,7 +82,7 @@ abstract class BaseAuthenticate {
} }
$result = ClassRegistry::init($userModel)->find('first', array( $result = ClassRegistry::init($userModel)->find('first', array(
'conditions' => $conditions, 'conditions' => $conditions,
'recursive' => 0 'recursive' => $this->settings['recursive']
)); ));
if (empty($result) || empty($result[$model])) { if (empty($result) || empty($result[$model])) {
return false; return false;

View file

@ -48,6 +48,7 @@ class BasicAuthenticate extends BaseAuthenticate {
* - `userModel` The model name of the User, defaults to User. * - `userModel` The model name of the User, defaults to User.
* - `scope` Additional conditions to use when looking up and authenticating users, * - `scope` Additional conditions to use when looking up and authenticating users,
* i.e. `array('User.is_active' => 1).` * i.e. `array('User.is_active' => 1).`
* - `recursive` The value of the recursive key passed to find(). Defaults to 0.
* - `realm` The realm authentication is for. Defaults the server name. * - `realm` The realm authentication is for. Defaults the server name.
* *
* @var array * @var array
@ -59,6 +60,7 @@ class BasicAuthenticate extends BaseAuthenticate {
), ),
'userModel' => 'User', 'userModel' => 'User',
'scope' => array(), 'scope' => array(),
'recursive' => 0,
'realm' => '', 'realm' => '',
); );

View file

@ -47,6 +47,7 @@ class BasicAuthenticateTest extends CakeTestCase {
'fields' => array('username' => 'user', 'password' => 'password'), 'fields' => array('username' => 'user', 'password' => 'password'),
'userModel' => 'User', 'userModel' => 'User',
'realm' => 'localhost', 'realm' => 'localhost',
'recursive' => 0
)); ));
$password = Security::hash('password', null, true); $password = Security::hash('password', null, true);