diff --git a/application/Acl.php b/application/Acl.php
index a2f1953..a0c7f65 100644
--- a/application/Acl.php
+++ b/application/Acl.php
@@ -2,6 +2,10 @@
class Acl extends Zend_Acl
{
+ const ROLE_VISITOR = 'visitor';
+ const ROLE_MEMBER = 'member';
+ const ROLE_FIKTIV = 'fiktiv';
+
public function __construct()
{
// Add roles
@@ -12,15 +16,25 @@ class Acl extends Zend_Acl
// Set accessrights
$this->loadAccess();
+
}
+ public function isAllowed($role = null, $resource = null, $privilege = null)
+ {
+ if ($role instanceof User) {
+ $role = $role->userRole;
+ }
+
+ return parent::isAllowed($role, $resource, $privilege);
+ }
+
protected function loadRoles()
{
- $this->addRole(new Zend_Acl_Role('visitor'));
- $this->addRole(new Zend_Acl_Role('member'), 'visitor');
- $this->addRole(new Zend_Acl_Role('team'), 'member');
+ $this->addRole(new Zend_Acl_Role(self::ROLE_VISITOR));
+ $this->addRole(new Zend_Acl_Role(self::ROLE_MEMBER), self::ROLE_VISITOR);
+ $this->addRole(new Zend_Acl_Role(self::ROLE_FIKTIV), self::ROLE_MEMBER);
}
@@ -39,13 +53,13 @@ class Acl extends Zend_Acl
$this->_setDefaultAccess();
// Blog
- $this->allow('member', 'blog', 'comment');
+ $this->allow(self::ROLE_MEMBER, 'blog', 'comment');
// Profile
- $this->deny('visitor','profile','read');
+ $this->deny(self::ROLE_VISITOR,'profile','read');
// Admin
- $this->allow('team', 'admin', array('read', 'write', 'delete'));
+ $this->allow(self::ROLE_FIKTIV, 'admin', array('read', 'write', 'delete'));
}
@@ -53,15 +67,15 @@ class Acl extends Zend_Acl
protected function _setDefaultAccess()
{
$defaults = array(
- 'visitor' => array('read'),
- 'member' => array('read'),
- 'team' => array('read','write', 'delete')
+ self::ROLE_VISITOR => array('read'),
+ self::ROLE_MEMBER => array('read'),
+ self::ROLE_FIKTIV => array('read','write', 'delete')
);
foreach ($defaults as $role => $privileges) {
foreach ($this->getResources() as $resource) {
-
+
$this->allow($role,$resource,$privileges);
}
}
diff --git a/application/Bootstrap.php b/application/Bootstrap.php
index 2710a77..7e289c0 100644
--- a/application/Bootstrap.php
+++ b/application/Bootstrap.php
@@ -16,6 +16,9 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
$this->bootstrap('translate');
$this->bootstrap('view');
+ $this->bootstrap('acl');
+ $this->bootstrap('models');
+
$navConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'navigation');
$navigation = new Zend_Navigation($navConfig);
@@ -23,7 +26,16 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view = $this->getResource('view');
$view->navigation()->setTranslator($this->getResource('translate'));
$view->navigation($navigation);
-
+ $view->navigation()->setAcl($this->getResource('acl'));
+
+ // Set userrole for navigation
+ $auth = Zend_Auth::getInstance();
+ //var_dump($auth->getIdentity()->userRole);
+ if ($auth->hasIdentity()) {
+ $view->navigation()->setRole($auth->getIdentity()->userRole);
+ } else {
+ $view->navigation()->setRole(Acl::ROLE_VISITOR);
+ }
return $navigation;
}
@@ -171,6 +183,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
*/
protected function _initModels()
{
+ $this->bootstrap('front');
$this->bootstrap('autoloader');
// Include global model directory
diff --git a/application/configs/navigation.xml b/application/configs/navigation.xml
index 6c0c17f..f8ec25e 100644
--- a/application/configs/navigation.xml
+++ b/application/configs/navigation.xml
@@ -52,6 +52,16 @@
index
+
+
+ default
+ default
+ dummy
+ dummy
+ blog
+ write
+
+
default-default
diff --git a/application/models/Mapper/User.php b/application/models/Mapper/User.php
index 7ff400e..c5d1402 100644
--- a/application/models/Mapper/User.php
+++ b/application/models/Mapper/User.php
@@ -5,33 +5,19 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract
protected function _createUser($object)
{
-
- $user = new User();
- // What happens?
if ($object instanceof stdClass)
$object = (array) $object;
- if ($object instanceof Zend_Db_Table_Row) {
-
- $user->setId($object->id);
- $user->setEmail($object->email);
- $user->setFirstName($object->firstName);
- $user->setLastName($object->lastName);
-
- } else if (is_array($object)) {
-
- $user->setId($object['id']);
- $user->setEmail($object['email']);
- $user->setFirstName($object['firstName']);
- $user->setLastName($object['lastName']);
-
- } else {
- $user = null;
- }
+ if ($object instanceof Zend_Db_Table_Row)
+ $object = $object->toArray();
+
+ $user = null;
+ if (is_array($object))
+ $user = new User($object);
return $user;
}
@@ -95,6 +81,7 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract
// Check result
if ($result->isValid()) {
+
// Keep all but password and salt in session.
$storage = $auth->getStorage();
$storage->write($this->_createUser($authAdapter->getResultRowObject(null, array('password', 'salt'))));
@@ -134,10 +121,9 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract
{
$data = $user->toArray();
unset($data['id']);
-
- return $this->_dbTable->update(
- $data,
- $this->_dbTable->getAdapter()->quoteInto('id = ?',$user->getId())
+
+ return $this->_dbTable->update($data,
+ $this->_dbTable->getAdapter()->quoteInto('id = ?',$user->getId())
);
}
diff --git a/application/models/User.php b/application/models/User.php
index 284aadb..df7f971 100644
--- a/application/models/User.php
+++ b/application/models/User.php
@@ -20,6 +20,7 @@ class User extends Fiktiv_Model_Abstract
'isDeleted' => false,
'avatar' => self::AVATAR_NONE,
'avatarImage' => null,
+ 'userRole' => Acl::ROLE_VISITOR
);
public function setId($id)
diff --git a/application/modules/default/controllers/IndexController.php b/application/modules/default/controllers/IndexController.php
index dd29044..03130e1 100644
--- a/application/modules/default/controllers/IndexController.php
+++ b/application/modules/default/controllers/IndexController.php
@@ -17,11 +17,13 @@ class IndexController extends Fiktiv_Controller_Action
echo '';
print_r($r);
echo '';
+
+ Zend_Debug::dump(Zend_Auth::getInstance()->getIdentity(), 'User');
}
public function aboutAction()
{
-
+
}
public function test()
diff --git a/library/Fiktiv/Model/Abstract.php b/library/Fiktiv/Model/Abstract.php
index eb8ecdc..0df2f0d 100644
--- a/library/Fiktiv/Model/Abstract.php
+++ b/library/Fiktiv/Model/Abstract.php
@@ -34,7 +34,7 @@ abstract class Fiktiv_Model_Abstract
return $this->$methodName($value);
}
- if (array_key_exists($name, $this->_data))
+ if (array_key_exists($name, $this->_default))
return $this->_data[$name] = $value;
}