Zend Framework ACL не извлекает столбец «Роль» из базы данных

В настоящее время я работаю над проектом, который требует ACL. Проблема в том, что столбец «роль» не идентифицирован. У меня все роли предопределены в таблице «пользователи».

Файл AuthPlugin

    $auth = Zend_Auth::getInstance();

// If user is not logged in and is not requesting login page
// - redirect to login page.
if (!$auth->hasIdentity()
&& $request->getControllerName() != $loginController
&& $request->getActionName()     != $loginAction) {

$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
$redirector->gotoSimpleAndExit($loginAction, $loginController);
}

// User is logged in or on login page.

if ($auth->hasIdentity()) {
$registry = Zend_Registry::getInstance();
$acl = $registry->get('acl');
$identity = $auth->getIdentity();
$isAllowed = $acl->isAllowed($identity->role,
$request->getControllerName(),
$request->getActionName());
if (!$isAllowed) {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
$redirector->gotoUrlAndExit('/');
}
}
}
}

Конфигурация ACL

<?php
$acl = new Zend_Acl();

$roles  = array('Administrator', 'User');
$controllers = array('cart', 'index', 'user', 'purchase');
foreach ($roles as $role) {
$acl->addRole(new Zend_Acl_Role($role));
}
foreach ($controllers as $controller) {
$acl->add(new Zend_Acl_Resource($controller));
}
$acl->allow('Administrator');
$acl->allow('User');
$acl->deny('User', 'Administrator');

$registry = Zend_Registry::getInstance();
$registry->set('acl', $acl);

контроллер

  public function indexAction()
{
$form = new Application_Form_Login();
$request = $this->getRequest();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
if ($this->_process($form->getValues())) {
$this->_helper->redirector('index', 'index');
}
}
}
$this->view->form = $form;
}

protected function _process($values)
{
$adapter = $this->_getAuthAdapter();
$adapter->setIdentity($values['username']);
$adapter->setCredential($values['password']);

$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
if ($result->isValid()) {
$user = $adapter->getResultRowObject();
$auth->getStorage()->write($user);
return true;
}
return false;
}

protected function _getAuthAdapter()
{
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);

$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setIdentity($username)
->setCredentialColumn('password')
->setCredentialTreatment('MD5(?)');
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
$data = $authAdapter->getResultRowObject(null, 'password'); // without password
$auth->getStorage()->write($data);
return $authAdapter;
}

при попытке войти я получаю сообщение об ошибке как

Message: A value for the identity was not provided prior to authentication with Zend_Auth_Adapter_DbTable.

Пожалуйста, скажите мне, как я могу получить «роль» из таблицы пользователей.

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector