Authentication is set in the _initAutoload file, for example. eg:
if(Zend_Auth::getInstance()->hasIdentity()) { Zend_Registry::set('role', Zend_Auth::getInstance() ->getStorage()->read()->role); }else{ Zend_Registry::set('role', 'guests'); }
In the case of REST authentication, you may need authentication by simply passing in the login parameters rather than logging in through the form.
So it might look like this: AuthenticationController :
private function getAuthAdapter() { $authAdapter = new Zend_Auth_Adapter_DbTable( Zend_Db_Table::getDefaultAdapter()); $authAdapter->setTableName('users') // the db table where users are stored ->setIdentityColumn('email') ->setCredentialColumn('password') ->setCredentialTreatment('SHA1(CONCAT(?,salt))'); return $authAdapter; } public function logoutAction() { Zend_Auth::getInstance()->clearIdentity(); $this->_redirect('index/index'); } public function loginAction(){ if (Zend_Auth::getInstance()->hasIdentity()){ $this->_redirect('index/index'); } if ($request->isPost()){ $username = $request->getPost('username'); $password = $request->getPost('password'); if ($username != "" && $password != "") { $authAdapter = $this->getAuthAdapter (); $authAdapter->setIdentity($username) ->setCredential($password); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if($result->isValid()){ $identity = $authAdapter->getResultRowObject(); $authStorage = $auth->getStorage(); $authStorage->write($identity); $this->_redirect ( 'index/index' ); } } } }
If you need more help with zend_auth and zend_acl , you can take a look.
source share