Fixing order of operations for AuthComponent

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4480 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-02-08 22:10:58 +00:00
parent a7653e4d80
commit b5dc025a61

View file

@ -172,10 +172,12 @@ class AuthComponent extends Object {
* @return void * @return void
*/ */
function startup(&$controller) { function startup(&$controller) {
if (low($controller->name) == 'app' || (low($controller->name) == 'tests' && DEBUG > 0)) { if (low($controller->name) == 'app' || (low($controller->name) == 'tests' && DEBUG > 0)) {
return; return;
} }
if (!$this->_setDefaults($controller)) {
return;
}
// Hash incoming passwords // Hash incoming passwords
if (isset($controller->data[$this->userModel])) { if (isset($controller->data[$this->userModel])) {
@ -184,9 +186,10 @@ class AuthComponent extends Object {
$controller->data[$this->userModel][$this->fields['password']] = Security::hash($controller->data[$this->userModel][$this->fields['password']]); $controller->data[$this->userModel][$this->fields['password']] = Security::hash($controller->data[$this->userModel][$this->fields['password']]);
} }
} }
$this->data = $controller->data;
if (!$this->_setDefaults($controller)) { if ($this->allowedActions == array('*') || in_array($controller->action, $this->allowedActions)) {
return; return false;
} }
if (!isset($controller->params['url']['url'])) { if (!isset($controller->params['url']['url'])) {
@ -249,12 +252,6 @@ class AuthComponent extends Object {
* @return void * @return void
*/ */
function _setDefaults(&$controller) { function _setDefaults(&$controller) {
$this->data = $controller->data;
if ($this->allowedActions == array('*') || in_array($controller->action, $this->allowedActions)) {
return false;
}
if (empty($this->userModel)) { if (empty($this->userModel)) {
$classes = array_values(array_intersect( $classes = array_values(array_intersect(
array_map('strtolower', get_declared_classes()), array_map('strtolower', get_declared_classes()),
@ -388,7 +385,7 @@ class AuthComponent extends Object {
*/ */
function validate($object, $user = null) { function validate($object, $user = null) {
$user = $this->identify($user); $user = $this->identify($user);
if ($user == null) { if (empty($user)) {
return false; return false;
} }
pr($user); pr($user);
@ -449,8 +446,11 @@ class AuthComponent extends Object {
* @return array User record data, or null, if the user could not be identified. * @return array User record data, or null, if the user could not be identified.
*/ */
function identify($user = null) { function identify($user = null) {
if ($user == null) { if (empty($user)) {
$model =& $this->getUserModel(); $user = $this->user();
if (empty($user)) {
return null;
}
} else if (is_object($user) && is_a($user, 'Model')) { } else if (is_object($user) && is_a($user, 'Model')) {
if (!$user->exists()) { if (!$user->exists()) {
return null; return null;