Leo Büttiker wrote:
Hi Steven,
For the first one _forward seams like the correct method
(http://framework.zend.com/apidoc/core/Zend_Controller/Zend_Controller_Actio
n.html#_forward).

For handling errors you probably should have a look into
Zend_Controller_Plugin_ErrorHandler
(http://framework.zend.com/manual/en/zend.controller.plugins.html) which is
the standard way to do it.
Cheers,
Leo

-----Ursprüngliche Nachricht-----
Von: Truppe Steven [mailto:[EMAIL PROTECTED] Gesendet: Freitag, 31. August 2007 20:51
An: [email protected]
Betreff: [fw-general] need help with simple authentication plugin (how to
redirect to another :model :controller :action?)

i'm on writing a simple Zend_Acl&Zend_Auth Plugin that checks in
preDispatch() if there are any rules for resources related to the actual
module/controller/action.

this all works fine, my question now is how can i forward to the
controller:admin action:login if i find that the current user needs to
login because he has not enouth permissions set ?

I also want to handle the Error stuff inside postDispatch(). So if there
is an exception it forwards to model:default, controller:Error,
action:customerror.

There is a method called _forward but i can't remember how to use it and
in which context i have use it.


best regards,
Truppe Steven




The following fragment may help:

class Acl_Plugin extends Zend_Controller_Plugin_Abstract
{
   // true or  false
   private $_locked =  false;   //  set true to lock site
   private $_admin_allowed =  true;
   private $_logging = true ;   //  set true to log route to debug log
private $_restricted = array( 'admin', 'services', 'info'); // restricted modules public function preDispatch($request)
   {
       Zend_Session::start();  //  we use a namespaced passkey
       $pass_ns = new Zend_Session_Namespace('passKey');  // get passkey

if($this->_logging) { // if logging variable true $logger = Zend_Registry::get('logger'); // log route for debugging $logger->debug("ACL plugin Route->$request->module::$request->controller::$request->action");
       }
if($this->_admin_allowed) if ($pass_ns->passkey === get_pass_phrase()) // has correct pass key
               return;
if($this->_locked) { // If locked variable true
           $request->setModuleName('default');     // The site is locked,
             $request->setControllerName('site');   // reroute to homepage
             $request->setActionName('locked');
           return;
       }
$module = $request->module; // Our acl uses modules if (!in_array( $module, $this->_restricted)) // not a restricted module
          return;                                    // so, nothing to do
if ($pass_ns->passkey === get_pass_phrase()) // has correct pass key return; // so, we let it go forward
       else                                          // no pass key, so
{ // reroute to error message
           $request->setModuleName('default');
             $request->setControllerName('error');
             $request->setActionName('unauthorized');
       }
}
function get_pass_phrase()
{
   $pass_phrase = 'YADA-YADA-YADA';
$today = date("Ymd"); // allow automatic aging return md5($pass_phrase . $today ); }


Cheers ,

pat

Reply via email to