Returns the current session. if available.
public getSession ( ) : null | Symfony\Component\HttpFoundation\Session\SessionInterface | ||
return | null | Symfony\Component\HttpFoundation\Session\SessionInterface |
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); }
/** * @ApiDoc( * section="File Manager", * description="Uploads a file to $path with $name as name" * ) * * @Rest\RequestParam(name="path", requirements=".+", strict=true, description="The target path") * @Rest\RequestParam(name="name", requirements=".*", strict=false, description="The file name if you want a different") * @ #Rest\RequestParam(name="overwrite", requirements=".*", default="false", description="If the target should be overwritten") * @Rest\RequestParam(name="file", strict=false, description="The file") * * @Rest\Post("/admin/file/upload") * * @param Request $request * @param ParamFetcher $paramFetcher * * @return string * @throws FileUploadException * @throws InvalidArgumentException * @throws AccessDeniedException */ public function doUploadAction(Request $request, ParamFetcher $paramFetcher) { $path = $paramFetcher->get('path'); $overwriteName = $paramFetcher->get('name'); // $overwrite = filter_var($paramFetcher->get('overwrite'), FILTER_VALIDATE_BOOLEAN); /** @var $file UploadedFile */ $file = $request->files->get('file'); if (null == $file) { throw new InvalidArgumentException("There is no file uploaded."); } $name = $file->getClientOriginalName(); if ($overwriteName) { $name = $overwriteName; } if ($file->getError()) { $error = sprintf('Failed to upload the file %s to %s. Error: %s', $name, $path, $file->getErrorMessage()); throw new FileUploadException($error); } $newPath = $path == '/' ? '/' . $name : $path . '/' . $name; if ($this->webFilesystem->has($newPath)) { // if (!$overwrite) { if ($this->webFilesystem->has($newPath)) { $content = $this->webFilesystem->read($newPath); $check = "file-is-being-uploaded-by-" . hash('sha512', $this->pageStack->getSession()->getId()); if ($content != $check) { //not our file, so cancel throw new FileUploadException(sprintf('The target file is currently being uploaded by someone else.')); } } else { throw new FileUploadException(sprintf('The target file has not be initialized.')); } // } } $fileToAdd = ['path' => $path]; $aclRequest = ACLRequest::create('jarves/file')->setPrimaryObjectItem($fileToAdd)->onlyUpdateMode(); if (!$this->acl->check($aclRequest)) { throw new AccessDeniedException(sprintf('No access to file `%s`', $path)); } $content = file_get_contents($file->getPathname()); $result = $this->webFilesystem->write($newPath, $content); @unlink($file->getPathname()); if ($result) { $this->newFeed($newPath, 'uploaded', 'to ' . $newPath); } return $newPath; }
/** * @ApiDoc( * section="Interface i18n", * description="Prints all language messages" * ) * * @Rest\QueryParam(name="lang", requirements="[a-z]{2,3}", strict=true, description="The language code") * @Rest\QueryParam(name="javascript", requirements=".+", default=false, description="If it should be printed as javascript") * * @Rest\Get("/admin/ui/language") * * @param ParamFetcher $paramFetcher * * @return array|string depends on javascript param */ public function getLanguageAction(ParamFetcher $paramFetcher) { $lang = $paramFetcher->get('lang'); $javascript = $paramFetcher->get('javascript'); if (!$this->translator->isValidLanguage($lang)) { $lang = 'en'; } $this->pageStack->getSession()->set('admin_language', $lang); $messages = $this->translator->loadMessages($lang); if ($javascript) { $response = new Response(); $response->headers->set('Content-Type', 'text/javascript'); $content = "if( typeof(jarves)=='undefined') window.jarves = {}; jarves.lang = " . json_encode($messages, JSON_PRETTY_PRINT); $content .= "\nLocale.define('en-US', 'Date', " . $this->templating->render('JarvesBundle:Default:javascript-locales.js.twig') . ");"; $response->setContent($content); return $response; } else { $messages['mootools'] = $this->templating->render('JarvesBundle:Default:javascript-locales.js.twig'); return $messages; } }