Browse Source

make AuthenticationException handle controllers from different apps, plus a redirect param

master
Jenny Lindberg 10 years ago
parent
commit
f1e02fb5a0
3 changed files with 23 additions and 11 deletions
  1. +8
    -2
      lib/SparkLib/Application.php
  2. +11
    -9
      lib/SparkLib/Exception/AuthenticationException.php
  3. +4
    -0
      lib/SparkLib/Exception/SparkException.php

+ 8
- 2
lib/SparkLib/Application.php View File

@ -277,13 +277,19 @@ abstract class Application {
// Override the current controller and validate the new target
$this->_controller = $e->controller();
$this->_controllerClass = $this->makeControllerName($this->_controller);
$this->_controllerClass = $this->makeControllerName($this->_controller, $e->appName());
$this->_ctl = new $this->_controllerClass($this);
$this->_action = $e->action();
$this->validate();
$redirect = $this->_ctl->linkAction($this->_action)->redirect(301);
if ($e->appName()) {
$app_name = $e->appName();
} else {
$app_name = $this->appName();
}
$redirect = $app_name::externalLink($this->_controller)->action($this->_action)->params($e->params())->redirect(301);
$redirect->fire();
}


+ 11
- 9
lib/SparkLib/Exception/AuthenticationException.php View File

@ -10,17 +10,19 @@ namespace SparkLib\Exception;
class AuthenticationException extends SparkException
{
public function __construct($message = "Authentication Required", $code = 0, Exception $previous = null) {
if($message instanceof \SparkLib\Application\Link) {
// this kind of feels dirty.
$this->_action = $message->getAction();
$this->_controller = $message->getController();
$message = 'Authentication Required';
} else {
$this->_action = 'login';
$this->_controller = 'account';
public function __construct ($redirect = null, $code = 0, Exception $previous = null)
{
$this->_app_name = 'Commerce';
$this->_controller = 'account';
$this->_action = 'login';
if ($redirect instanceof \SparkLib\Application\Link) {
$this->_params = 'redirect=' . $redirect->path(false);
} else if ($redirect) {
$this->_params = 'redirect=' . $redirect;
}
$message = 'Please log in.';
parent::__construct($message, $code, $previous);
}
}

+ 4
- 0
lib/SparkLib/Exception/SparkException.php View File

@ -15,7 +15,9 @@ use \SparkLib\Blode\Event;
class SparkException extends \Exception
{
protected $_action = 'index';
protected $_app_name = '';
protected $_controller = 'index';
protected $_params = '';
// require a message which will be displayed to the user
public function __construct($message, $code = 0, Exception $previous = null) {
@ -30,7 +32,9 @@ class SparkException extends \Exception
}
public function action() { return $this->_action; }
public function appName() { return $this->_app_name; }
public function controller() { return $this->_controller; }
public function params() { return $this->_params; }
// these are user-level exceptions, never display a stack-trace.
public function __toString() { return $this->message; }


|||||||
x
 
000:0
Loading…
Cancel
Save