mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 11:32:40 +00:00
Fixes #3217, Auth flash message when Auth->authorize = false is not shown.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5680 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
0f1de003c6
commit
b89c3c98ad
2 changed files with 37 additions and 24 deletions
|
@ -305,6 +305,7 @@ class AuthComponent extends Object {
|
|||
} else {
|
||||
if (!$this->user()) {
|
||||
if (!$this->RequestHandler->isAjax()) {
|
||||
$this->Session->setFlash($this->authError, 'default', array(), 'auth');
|
||||
$this->Session->write('Auth.redirect', $url);
|
||||
$controller->redirect($this->loginAction, null, true);
|
||||
return false;
|
||||
|
@ -819,4 +820,4 @@ class AuthComponent extends Object {
|
|||
return $url;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -201,6 +201,8 @@ class AuthTest extends CakeTestCase {
|
|||
@$this->Controller->_initComponents();
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
ClassRegistry::addObject('view', new View($this->Controller));
|
||||
$this->Controller->Session->del('Auth');
|
||||
$this->Controller->Session->del('Message.auth');
|
||||
}
|
||||
|
||||
function testNoAuth() {
|
||||
|
@ -240,6 +242,10 @@ class AuthTest extends CakeTestCase {
|
|||
$this->Controller->Auth->authorize = false;
|
||||
$result = $this->Controller->Auth->startup($this->Controller);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$this->Controller->Session->del('Auth');
|
||||
$result = $this->Controller->Auth->startup($this->Controller);
|
||||
$this->assertTrue($this->Controller->Session->check('Message.auth'));
|
||||
}
|
||||
|
||||
function testAuthorizeController(){
|
||||
|
@ -253,6 +259,7 @@ class AuthTest extends CakeTestCase {
|
|||
|
||||
$this->Controller->params['testControllerAuth'] = 1;
|
||||
$result = $this->Controller->Auth->startup($this->Controller);
|
||||
$this->assertTrue($this->Controller->Session->check('Message.auth'));
|
||||
$this->assertFalse($result);
|
||||
|
||||
$this->Controller->Session->del('Auth');
|
||||
|
@ -272,6 +279,8 @@ class AuthTest extends CakeTestCase {
|
|||
$this->assertTrue($result);
|
||||
|
||||
$this->Controller->Session->del('Auth');
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$this->assertTrue($this->Controller->Session->check('Message.auth'));
|
||||
$result = $this->Controller->Auth->isAuthorized();
|
||||
$this->assertFalse($result);
|
||||
|
||||
|
@ -328,39 +337,41 @@ class AuthTest extends CakeTestCase {
|
|||
|
||||
$this->assertTrue($this->Controller->Auth->isAuthorized());
|
||||
|
||||
|
||||
$this->Controller->Session->del('Auth');
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$this->assertTrue($this->Controller->Session->check('Message.auth'));
|
||||
}
|
||||
|
||||
function testLoginRedirect() {
|
||||
$backup = $_SERVER['HTTP_REFERER'];
|
||||
$backup = $_SERVER['HTTP_REFERER'];
|
||||
|
||||
$_SERVER['HTTP_REFERER'] = false;
|
||||
$_SERVER['HTTP_REFERER'] = false;
|
||||
|
||||
$this->Controller->Session->write('Auth', array('AuthUser' => array('id'=>'1', 'username'=>'nate')));
|
||||
|
||||
$this->Controller->params['url']['url'] = 'users/login';
|
||||
$this->Controller->Auth->initialize($this->Controller);
|
||||
$this->Controller->params['url']['url'] = 'users/login';
|
||||
$this->Controller->Auth->initialize($this->Controller);
|
||||
|
||||
$this->Controller->Auth->userModel = 'AuthUser';
|
||||
$this->Controller->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'welcome');
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$expected = $this->Controller->Auth->_normalizeURL($this->Controller->Auth->loginRedirect);
|
||||
$this->assertEqual($expected, $this->Controller->Auth->redirect());
|
||||
$this->Controller->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'welcome');
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$expected = $this->Controller->Auth->_normalizeURL($this->Controller->Auth->loginRedirect);
|
||||
$this->assertEqual($expected, $this->Controller->Auth->redirect());
|
||||
|
||||
$this->Controller->Session->del('Auth');
|
||||
|
||||
$this->Controller->params['url']['url'] = 'admin/';
|
||||
$this->Controller->Auth->initialize($this->Controller);
|
||||
$this->Controller->params['url']['url'] = 'admin/';
|
||||
$this->Controller->Auth->initialize($this->Controller);
|
||||
$this->Controller->Auth->userModel = 'AuthUser';
|
||||
$this->Controller->Auth->loginRedirect = null;
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$expected = $this->Controller->Auth->_normalizeURL('admin/');
|
||||
$this->assertEqual($expected, $this->Controller->Auth->redirect());
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$expected = $this->Controller->Auth->_normalizeURL('admin/');
|
||||
$this->assertTrue($this->Controller->Session->check('Message.auth'));
|
||||
$this->assertEqual($expected, $this->Controller->Auth->redirect());
|
||||
|
||||
$this->Controller->Session->del('Auth');
|
||||
|
||||
$_SERVER['HTTP_REFERER'] = '/admin/';
|
||||
$_SERVER['HTTP_REFERER'] = '/admin/';
|
||||
|
||||
$this->Controller->Session->write('Auth', array('AuthUser' => array('id'=>'1', 'username'=>'nate')));
|
||||
|
||||
|
@ -372,13 +383,13 @@ class AuthTest extends CakeTestCase {
|
|||
|
||||
$this->Controller->Auth->userModel = 'AuthUser';
|
||||
$this->Controller->Auth->loginRedirect = false;
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$expected = $this->Controller->Auth->_normalizeURL('admin');
|
||||
$this->assertEqual($expected, $this->Controller->Auth->redirect());
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$expected = $this->Controller->Auth->_normalizeURL('admin');
|
||||
$this->assertEqual($expected, $this->Controller->Auth->redirect());
|
||||
|
||||
$_SERVER['HTTP_REFERER'] = $backup;
|
||||
$this->Controller->Session->del('Auth');
|
||||
}
|
||||
$_SERVER['HTTP_REFERER'] = $backup;
|
||||
$this->Controller->Session->del('Auth');
|
||||
}
|
||||
|
||||
function testEmptyUsernameOrPassword() {
|
||||
$this->AuthUser =& new AuthUser();
|
||||
|
@ -401,12 +412,13 @@ class AuthTest extends CakeTestCase {
|
|||
|
||||
$this->Controller->Auth->startup($this->Controller);
|
||||
$user = $this->Controller->Auth->user();
|
||||
$this->assertTrue($this->Controller->Session->check('Message.auth'));
|
||||
$this->assertEqual($user, false);
|
||||
$this->Controller->Session->del('Auth');
|
||||
}
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
unset($this->Controller, $this->AuthUser);
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue