mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-08 04:22:40 +00:00
closes #5172, AuthComponent login with with UUID
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7396 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
7ce4bd4131
commit
4a5282bcd7
2 changed files with 79 additions and 17 deletions
|
@ -763,7 +763,7 @@ class AuthComponent extends Object {
|
|||
if (empty($data) || empty($data[$this->userModel])) {
|
||||
return null;
|
||||
}
|
||||
} elseif (is_numeric($user)) {
|
||||
} elseif (!empty($user)) {
|
||||
$model =& $this->getModel();
|
||||
$data = $model->find(array_merge(array($model->escapeField() => $user), $conditions));
|
||||
|
||||
|
@ -772,7 +772,7 @@ class AuthComponent extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
if (isset($data) && !empty($data)) {
|
||||
if (!empty($data)) {
|
||||
if (!empty($data[$this->userModel][$this->fields['password']])) {
|
||||
unset($data[$this->userModel][$this->fields['password']]);
|
||||
}
|
||||
|
|
|
@ -115,6 +115,69 @@ class AuthUser extends CakeTestModel {
|
|||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class UuidUser extends CakeTestModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'AuthUser'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'UuidUser';
|
||||
/**
|
||||
* useDbConfig property
|
||||
*
|
||||
* @var string 'test_suite'
|
||||
* @access public
|
||||
*/
|
||||
var $useDbConfig = 'test_suite';
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'uuid'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'uuids';
|
||||
/**
|
||||
* parentNode method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function parentNode() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* bindNode method
|
||||
*
|
||||
* @param mixed $object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function bindNode($object) {
|
||||
return 'Roles/Admin';
|
||||
}
|
||||
/**
|
||||
* isAuthorized method
|
||||
*
|
||||
* @param mixed $user
|
||||
* @param mixed $controller
|
||||
* @param mixed $action
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function isAuthorized($user, $controller = null, $action = null) {
|
||||
if (!empty($user)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class AuthTestController extends Controller {
|
||||
/**
|
||||
* name property
|
||||
|
@ -313,7 +376,7 @@ class AuthTest extends CakeTestCase {
|
|||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.auth_user', 'core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action');
|
||||
var $fixtures = array('core.uuid', 'core.auth_user', 'core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action');
|
||||
/**
|
||||
* initialized property
|
||||
*
|
||||
|
@ -328,19 +391,9 @@ class AuthTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function startTest() {
|
||||
if (!$this->initialized) {
|
||||
Configure::write('Acl.database', 'test_suite');
|
||||
Configure::write('Acl.classname', 'DbAcl');
|
||||
if (isset($this->fixtures) && (!is_array($this->fixtures) || empty($this->fixtures))) {
|
||||
unset($this->fixtures);
|
||||
}
|
||||
// Create records
|
||||
if (isset($this->_fixtures) && isset($this->db)) {
|
||||
foreach ($this->_fixtures as $fixture) {
|
||||
$fixture->insert($this->db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->Controller =& new AuthTestController();
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
|
||||
|
@ -418,6 +471,15 @@ class AuthTest extends CakeTestCase {
|
|||
$this->assertFalse($user);
|
||||
$this->Controller->Session->del('Auth');
|
||||
|
||||
$this->Controller->Auth->userModel = 'UuidUser';
|
||||
$this->Controller->Auth->login('47c36f9c-bc00-4d17-9626-4e183ca6822b');
|
||||
|
||||
$user = $this->Controller->Auth->user();
|
||||
$expected = array('UuidUser' => array(
|
||||
'id' => '47c36f9c-bc00-4d17-9626-4e183ca6822b', 'title' => 'Unique record 1', 'count' => 2, 'created' => '2008-03-13 01:16:23', 'updated' => '2008-03-13 01:18:31'
|
||||
));
|
||||
$this->assertEqual($user, $expected);
|
||||
$this->Controller->Session->del('Auth');
|
||||
}
|
||||
/**
|
||||
* testAuthorizeFalse method
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue