php - Zend _forward doesn't work after failed authentication (Zend Framework 1) -
after user fails authorisation i'd forward them login page. _forward method causes zend hang , give time out error (30 seconds exceeded).
the code login page handles both login , signup form, , forwards authorisation controller:
public function indexaction() { if ($this->_request->ispost()) { $formdata = $this->_request->getpost(); if (array_key_exists('signup', $formdata)) { $authaction = 'signup'; $form = 'signupform'; } elseif (array_key_exists('login', $formdata)) { $authaction = 'login'; $form = 'loginform'; } if ($this->$form->isvalid($formdata)) { $this->_forward($authaction, 'user-auth', null, $formdata); } else { $this->$form->populate($formdata); } } }
this works fine , redirects auth controller successfully. code inside login action of auth controller such:
public function loginaction() { $formdata = $this->_request->getpost(); $authadapter = new my_auth_adapter(); $authadapter->settablename('user') ->setidentity($formdata['username']) ->setcredential($formdata['password']) ->setidentitycolumn('username') ->setcredentialcolumn('password'); $result = $authadapter->authenticate(); if ($result->isvalid()) { // success, } else { $this->_forward('index', 'login', 'default', $formdata); } }
we arrive here fine, , successful authorisation works expected. in else statement placing forward original login controller (i wish populate username post error message) causes program hang, although redirect works fine.
i thought may because login controller re-detecting post data , i'm getting caught in infinite loop, removing $formdata last argument of forward doesn't change anything.
i've tried $formdata['errmsg'] = 'whatever' above forward , checking if key exists or if set in login controller, doesn't change thing either.
interestingly, time out error receive references auth dbtable adapter:
fatal error: maximum execution time of 30 seconds exceeded in /applications/mamp/mampserver/mysite/library/zend/auth/adapter/dbtable.php on line 174
any ideas may happening?
i think infinity looping between loginaction()
, indexaction()
.
check out difference between calls forward()
, redirect()
action helpers. former, forward()
internally change $request->isdispatched() == false
- means front controller execute targeted controller action without new http request.
the outcome of $this->_request->ispost()
true
, therefore $this->$form->isvalid($formdata)
again true, meaning going around in circles.
i know below different approach, believe more conventional separation of concerns zend 1 controllers.
// ... somecontroller.php public function getloginform(); public function getsignupform(); protected function authenticate($username, $password) { $authadapter = new my_auth_adapter(); $authadapter->settablename('user') ->setidentity($username) ->setcredential($password) ->setidentitycolumn('username') ->setcredentialcolumn('password'); $result = $authadapter->authenticate(); return ($result->isvalid()) ? true : false; } public function indexaction() { $form = $this->getloginform(); $request = $this->getrequest(); if ($request->ispost()) { if ($form->isvalid($request->getpost())) { if ($this->authenticate($form->getvalue('username'), $form->getvalue('username'))) { $this->redirect('/members'); // logged in } } } $this->view->form = $form; } public function signupaction() { // stuff signups! }
edit elaborate: forward()
controller action helper. job modify zend_controller_request_http
instance. zend_controller_request_http
class 1 returned when call $this->getrequest()
within controller.
the request instance encapsulates access $_post
, $_get
, stores values within object. calls such $request->setparam('someparam', 123)
set or these values rather standard direct access $_post['someparam']
or $_get['someparam']
.
the special case values module
,controller
,action
, dispatched
. these key's used zend_controller_front
, dispatcher when trying determine correct controller instantiate , action method execute.
a simplified example of how dispatch loop works:
while(! $request->isdispatched()) { $request->setdispatched(true); // if @ point here change setdispatched(true) // perhaps in controller action call forward() // whole dispatch loop called again // perhaps creating different controller $controllername = $request->getcontrollername(); $actionname = $request->getactionname(); $controller = new $controllername(); $controller->$actionname(); }
Comments
Post a Comment