/** * View the permissions for a profile level, and change them if we have a POST. */ 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"'); }
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('name')); $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'))); }
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); $name = new Text('name', array('placeholder' => 'Name')); $name->addValidators(array(new PresenceOf(array('message' => 'The name is required')))); $this->add($name); $email = new Text('email', array('placeholder' => 'Email')); $email->addValidators(array(new PresenceOf(array('message' => 'The e-mail is required')), new Email(array('message' => 'The e-mail is not valid')))); $this->add($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'))); }
/** * Searches for profiles */ public function searchAction() { $numberPage = 1; if ($this->request->isPost()) { $query = Criteria::fromInput($this->di, 'Vokuro\\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(); }
/** * Rebuilds the access list into a file * * @return \Phalcon\Acl\Adapter\Memory */ 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'); } if (touch(APP_DIR . $this->filePath) && is_writable(APP_DIR . $this->filePath)) { file_put_contents(APP_DIR . $this->filePath, serialize($acl)); // Store the ACL in APC if (function_exists('apc_store')) { apc_store('vokuro-acl', $acl); } } else { $this->flash->error('The user does not have write permissions to create the ACL list at ' . APP_DIR . $this->filePath); } return $acl; }