Saturday, 24 August 2013

Zend Framework is not finding indexAction but is finding init() function

Zend Framework is not finding indexAction but is finding init() function

So, all I have is a file in my Zend /Library folder called
RequestHandler.php. In here is a preDispatch() method which checks to see
if a Token exists for an authenticated login. If it does not it sends the
user to the LoginController method entitled indexAction. From my debug I
can see that LoginController > init() is called and completes. However,
the LoginController>indexAction() method does not even seem to be being
called(?) Even if I empty the method and just put a 'print 1;' in the
indexAction I can see it is not being called at all. What could be causing
such an error?
Until now I've been using Zend out of the box and actually got to building
a pretty big website but now I guess it's time to lift the hood on this
thing and figure out what is going on. If any of you guys have any input
let me know and as I get any good at Zend I'll eventually get to join you
in this community with some feedback of my own.
RequestHandler.php
<?php
/* * This Service will verify if the user is logged and check if they are
viewing what they are allowed to * It will set the logged_in so it can be
used to manipulate the views * */
class Services_RequestHandler extends Zend_Controller_Plugin_Abstract {
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$this->ensureSSL($request);
if ($request->getModuleName() == 'myflatchecker'
||
$request->getModuleName() == 'admin'
||
$request->getModuleName() == 'default') {
$this->authenticateUiRequest($request);
} else {
$this->authenticateApiRequest($request);
}
}
protected function ensureSSL($request) {
if ($_SERVER['SERVER_NAME'] != 'staging.flatchecker.com') {
$sslControllers = array('login', 'registration');
$sslModules = array('myflatchecker');
$controller = $request->getControllerName();
$action = $request->getActionName();
$module = $request->getModuleName();
//in some cases we should not never redirect
if ($action != 'stopwatch' && $controller != 'search' &&
$controller != 'review') {
if ($_SERVER['HTTPS']) {
if (!in_array($controller, $sslControllers) &&
!in_array($module, $sslModules)) {
$url = 'http://' . $_SERVER['HTTP_HOST'] .
$request->getRequestUri();
$redirector =
Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl($url);
}
} else {
if (in_array($controller, $sslControllers) ||
in_array($module, $sslModules)) {
$url = 'https://' . $_SERVER['HTTP_HOST'] .
$request->getRequestUri();
$redirector =
Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl($url);
}
}
}
}
}
protected function authenticateUiRequest(Zend_Controller_Request_Abstract
$request) {
$layout = Zend_Layout::getMvcInstance();
$view = $layout->getView();
//$controller = $request->getControllerName();
$module = $request->getModuleName();
$auth = Zend_Auth::getInstance();
if (!$auth->hasIdentity()) {
$view->logged_in = null;
if ($module == 'myflatchecker' || $module == 'admin') {
//$request->redirector('login');
$request->setControllerName('login')
->setActionName('index')
->setModuleName('default');
}
} else {
//if the user is logged but is not an admin they must not access
the admin pages
$user = $auth->getIdentity();
if ($module == 'admin' && !$user->admin) {
$request->setControllerName('error')
->setActionName('access')
->setModuleName('default');
} else {
$view->logged_in = true;
}
}
}
protected function authenticateApiRequest(Zend_Controller_Request_Abstract
$request) {
$token = $request->getParam('access_token');
if (!isset($token) && $request->getControllerName() != 'login') {
$request->setControllerName('login')
->setActionName('index');
} else {
if (isset($token)) {
//access token
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('users')
->setIdentityColumn('access_token')
->setCredentialColumn('access_token');
$authAdapter->setIdentity($token);
$authAdapter->setCredential($token);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if (!$result->isValid()) {
$request->setControllerName('login')
->setActionName('index');
}
}
}
}
}
?>
Also, this is not an SSL issue as I've turned the SSL testing off and the
same error exists!

No comments:

Post a Comment