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
 /**
  * Searches for profiles
  */
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Criteria::fromInput($this->di, 'Phalconvn\\Models\\Profiles', $this->request->getPost());
         $this->persistent->searchParams = $query->getParams();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
     }
     $parameters = array();
     if ($this->persistent->searchParams) {
         $parameters = $this->persistent->searchParams;
     }
     $profiles = Profiles::find($parameters);
     if (count($profiles) == 0) {
         $this->flash->notice("The search did not find any profiles");
         return $this->dispatcher->forward(array("action" => "index"));
     }
     $paginator = new Paginator(array("data" => $profiles, "limit" => 10, "page" => $numberPage));
     $this->view->page = $paginator->getPaginate();
 }
Exemplo n.º 4
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;
 }