[Resolvido] Problema com plugin acl
Como um amigo recomendou, estou parand de pegar tutoriais e tomei vergonha na cara pra fazer ou tentar fazer uma autenticacao decente, com recursos do zend...mas esta dando erro
segue codigo
<?php
//acl
class Application_Plugin_Acl extends Zend_Controller_Plugin_Abstract {
private $acl,$auth,$role;
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$this->_setupAcl();
$this->auth = Zend_Auth::getInstance();
$st = $this->auth->getStorage()->read();
isset($st->perfil_id) ? $this->role = $st->perfil_id : $this->role = 'guest';
$this->_Allowing();
}
protected function _setupAcl()
{
$this->acl = new Zend_Acl();
$this->acl->addResource(new Zend_Acl_Resource('Error'));
$this->acl->addResource(new Zend_Acl_Resource('Index'));
$this->acl->addResource(new Zend_Acl_Resource('Admin'));
$this->acl->addResource(new Zend_Acl_Resource('Noticias'));
$this->acl->addRole(new Zend_Acl_Role('guest'));
$this->acl->addRole(new Zend_Acl_Role('escritor'),new Zend_Acl_Role('guest'));
$this->acl->addRole(new Zend_Acl_Role('admin'),new Zend_Acl_Role('escritor'));
$this->acl->allow('guest','Error','error');
$this->acl->allow('guest','Index');
$this->acl->allow('escritor','Noticias');
$this->acl->allow('admin','Admin');
}
protected function _Allowing()
{
$p = new Perfil();
$st = $this->auth->getStorage()->read();
$perfil = $p->find($st->perfil_id)->current();
if(!$this->acl->isAllowed(isset($perfil)?$perfil:$this->role,$this->getRequest()->getControllerName(),$this->getRequest()->getActionName()))
{
$this->getRequest()->setActionName('login');
$this->getRequest()->setControllerName('auth');
}
}
}
<?php
//auth
class AuthController extends Zend_Controller_Action
{
public function init()
{
/ Initialize action controller here /
}
public function indexAction()
{
// action body
}
public function loginAction()
{
$loginform = new Application_Form_Login();
$loginform->setAction('/Auth/login')->setMethod(Zend_Form::METHOD_POST);
if($this->getRequest()->isPost())
{
$login = $this->_getParam('login');
$senha = $this->_getParam('senha');
$user = new Usuario();
$authadapter = new Zend_Auth_Adapter_DbTable($user->getDefaultAdapter());
$authadapter->setTableName('usuario')->setIdentityColumn('login')->setCredentialColumn('senha')->setCredentialTreatment('MD5(?)');
$authadapter->setCredential($senha)->setIdentity($login);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authadapter);
if($result->isValid())
{
$st = $auth->getStorage();
$userlogged = $authadapter->getResultRowObject(null,'senha');
$st->write($userlogged);
$this->_redirect('/Noticias');
}
}
$this->view->loginform = $loginform;
}
public function logoutAction(){
$this->_helper->viewRenderer->setNoRender(true);
$auth = Zend_Auth::getInstance();
$auth->clearIdentity();
$this->_redirect('/Auth/login');
}
}
<?php//boostrap
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload() {
$loader = Zend_Loader_Autoloader::getInstance ();
$loader->setFallbackAutoloader ( true );
$autoloader = new Zend_Application_Module_Autoloader(array(
'basePath' => APPLICATION_PATH,
'namespace' => ''
));
return $autoloader;
}
protected function _initFrontControllerPlugin(){
$front = $this->bootstrap('frontcontroller')->getresource('frontcontroller');
$front->registerPlugin(new Application_Plugin_Acl());
}
}
e a mensagem de erro
Notice: Trying to get property of non-object in C:\Zend\Apache2\htdocs\zfauthself\application\plugins\Acl.php on line 40
Notice: Trying to get property of non-object in C:\Zend\Apache2\htdocs\zfauthself\application\plugins\Acl.php on line 40
Fatal error: Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'error' not found' in C:\Zend\ZendServer\share\ZendFramework\library\Zend\Acl.php:365 Stack trace: #0 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Acl.php(846): Zend_Acl->get('error') #1 C:\Zend\Apache2\htdocs\zfauthself\application\plugins\Acl.php(42): Zend_Acl->isAllowed('guest', 'error', 'error') #2 C:\Zend\Apache2\htdocs\zfauthself\application\plugins\Acl.php(14): Application_Plugin_Acl->_Allowing() #3 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Plugin\Broker.php(309): Application_Plugin_Acl->preDispatch(Object(Zend_Controller_Request_Http)) #4 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Front.php(941): Zend_Controller_Plugin_Broker->preDispatch(Object(Zend_Controller_Request_Http)) #5 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() #6 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Application.php(366): Zend_Applicat in C:\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Plugin\Broker.php on line 312
onde errei, e o que fiz de errado?
Discussão (1)
Carregando comentários...