Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Default to loginRedirect, if set, on authError in AuthComponent #585

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2012
  1. @shama

    Default to loginRedirect, if set, on authError in AuthComponent

    shama authored
    Implements #2390
    Based on the patch written by @dereuromark
This page is out of date. Refresh to see the latest.
View
6 lib/Cake/Controller/Component/AuthComponent.php
@@ -332,7 +332,11 @@ public function startup(Controller $controller) {
}
$this->flash($this->authError);
- $controller->redirect($controller->referer('/'), null, true);
+ $default = '/';
+ if (!empty($this->loginRedirect)) {
+ $default = $this->loginRedirect;
+ }
+ $controller->redirect($controller->referer($default), null, true);
return false;
}
View
45 lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
@@ -804,8 +804,8 @@ public function testLoginRedirect() {
$expected = Router::normalize('/admin');
$this->assertEquals($expected, $this->Auth->redirect());
- //Ticket #4750
- //named params
+ // Ticket #4750
+ // Named Parameters
$this->Controller->request = $this->Auth->request;
$this->Auth->Session->delete('Auth');
$url = '/posts/index/year:2008/month:feb';
@@ -817,7 +817,7 @@ public function testLoginRedirect() {
$expected = Router::normalize('posts/index/year:2008/month:feb');
$this->assertEquals($expected, $this->Auth->Session->read('Auth.redirect'));
- //passed args
+ // Passed Arguments
$this->Auth->Session->delete('Auth');
$url = '/posts/view/1';
$this->Auth->request->addParams(Router::parse($url));
@@ -848,7 +848,7 @@ public function testLoginRedirect() {
$_GET = $_back;
- //external authed action
+ // External Authed Action
$_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message';
$this->Auth->Session->delete('Auth');
$url = '/posts/edit/1';
@@ -863,7 +863,7 @@ public function testLoginRedirect() {
$expected = Router::normalize('/posts/edit/1');
$this->assertEquals($expected, $this->Auth->Session->read('Auth.redirect'));
- //external direct login link
+ // External Direct Login Link
$_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message';
$this->Auth->Session->delete('Auth');
$url = '/AuthTest/login';
@@ -880,7 +880,40 @@ public function testLoginRedirect() {
}
/**
- * test that no redirects or authorization tests occur on the loginAction
+ * Default to loginRedirect, if set, on authError.
+ *
+ * @return void
+ */
+ public function testDefaultToLoginRedirect() {
+ $_SERVER['HTTP_REFERER'] = false;
+ $_ENV['HTTP_REFERER'] = false;
+ putenv('HTTP_REFERER=');
+
+ $url = '/party/on';
+ $this->Auth->request = $CakeRequest = new CakeRequest($url);
+ $this->Auth->request->addParams(Router::parse($url));
+ $this->Auth->authorize = array('Controller');
+ $this->Auth->login(array('username' => 'mariano', 'password' => 'cake'));
+ $this->Auth->loginRedirect = array(
+ 'controller' => 'something', 'action' => 'else',
+ );
+
+ $CakeResponse = new CakeResponse();
+ $Controller = $this->getMock(
+ 'Controller',
+ array('on', 'redirect'),
+ array($CakeRequest, $CakeResponse)
+ );
+
+ $expected = Router::url($this->Auth->loginRedirect, true);
+ $Controller->expects($this->once())
+ ->method('redirect')
+ ->with($this->equalTo($expected));
+ $this->Auth->startup($Controller);
+ }
+
+/**
+ * Test that no redirects or authorization tests occur on the loginAction
*
* @return void
*/
Something went wrong with that request. Please try again.