Ejemplo n.º 1
0
 /**
  * Template's init method is called automatically from `charcoal-app`'s Template Route.
  *
  * For admin templates, initializations is:
  *
  * - to start a session, if necessary
  * - to authenticate
  * - to initialize the template data with `$_GET`
  *
  * @param RequestInterface $request The request to initialize.
  * @return boolean
  * @see \Charcoal\App\Route\TemplateRoute::__invoke()
  */
 public function init(RequestInterface $request)
 {
     if (!session_id()) {
         session_cache_limiter(false);
         session_start();
     }
     if ($this->authRequired() !== false) {
         // This can reset headers / die if unauthorized.
         if (!$this->authenticator->authenticate()) {
             header('HTTP/1.0 403 Forbidden');
             header('Location: ' . $this->adminUrl() . 'login');
             exit;
         }
         // Initialize data with GET
         $this->setData($request->getParams());
         // Test template vs. ACL roles
         $authUser = $this->authenticator()->authenticate();
         if (!$this->authorizer()->userAllowed($authUser, $this->requiredAclPermissions())) {
             header('HTTP/1.0 403 Forbidden');
             header('Location: ' . $this->adminUrl() . 'login');
             exit;
         }
     } else {
         // Initialize data with GET
         $this->setData($request->getParams());
     }
     return parent::init($request);
 }