Пример #1
0
 /**
  * Form configuration
  */
 public function initialize($entity = null, $options = null)
 {
     $t = $this->getDI()->get('translate');
     // In edition the id is hidden
     if (isset($options['edit']) && $options['edit']) {
         $id = new Hidden('id');
     } else {
         $id = new Text('id');
     }
     $id->setLabel($t->gettext('Id'));
     $this->add($id);
     // Name field
     $name = new Text('name', ['placeholder' => $t->gettext('Name')]);
     $name->setLabel($t->gettext('Name'));
     $name->addValidators([new PresenceOf(['message' => $t->gettext('Name is required')])]);
     $this->add($name);
     // Email field
     $email = new Text('email', ['placeholder' => $t->gettext('Email')]);
     $email->setLabel($t->gettext('Email'));
     $email->addValidators([new PresenceOf(['message' => $t->gettext('Email is required')]), new Email(['message' => $t->gettext('Email is not valid')])]);
     $this->add($email);
     // rolesId field
     $roles = Roles::find(['active = :active:', 'bind' => ['active' => 'Y']]);
     $role = new Select('rolesId', $roles, ['using' => ['id', 'name'], 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => '']);
     $role->setLabel($t->gettext('Role'));
     $role->addValidators([new PresenceOf(['message' => $t->gettext('The user role must be set.')])]);
     $this->add($role);
     // active field
     $active = new Select('active', ['N' => $t->gettext('No'), 'Y' => $t->gettext('Yes')]);
     $active->setLabel($t->gettext('Active'));
     $this->add($active);
     // banned field
     $banned = new Select('banned', ['Y' => $t->gettext('Yes'), 'N' => $t->gettext('No')]);
     $banned->setLabel($t->gettext('Banned'));
     $this->add($banned);
     // emailActivationMsg field
     $emailExtraMsg = new Textarea('emailActivationMsg', ['placeholder' => $t->gettext('Add text to send confirmation email.')]);
     $emailExtraMsg->setLabel($t->gettext('Send activation email'));
     $this->add($emailExtraMsg);
     // Submit
     $submit = new Submit('submit', ['value' => $t->gettext('Save')]);
     $this->add($submit);
 }
Пример #2
0
 /**
  * Searches for roles
  */
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Criteria::fromInput($this->di, 'Webird\\Models\\Roles', $this->request->getPost());
         $this->persistent->searchParams = $query->getParams();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
     }
     $parameters = [];
     if ($this->persistent->searchParams) {
         $parameters = $this->persistent->searchParams;
     }
     $roles = Roles::find($parameters);
     if (count($roles) == 0) {
         $this->flash->notice($this->translate->gettext('The search did not find any roles'));
         return $this->dispatcher->forward(["action" => "index"]);
     }
     $paginator = new Paginator(["data" => $roles, "limit" => 10, "page" => $numberPage]);
     $this->view->page = $paginator->getPaginate();
 }
Пример #3
0
 /**
  * View the permissions for a role level, and change them if we have a POST.
  */
 public function indexAction()
 {
     if ($this->request->isPost()) {
         // Validate the role
         $role = Roles::findFirstById($this->request->getPost('roleId'));
         if ($role) {
             if ($this->request->hasPost('save') && $this->request->hasPost('permissions')) {
                 // Deletes the current permissions
                 $role->getPermissions()->delete();
                 $savedMessages = [];
                 // Save the new permissions
                 foreach ($this->request->getPost('permissions') as $permission) {
                     // This may become out of sync with the permission model validators but
                     // its user input so rather be a bit more careful.
                     if (preg_match('/^([a-z]*):([a-zA-Z]+).([a-zA-Z]+)$/', $permission, $matches) !== 1) {
                         throw new \Exception('Error: The fully qualified permission is not valid');
                     }
                     $permission = new Permissions();
                     $permission->rolesId = $role->id;
                     $permission->namespace = $matches[1];
                     $permission->resource = $matches[2];
                     $permission->action = $matches[3];
                     if (!$permission->save()) {
                         $savedMessages[] = $permission->getMessages()[0];
                     }
                 }
                 if (empty($savedMessages)) {
                     $this->flash->success($this->translate->gettext('Permissions were updated with success'));
                 }
             }
             $this->view->acl = $this->acl;
             // // Pass the current permissions to the view
             $this->view->permissions = $this->acl->getPermissions($role);
         }
         $this->view->role = $role;
     }
     // Pass all the active roles
     $this->view->roles = Roles::find(['active = :active:', 'bind' => ['active' => 'Y']]);
 }
Пример #4
0
 private function build()
 {
     $acl = new AclMemory();
     $acl->setDefaultAction(\Phalcon\Acl::DENY);
     foreach ($this->specComplete as $namespace => $resources) {
         foreach ($resources as $resource => $actions) {
             $nsRes = $namespace == '' ? $resource : $namespace . ':' . $resource;
             $acl->addResource(new AclResource($this->mergeResource($namespace, $resource)), $actions);
         }
     }
     // Register roles
     $roles = Roles::find(['active = :active:', 'bind' => ['active' => 'Y']]);
     foreach ($roles as $role) {
         $acl->addRole(new AclRole($role->name));
     }
     // Grant access to private area
     foreach ($roles as $role) {
         foreach ($this->specPublic as $namespace => $resources) {
             foreach ($resources as $resource => $actions) {
                 $acl->allow($role->name, $this->mergeResource($namespace, $resource), $actions);
             }
         }
         // Grant permissions in "permissions" model
         foreach ($role->getPermissions() as $permission) {
             $acl->allow($role->name, $permission->getNamespaceResource(), $permission->action);
         }
     }
     return $acl;
 }