Example #1
0
 public function addSessionScripts()
 {
     $response = $this->pageStack->getPageResponse();
     $session = array();
     $session['userId'] = null;
     $session['lang'] = 'en';
     if ($this->pageStack->getSession() && $this->pageStack->getSession()->has('admin_language')) {
         $session['lang'] = $this->pageStack->getSession()->get('admin_language');
     }
     $session['access'] = $this->acl->check(ACLRequest::create('jarves/entryPoint', ['path' => '/admin']));
     if ($this->pageStack->isLoggedIn()) {
         $user = $this->pageStack->getUser();
         $session['userId'] = $user->getId();
         $session['username'] = $user->getUsername();
         $session['lastLogin'] = $user->getLastLogin();
         $session['firstName'] = $user->getFirstName();
         $session['lastName'] = $user->getLastName();
         //            $email = $user->getEmail();
         //            $session['emailMd5'] = $email ? md5(strtolower(trim($email))) : null;
         $session['imagePath'] = $user->getImagePath();
     }
     $session['token'] = get_class($this->pageStack->getToken());
     $css = 'window._session = ' . json_encode($session) . ';';
     $response->addJs($css);
 }
Example #2
0
 /**
  * @param int|null $nodeId
  *
  * @return bool
  */
 public function isEditMode($nodeId = null)
 {
     $request = $this->requestStack->getMasterRequest();
     $hasRequest = !!$request;
     if ($nodeId) {
         return $hasRequest && 1 === (int) $request->get('_jarves_editor') && $this->acl->isUpdatable('jarves/node', ['id' => $nodeId]);
     }
     return $hasRequest && 1 === (int) $request->get('_jarves_editor') && $this->pageStack->getCurrentPage() && $this->acl->isUpdatable('jarves/node', ['id' => $this->pageStack->getCurrentPage()->getId()]);
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null)
 {
     if ($pk) {
         $path = $this->getPathFromPK($pk);
     } else {
         $path = '/';
     }
     if ($depth === null) {
         $depth = 1;
     }
     try {
         $files = $this->webFilesystem->getFiles($path);
     } catch (NotADirectoryException $e) {
         return null;
     }
     $c = 0;
     //        $offset = $options['offset'];
     //        $limit = $options['limit'];
     $result = array();
     $blacklistedFiles = array();
     $showHiddenFiles = false;
     //todo
     foreach ($files as $file) {
         $file = $file->toArray();
         if (isset($blacklistedFiles[$file['path']]) | (!$showHiddenFiles && substr($file['name'], 0, 1) == '.')) {
             continue;
         }
         if ($condition && $condition->hasRules() && !$condition->satisfy($file, 'jarves/file')) {
             continue;
         }
         $file['writeAccess'] = $this->acl->isUpdatable('jarves/file', array('path' => $file['path']));
         $c++;
         //            if ($offset && $offset >= $c) {
         //                continue;
         //            }
         //            if ($limit && $limit < $c) {
         //                break;
         //            }
         if ($depth > 0) {
             $children = array();
             if ($file['type'] == 'dir') {
                 try {
                     $children = self::getBranch(array('path' => $file['path']), $condition, $depth - 1);
                 } catch (FileNotFoundException $e) {
                     $children = null;
                 }
             }
             $file['_childrenCount'] = count($children);
             if ($depth > 1 && $file['type'] == 'dir') {
                 $file['_children'] = $children;
             }
         }
         $result[] = $file;
     }
     return $result;
 }
Example #4
0
 /**
  * Returns file information as array.
  *
  * @param string|integer $path
  * @return array|null
  */
 protected function getFile($path)
 {
     $file = $this->webFilesystem->getFile($path);
     $file = $file->toArray();
     $aclRequest = ACLRequest::create('jarves/file', $file)->onlyListingMode();
     if (!$file || !$this->acl->check($aclRequest)) {
         return null;
     }
     $file['writeAccess'] = $this->acl->check($aclRequest->onlyUpdateMode());
     $this->appendImageInformation($file);
     return $file;
 }
Example #5
0
 /**
  * @ApiDoc(
  *  section="Backend",
  *  description="Returns all available menu/entryPoint items for the main navigation bar in the administration"
  * )
  *
  * @Rest\View()
  * @Rest\Get("/admin/backend/menus")
  *
  * @return array
  */
 public function getMenusAction()
 {
     $entryPoints = array();
     foreach ($this->jarves->getConfigs() as $bundleName => $bundleConfig) {
         foreach ($bundleConfig->getAllEntryPoints() as $subEntryPoint) {
             $path = $subEntryPoint->getFullPath();
             if (substr_count($path, '/') <= 3) {
                 if ($subEntryPoint->isLink()) {
                     if ($this->acl->check(ACLRequest::create('jarves/entryPoint', ['path' => '/' . $path]))) {
                         $entryPoints[$path] = array('label' => $subEntryPoint->getLabel(), 'icon' => $subEntryPoint->getIcon(), 'fullPath' => $path, 'path' => $subEntryPoint->getPath(), 'type' => $subEntryPoint->getType(), 'system' => $subEntryPoint->getSystem(), 'templateUrl' => $subEntryPoint->getTemplateUrl(), 'level' => substr_count($path, '/'));
                     }
                 }
             }
         }
     }
     return $entryPoints;
 }
Example #6
0
 /**
  * @ApiDoc(
  *  section="Administration",
  *  description="Logs in a user to the current session"
  * )
  *
  * Result on success:
  * {
  *    token: "c7405b2be7da96b0db784f2dc8b2b974",
  *    userId: 1,
  *    username: "******",
  *    access: true, #administration access
  *    firstName: "Admini",
  *    lastName: "strator",
  *    emailMd5: <emailAsMd5>, //for gravatar
  *    imagePath: "/path/to/image.jpg"
  *}
  *
  * @Rest\RequestParam(name="username", requirements=".+", strict=true)
  * @Rest\RequestParam(name="password", requirements=".+", strict=true)
  *
  * @Rest\Post("/admin/login")
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return array|bool Returns false on failure or a array if successful.
  */
 public function loginUserAction(ParamFetcher $paramFetcher, Request $request)
 {
     $username = $paramFetcher->get('username');
     $password = $paramFetcher->get('password');
     $user = $this->userProvider->loadUserByUsername($username);
     if (!$user) {
         $this->logger->warning(sprintf('Login failed for "%s". User not found', $username));
         sleep(1);
         return false;
     }
     $encoder = $this->encoderFactory->getEncoder($user);
     if (!$encoder->isPasswordValid($user->getPassword(), $password, null)) {
         $this->logger->warning(sprintf('Login failed for "%s". Password missmatch ', $username));
         sleep(1);
         return false;
     }
     $token = new UsernamePasswordToken($user, null, "main", $user->getGroupRoles());
     $this->tokenStorage->setToken($token);
     //now dispatch the login event
     $event = new InteractiveLoginEvent($request, $token);
     $this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
     return array('userId' => $user->getId(), 'username' => $user->getUsername(), 'lastLogin' => $user->getLastLogin(), 'access' => $this->acl->check(ACLRequest::create('jarves/entryPoint', ['path' => '/admin'])), 'firstName' => $user->getFirstName(), 'lastName' => $user->getLastName(), 'imagePath' => $user->getImagePath());
 }
Example #7
0
 /**
  * Generates a row from the propel object using the get*() methods. Resolves *-to-many relations.
  *
  * @param      $clazz
  * @param      $row
  * @param      $selects
  * @param      $relations
  * @param      $relationFields
  * @param bool $permissionCheck
  *
  * @return array
  */
 public function populateRow($clazz, $row, $selects, $relations, $relationFields, $permissionCheck = false)
 {
     $item = new $clazz();
     $item->fromArray($row);
     $newRow = [];
     foreach ($selects as $select) {
         if (strpos($select, '.') === false) {
             $newRow[lcfirst($select)] = $item->{'get' . $select}();
         }
     }
     if (!$relations) {
         return $newRow;
     }
     foreach ($relations as $name => $relation) {
         /** @var $relation \Propel\Runtime\Map\RelationMap */
         if ($relation->getType() != RelationMap::MANY_TO_MANY && $relation->getType() != RelationMap::ONE_TO_MANY) {
             if (isset($relationFields[$name]) && is_array($relationFields[$name])) {
                 $foreignClazz = $relation->getForeignTable()->getClassName();
                 $foreignObj = new $foreignClazz();
                 $foreignRow = array();
                 $allNull = true;
                 foreach ($relationFields[$name] as $col) {
                     if ($row[$name . "." . $col] !== null) {
                         $foreignRow[$col] = $row[$name . "." . $col];
                         $allNull = false;
                     }
                 }
                 if ($allNull) {
                     $newRow[lcfirst($name)] = null;
                 } else {
                     $foreignObj->fromArray($foreignRow);
                     $foreignRow = array();
                     foreach ($relationFields[$name] as $col) {
                         $foreignRow[lcfirst($col)] = $foreignObj->{'get' . $col}();
                     }
                     $newRow[lcfirst($name)] = $foreignRow;
                 }
             }
         } else {
             //many-to-one and many-to-many, we need a extra query
             if (is_array($relationFields[$name]) && ($relationField = $this->getDefinition()->getField($name))) {
                 if (!($relationObjectName = $relationField->getObject())) {
                     $relationObjectName = $this->getDefinition()->getKey();
                     //                            if (!$relationField->getObjectDefinition() || !$relationObjectName = $relationField->getObjectDefinition()->getKey()) {
                     //                                throw new ObjectNotFoundException(sprintf('No object defined for relation `%s`.', $relationField->getId()));
                     //                            }
                 }
                 $sClazz = $relation->getRightTable()->getClassname();
                 $queryName = $sClazz . 'Query';
                 if ($relation->getType() === RelationMap::MANY_TO_MANY) {
                     $filterBy = 'filterBy' . $this->getDefinition()->getId();
                 } else {
                     $filterBy = 'filterBy' . $relation->getSymmetricalRelation()->getName();
                 }
                 $sQuery = $queryName::create()->select($relationFields[$name])->{$filterBy}($item);
                 $condition = null;
                 if ($permissionCheck) {
                     $condition = $this->acl->getListingCondition($relationObjectName);
                 }
                 $sStmt = $this->getStm($sQuery, $condition);
                 $sItems = array();
                 while ($subRow = $sStmt->fetch(\PDO::FETCH_ASSOC)) {
                     $sItem = new $sClazz();
                     $sItem->fromArray($subRow);
                     $temp = array();
                     foreach ($relationFields[$name] as $select) {
                         $temp[lcfirst($select)] = $sItem->{'get' . $select}();
                     }
                     $sItems[] = $temp;
                 }
             } else {
                 $get = 'get' . $relation->getPluralName();
                 $sItems = $item->{$get}();
             }
             if ($sItems instanceof ObjectCollection) {
                 $newRow[lcfirst($name)] = $sItems->toArray(null, null, TableMap::TYPE_CAMELNAME) ?: null;
             } else {
                 if (is_array($sItems) && $sItems) {
                     $newRow[lcfirst($name)] = $sItems;
                 } else {
                     $newRow[lcfirst($name)] = null;
                 }
             }
         }
     }
     return $newRow;
 }
Example #8
0
 /**
  * Each item goes through this function in getItems(). Defines whether a item is editable or deleteable.
  * You can attach here extra action icons, too.
  *
  * Result should be:
  *
  * $item['_editable'] = true|false
  * $item['_deleteable'] = true|false
  * $item['_actions'] = array(
  *         array('/* action * /') //todo
  *     )
  * )
  *
  * @param array $item
  *
  * @return array
  */
 public function prepareRow(&$item)
 {
     $item['_editable'] = $this->acl->isUpdatable($this->getObject(), $item);
     $item['_deletable'] = $this->acl->isDeletable($this->getObject(), $item);
 }