Пример #1
0
 public function save()
 {
     $superuser = $this->request->input('superuser');
     $this->editPerson->setName($this->request->input('name'))->setEnabled($this->request->input('enabled') == 1);
     if ($superuser !== null && Auth::getPerson()->isSuperuser() && Auth::getPerson()->getId() != $this->editPerson->getId()) {
         $this->editPerson->setSuperuser($superuser == 1);
     }
     Person::save($this->editPerson);
 }
Пример #2
0
 /**
  * Checks whether the current user is authorized to perform a particular action.
  *
  * @param string $role
  * @param Page   $page
  */
 public function authorization($role, Page $page = null)
 {
     if (!Auth::isLoggedIn()) {
         abort(401);
     }
     if (!Auth::loggedIn($role, $page)) {
         abort(403);
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     View::share('auth', Auth::getFacadeRoot());
     View::share('request', $request);
     View::share('editor', Editor::getFacadeRoot());
     $viewHelpers = Config::get('boomcms.viewHelpers');
     foreach ($viewHelpers as $key => $value) {
         View::share($key, $value);
     }
     return $next($request);
 }
Пример #4
0
 public function addVersion(array $attrs = [])
 {
     if ($currentVersion = $this->getCurrentVersion()) {
         $attrs = array_merge($currentVersion->toArray(), $attrs);
     }
     $attrs = array_merge($attrs, ['page_id' => $this->getId(), 'edited_by' => Auth::getPerson()->getId(), 'edited_time' => time()]);
     // If the embargo time of the new version is in the past, set the embargo time to null
     // This means that if the old version was published, the new version will be a draft.
     // If the embargo time is in the future don't change it.
     if (!isset($attrs['embargoed_until']) || $attrs['embargoed_until'] < time()) {
         $attrs['embargoed_until'] = null;
     }
     $this->currentVersion = PageVersion::create($attrs);
     return $this->currentVersion;
 }
Пример #5
0
 public static function items()
 {
     $items = Config::get('boomcms.menu');
     foreach ($items as $key => $item) {
         if (isset($item['role']) && !Auth::loggedIn($item['role'])) {
             unset($items[$key]);
             continue;
         }
         $items[$key]['title'] = isset($item['title']) ? $item['title'] : Lang::get('boomcms::menu.' . $key);
     }
     usort($items, function ($a, $b) {
         if ($a['title'] === $b['title']) {
             return 0;
         }
         return $a['title'] < $b['title'] ? -1 : 1;
     });
     return $items;
 }
Пример #6
0
 /**
  * @return void
  */
 public function handle()
 {
     $password = (string) new RandomPassword();
     $this->credentials['password'] = Auth::hash($password);
     try {
         $person = Person::create($this->credentials);
     } catch (DuplicateEmailException $e) {
     }
     if (isset($person)) {
         foreach ($this->groups as $groupId) {
             $person->addGroup(Group::find($groupId));
         }
         Event::fire(new AccountCreated($person, $password, Auth::getPerson()));
         return $person;
     } else {
         return Person::findByEmail($this->credentials['email']);
     }
 }
Пример #7
0
 public function revert(AssetInterface $asset, $versionId)
 {
     $version = $this->version->find($versionId);
     if ($version && $version->getAssetId() == $asset->getId()) {
         $attrs = $version->toArray();
         unset($attrs['id']);
         $attrs['edited_at'] = time();
         $attrs['edited_by'] = Auth::getPerson()->getId();
         $version = $this->version->create($attrs);
         copy($asset->directory() . DIRECTORY_SEPARATOR . $versionId, $asset->directory() . DIRECTORY_SEPARATOR . $version->getId());
     }
     return $asset;
 }
Пример #8
0
 public function __construct(Request $request)
 {
     $this->request = $request;
     $this->page = $this->request->route()->getParameter('page');
     $this->page->wasCreatedBy(Auth::getPerson()) || parent::authorization('edit_page_content', $this->page);
 }
Пример #9
0
 public function authorization($role, Page $page = null)
 {
     if (!Auth::loggedIn('manage_pages')) {
         parent::authorization($role, $page);
     }
 }
Пример #10
0
 public function visibility()
 {
     parent::visibility();
     $wasVisible = $this->page->isVisible();
     $this->page->setVisibleAtAnyTime($this->request->input('visible') == 1);
     if ($this->page->isVisibleAtAnyTime()) {
         $visibleTo = $this->request->input('toggle_visible_to') == 1 ? new DateTime($this->request->input('visible_to')) : null;
         $this->page->setVisibleFrom(new DateTime($this->request->input('visible_from')))->setVisibleTo($visibleTo);
     }
     Page::save($this->page);
     if (!$wasVisible && $this->page->isVisible()) {
         Event::fire(new PageWasMadeVisible($this->page, Auth::getPerson()));
     }
     return (int) $this->page->isVisible();
 }
Пример #11
0
 public function upload()
 {
     $assetIds = [];
     list($validFiles, $errors) = $this->validateFileUpload();
     foreach ($validFiles as $file) {
         $asset = new Asset();
         $asset->setUploadedTime(new DateTime('now'))->setUploadedBy(Auth::getPerson())->setTitle($file->getClientOriginalName())->setType(AssetHelper::typeFromMimetype($file->getMimeType()));
         $assetIds[] = AssetFacade::save($asset)->getId();
         AssetFacade::createVersionFromFile($asset, $file);
     }
     return count($errors) ? new JsonResponse($errors, 500) : $assetIds;
 }