Exemplo n.º 1
0
 public function indexAction()
 {
     $this->view->setTemplateBefore('private');
     if ($this->request->isPost()) {
         //Validate the profile
         $profile = Profiles::findFirstById($this->request->getPost('profileId'));
         if ($profile) {
             if ($this->request->hasPost('permissions')) {
                 //Deletes the current permissions
                 $profile->getPermissions()->delete();
                 //Save the new permissions
                 foreach ($this->request->getPost('permissions') as $permission) {
                     $parts = explode('.', $permission);
                     $permission = new Permissions();
                     $permission->profilesId = $profile->id;
                     $permission->resource = $parts[0];
                     $permission->action = $parts[1];
                     $permission->save();
                 }
                 $this->flash->success(_('Permissions were updated with success'));
             }
             //Rebuild the ACL with
             $this->acl->rebuild();
             //Pass the current permissions to the view
             $this->view->permissions = $this->acl->getPermissions($profile);
         }
         $this->view->profile = $profile;
     }
     //Pass all the active profiles
     $this->view->profiles = Profiles::find('active = "Y"');
 }
Exemplo n.º 2
0
 public function initialize($entity = null, $options = null)
 {
     //In edition the id is hidden
     if (isset($options['edit']) && $options['edit']) {
         $id = new Hidden('id');
     } else {
         $id = new Text('id');
     }
     $this->add($id);
     $this->add(new Text('username'));
     $this->add(new Text('fullName'));
     $this->add(new Text('email'));
     $this->add(new Select('profilesId', Profiles::find('active = "Y"'), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => '')));
     $this->add(new Select('banned', array('Y' => 'Yes', 'N' => 'No')));
     $this->add(new Select('suspended', array('Y' => 'Yes', 'N' => 'No')));
     $this->add(new Select('active', array('Y' => 'Yes', 'N' => 'No')));
 }
Exemplo n.º 3
0
Arquivo: Acl.php Projeto: kjmtrue/blog
 /**
  * Rebuils the access list into a file
  *
  */
 public function rebuild()
 {
     $acl = new AclMemory();
     $acl->setDefaultAction(\Phalcon\Acl::DENY);
     //Register roles
     $profiles = Profiles::find('active = "Y"');
     foreach ($profiles as $profile) {
         $acl->addRole(new AclRole($profile->name));
     }
     foreach ($this->_privateResources as $resource => $actions) {
         $acl->addResource(new AclResource($resource), $actions);
     }
     //Grant acess to private area to role Users
     foreach ($profiles as $profile) {
         //Grant permissions in "permissions" model
         foreach ($profile->getPermissions() as $permission) {
             $acl->allow($profile->name, $permission->resource, $permission->action);
         }
         //Always grant these permissions
         $acl->allow($profile->name, 'users', 'changePassword');
     }
     return $acl;
 }
Exemplo n.º 4
0
 /**
  * Deletes a Profile
  *
  * @param int $id
  */
 public function deleteAction($id)
 {
     $profile = Profiles::findFirstById($id);
     if (!$profile) {
         $this->flash->error("Profile was not found");
         return $this->dispatcher->forward(array('action' => 'index'));
     }
     if (!$profile->delete()) {
         $this->flash->error($profile->getMessages());
     } else {
         $this->flash->success("Profile was deleted");
     }
     return $this->dispatcher->forward(array('action' => 'index'));
 }