mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
updating auth, fixes #4417 ajaxLogin rendering
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6893 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
3b524b70d5
commit
1623fa89f8
2 changed files with 43 additions and 19 deletions
|
@ -28,7 +28,7 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
uses('set', 'security');
|
||||
App::import(array('Router', 'Security'));
|
||||
|
||||
/**
|
||||
* Authentication control component class
|
||||
|
@ -272,23 +272,20 @@ class AuthComponent extends Object {
|
|||
|
||||
$this->data = $controller->data = $this->hashPasswords($controller->data);
|
||||
|
||||
if (!isset($controller->params['url']['url'])) {
|
||||
$url = '';
|
||||
} else {
|
||||
if (is_array($this->loginAction)) {
|
||||
$url = $controller->params['controller'].'/'.$controller->params['action'];
|
||||
} elseif (isset($controller->params['url']['url'])) {
|
||||
$url = $controller->params['url']['url'];
|
||||
}
|
||||
$url = Router::normalize($url);
|
||||
$loginAction = Router::normalize($this->loginAction);
|
||||
|
||||
if (is_array($this->loginAction)) {
|
||||
$this->loginAction = Router::url($this->loginAction);
|
||||
$url = $controller->params['controller'].'/'.$controller->params['action'];
|
||||
}
|
||||
$this->loginAction = Router::normalize($this->loginAction);
|
||||
|
||||
if ($this->loginAction != Router::normalize($url) && ($this->allowedActions == array('*') || in_array($controller->action, $this->allowedActions))) {
|
||||
if ($loginAction != $url && ($this->allowedActions == array('*') || in_array($controller->action, $this->allowedActions))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->loginAction == Router::normalize($url)) {
|
||||
if ($loginAction == $url) {
|
||||
if (empty($controller->data) || !isset($controller->data[$this->userModel])) {
|
||||
if (!$this->Session->check('Auth.redirect') && env('HTTP_REFERER')) {
|
||||
$this->Session->write('Auth.redirect', $controller->referer());
|
||||
|
@ -316,12 +313,12 @@ class AuthComponent extends Object {
|
|||
if (!$this->RequestHandler->isAjax()) {
|
||||
$this->Session->setFlash($this->authError, 'default', array(), 'auth');
|
||||
$this->Session->write('Auth.redirect', $url);
|
||||
$controller->redirect($this->loginAction, null, true);
|
||||
$controller->redirect($loginAction, null, true);
|
||||
return false;
|
||||
} elseif (!empty($this->ajaxLogin)) {
|
||||
$controller->viewPath = 'elements';
|
||||
$controller->render($this->ajaxLogin, 'ajax');
|
||||
exit();
|
||||
echo $controller->render($this->ajaxLogin, 'ajax');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -376,7 +373,7 @@ class AuthComponent extends Object {
|
|||
return false;
|
||||
}
|
||||
if (empty($this->loginAction)) {
|
||||
$this->loginAction = Router::url(array('controller'=> Inflector::underscore(Inflector::pluralize($this->userModel)), 'action'=>'login'));
|
||||
$this->loginAction = Router::normalize(array('controller'=> Inflector::underscore(Inflector::pluralize($this->userModel)), 'action'=>'login'));
|
||||
}
|
||||
if (empty($this->sessionKey)) {
|
||||
$this->sessionKey = 'Auth.' . $this->userModel;
|
||||
|
@ -622,7 +619,7 @@ class AuthComponent extends Object {
|
|||
$redir = $this->Session->read('Auth.redirect');
|
||||
$this->Session->delete('Auth.redirect');
|
||||
|
||||
if (Router::normalize($redir) == $this->loginAction) {
|
||||
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
|
||||
$redir = $this->loginRedirect;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
uses('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl');
|
||||
App::import(array('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl'));
|
||||
|
||||
uses('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl');
|
||||
App::import(array('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl'));
|
||||
Configure::write('Security.salt', 'JfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
|
||||
/**
|
||||
* Short description for class.
|
||||
|
@ -88,6 +88,7 @@ class AuthTestController extends Controller {
|
|||
}
|
||||
|
||||
function add() {
|
||||
echo "add";
|
||||
}
|
||||
|
||||
function redirect($url, $status, $exit) {
|
||||
|
@ -466,6 +467,32 @@ class AuthTest extends CakeTestCase {
|
|||
Configure::write('Routing.admin', $admin);
|
||||
}
|
||||
|
||||
function testAjaxLogin() {
|
||||
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest";
|
||||
|
||||
$url = '/auth_test/add';
|
||||
$this->Controller->params = Router::parse($url);
|
||||
Router::setRequestInfo(array($this->Controller->passedArgs, array('base' => null, 'here' => $url, 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())));
|
||||
|
||||
$this->Controller->Auth->RequestHandler->startup($this->Controller);
|
||||
$this->Controller->Auth->initialize($this->Controller);
|
||||
|
||||
$this->Controller->Auth->loginAction = array('controller' => 'auth_test', 'action' => 'login');
|
||||
$this->Controller->Auth->userModel = 'AuthUser';
|
||||
|
||||
$this->Controller->Auth->ajaxLogin = 'test_element';
|
||||
|
||||
ob_start();
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/test element/', $result);
|
||||
$this->assertNoPattern('/add/', $result);
|
||||
|
||||
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
unset($this->Controller, $this->AuthUser);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue