Ejemplo n.º 1
0
 public function isAllowed($module, $permissionLevel, $element = null, $entity = null)
 {
     if ($this->user->getRole() == "admin") {
         return true;
     }
     if (!isset($this->roles[$this->user->getRole()])) {
         return false;
     }
     $role = $this->roles[$this->user->getRole()];
     $allowed = false;
     if (!isset($role['modules'][$module])) {
         return false;
     }
     if ($role['modules'][$module]['global'] >= $permissionLevel) {
         $allowed = true;
     }
     if ($element && isset($role['modules'][$module]['elements'][$element])) {
         if ($role['modules'][$module]['elements'][$element] > $role['modules'][$module]['global']) {
             throw new \Exception("You cannot set element permission bigger than global permission.");
         } else {
             if ($role['modules'][$module]['elements'][$element] >= $permissionLevel) {
                 $allowed = true;
             } else {
                 $allowed = false;
             }
         }
     }
     return $allowed;
 }
Ejemplo n.º 2
0
 /**
  * @param \MfccAdminModule\Form\Element\File $element
  * @param \MfccAdminModule\Entity\User|null $user
  * @param array $option
  * @return File
  */
 public function upload($element, \MfccAdminModule\Entity\User $user = null, array $option = [])
 {
     $_file = $element->getValue();
     if ($_file['error'] != 0) {
         return null;
     }
     $fileName = $_file['name'];
     $mimetype = $_file['type'];
     $hash = md5(microtime(true) . $fileName);
     $savePath = substr($hash, 0, 1) . '/' . substr($hash, 1, 1) . '/';
     $file = new File();
     if ($user) {
         $file->setInsertedBy($user->getId());
     }
     if (isset($option['fileName'])) {
         $file->setName($option['fileName']);
     } else {
         $file->setName($fileName);
     }
     $file->setMimetype($mimetype);
     $file->setSize($_file['size']);
     $file->setActive($this->params['default_is_active']);
     $file->setSavePath($savePath . $hash);
     if (isset($option['keywords'])) {
         $this->addKeywordsToFile($option['keywords']);
     }
     try {
         $this->getFilesystem()->writeStream($savePath . $hash, fopen($_file['tmp_name'], 'r+'));
         $element->setFileObject($file);
         $this->getEntityManager()->persist($file);
     } catch (\Exception $e) {
         throw new Exception\RuntimeException('File cannot be saved.', 0, $e);
     }
     return $file;
 }
Ejemplo n.º 3
0
 /**
  * @param UserEntity $entity
  * @param array $data
  * @return UserEntity
  */
 protected function populateData(UserEntity $entity, array $data)
 {
     if ($data['name']) {
         $entity->setName($data['name']);
     }
     if ($data['email']) {
         $entity->setEmail($data['email']);
     }
     if ($data['active']) {
         $entity->setActive($data['active']);
     }
     if ($data['roleId']) {
         $role = $this->getAccessControl()->getRoleMapper()->findById($data['roleId']);
         $entity->setRole($role);
     }
     return $entity;
 }
Ejemplo n.º 4
0
 /**
  * @param UserEntity $userObject
  * @param $password
  * @param Bcrypt $bcrypt
  * @return $this|bool
  */
 protected function updateUserPasswordHash(UserEntity $userObject, $password, Bcrypt $bcrypt)
 {
     $hash = explode('$', $userObject->getPassword());
     if ($hash[2] === $bcrypt->getCost()) {
         return true;
     }
     $userObject->setPassword($bcrypt->create($password));
     $this->getUserMapper()->update($userObject);
     return $this;
 }