function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $settings = $this->kernelSettings;
     $session = $this->session;
     $this->redirection->setRequest($request);
     // Start the sessions engine.
     session_name($settings->name);
     $name = session_name();
     session_start();
     // Load the saved session (if any).
     /** @var AssignableInterface $savedSession */
     if (($savedSession = get($_SESSION, '#data')) && $savedSession instanceof AssignableInterface) {
         $this->session->import($savedSession->export());
     }
     // (Re)initialize some session settings.
     $session->name = $name;
     // Setup current session to be saved on shutdown.
     $_SESSION['#data'] = $session;
     $flashMessage = $session->getFlashMessage();
     if ($flashMessage) {
         $this->renderFlashMessage($flashMessage['type'], $flashMessage['message']);
     }
     // Run the next middleware, catching any flash message exceptions.
     try {
         return $next($request);
     } catch (FlashMessageException $flash) {
         $session->flashMessage($flash->getMessage(), $flash->getCode(), $flash->getTitle());
         $post = $request->getParsedBody();
         if (is_array($post)) {
             $session->flashInput($post);
         }
         return $this->redirection->refresh();
     }
 }
 protected function initialize()
 {
     $user = $this->session->user();
     if (!$user) {
         throw new HttpException(403, 'Access denied.', "No user is logged-in.<p><br>Did you forget to setup an authentication middleware?");
     }
     parent::initialize();
 }
 function defineNavigation(NavigationInterface $nav)
 {
     $userMenu = ['users-management' => $nav->group()->id('userMenu')->icon('fa ion-person')->title('$APP_USER_MENU')->links(['profile' => $nav->link()->id('profile')->title('$LOGIN_PROFILE')->icon('fa ion-person')->visible($this->settings->enableProfile()), 'users' => $nav->link()->id('users')->title('$APP_SETTINGS_USERS')->icon('fa ion-person-stalker')->visible(function () {
         $user = $this->session->user();
         if (!$user) {
             return false;
         }
         return $this->settings->enableUsersManagement() && $user->roleField() >= UserInterface::USER_ROLE_ADMIN;
     })->links(['@id' => $nav->link()->id('userForm')->title('$APP_SETTINGS_USER')->visibleIfUnavailable(Y)]), '-' => $nav->divider(), '' => $nav->link()->url($this->authenticationSettings->getLogoutUrl())->title('$LOGOUT')->icon('fa ion-log-out')])];
     $nav->add([$nav->group()->id('app_home')->title('$APP_HOME')->icon('fa fa-home')->url($this->settings->urlPrefix())->links(['' => $nav->group()->id('mainMenu')->icon('fa ion-navicon')->title('Main Menu')->links(['' => $nav->link()->id('home')->icon('fa ion-home')->title('Home')]), 'settings' => $nav->group()->id('settings')->icon('fa ion-gear-a')->title('Platform')->links($userMenu)])]);
 }
Beispiel #4
0
 protected function viewModel(ViewModel $viewModel)
 {
     $settings = $viewModel->adminSettings = $this->adminSettings;
     if ($settings->showMenu()) {
         $target = $settings->topMenuTarget();
         $viewModel->topMenu = exists($target) ? isset($this->navigation[$target]) ? $this->navigation[$target] : null : $this->navigation;
     }
     $viewModel->sideMenu = get($this->navigation->getCurrentTrail($settings->sideMenuOffset()), 0);
     $user = $this->session->user();
     $viewModel->devMode = $user && $user->roleField() == UserInterface::USER_ROLE_DEVELOPER;
 }
 function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $mode = $this->settings->selectionMode();
     $this->locale->selectionMode($mode);
     if ($mode == 'session') {
         $lang = $this->session->getLang() ?: $this->locale->defaultLang();
         $this->locale->locale($lang);
         $this->session->setLang($lang);
     }
     if ($this->webConsole) {
         DebugConsole::logger('config')->inspect($this->locale);
     }
     return $next();
 }
 function handleRequest()
 {
     $request = $this->request;
     // Merge route parameters.
     $rp = Http::getRouteParameters($request);
     if ($rp) {
         $o = [];
         setAt($o, $this->mainSubModelPath, $rp);
         $this->merge($o);
     }
     switch ($request->getMethod()) {
         case 'GET':
             $old = $this->session->getOldInput();
             if ($old) {
                 $this->merge($this->parseFormData($old));
             }
             break;
         case 'POST':
             $data = $request->getParsedBody();
             if (isset($data)) {
                 $contentType = $request->getHeaderLine('Content-Type');
                 if ($contentType == 'application/x-www-form-urlencoded' || str_beginsWith($contentType, 'multipart/form-data')) {
                     $data = $this->parseFormData($data);
                 }
                 unset($data[PlatformModule::ACTION_FIELD]);
                 $this->merge($data);
             }
     }
     $this->runExtensions();
 }
 public function model()
 {
     $myRole = $this->session->user()->roleField();
     if ($myRole < UserInterface::USER_ROLE_ADMIN) {
         // Can't view other users.
         throw new HttpException(403);
     }
     $class = $this->userModel;
     $users = $class::orderBy('username')->get();
     //TODO: order by custom username column
     $users = filter($users, function (UserInterface $user) use($myRole) {
         return $user->roleField() <= $myRole;
     });
     $users = map($users, function (UserInterface $user) {
         return $user->getRecord();
     });
     $this->modelController->setModel($users);
 }
 protected function viewModel(ViewModel $viewModel)
 {
     $user = $viewModel->user = $this->user;
     $mySelf = $this->session->user();
     $isDev = $mySelf->roleField() == UserInterface::USER_ROLE_DEVELOPER;
     $isAdmin = $mySelf->roleField() == UserInterface::USER_ROLE_ADMIN;
     // Are we editing the logged-in user?
     $isSelf = $user->idField() == $mySelf->idField();
     if ($isSelf) {
         $this->session->setPreviousUrl($this->request->getHeaderLine('Referer'));
     }
     $viewModel->role = ['dev' => UserInterface::USER_ROLE_DEVELOPER, 'admin' => UserInterface::USER_ROLE_ADMIN, 'standard' => UserInterface::USER_ROLE_STANDARD, 'guest' => UserInterface::USER_ROLE_GUEST];
     $viewModel->show = ['roles' => $isDev || $isAdmin && $this->adminSettings->allowEditRole(), 'active' => !$isSelf && $this->adminSettings->enableUsersDisabling()];
     $viewModel->canDelete = $user->exists && ($isDev || !$isSelf || $this->adminSettings->allowDeleteSelf()) ?: null;
     $viewModel->canRename = $this->adminSettings->allowRename();
 }
 function intended($defaultUrl = '', $status = 302)
 {
     $this->validate();
     $url = $this->session->previousUrl() ?: $this->normalizeUrl($defaultUrl);
     return $this->to($url, $status);
 }
Beispiel #10
0
 protected function initialize()
 {
     parent::initialize();
     $this->session->reflashPreviousUrl();
 }