/** * Check saml authentication and store credential into */ public final function __construct() { parent::__construct(); $this->layout = 'wide'; $this->_store = $this->_session->getStore(self::SESSION_STORE_NAME, $this->_config->getAdminSessionLifetime()); if ($this->isPreviewMode()) { $class = '\\Jazzee\\AdminAuthentication\\PreviewApplication'; } else { $class = $this->_config->getAdminAuthenticationClass(); } $this->_adminAuthentication = new $class($this); if (!$this->_adminAuthentication instanceof Interfaces\AdminAuthentication) { throw new Exception($this->_config->getAdminAuthenticationClass() . ' does not implement AdminAuthentication Interface.'); } if ($this->_adminAuthentication->isValidUser()) { $this->_user = $this->_adminAuthentication->getUser(); if ($this->_user->getDefaultProgram()) { $this->_program = $this->_user->getDefaultProgram(); } else { if ($programs = $this->_user->getPrograms()) { $programId = array_pop($programs); $program = $this->_em->getRepository('\\Jazzee\\Entity\\Program')->find($programId); $this->_program = $program; $this->_user->setDefaultProgram($program); $this->_em->persist($this->_user); } } if ($this->_user->getDefaultCycle()) { $this->_cycle = $this->_user->getDefaultCycle(); } else { if ($cycle = $this->_em->getRepository('\\Jazzee\\Entity\\Cycle')->findBestCycle($this->_program)) { $this->_cycle = $cycle; $this->_user->setDefaultCycle($cycle); $this->_em->persist($this->_user); } } if (isset($this->_store->currentProgramId)) { $this->_program = $this->_em->getRepository('\\Jazzee\\Entity\\Program')->find($this->_store->currentProgramId); } if (isset($this->_store->currentCycleId)) { $this->_cycle = $this->_em->getRepository('\\Jazzee\\Entity\\Cycle')->find($this->_store->currentCycleId); } if ($this->_cycle and $this->_program) { if (!($this->_application = $this->_em->getRepository('Jazzee\\Entity\\Application')->findOneByProgramAndCycle($this->_program, $this->_cycle))) { $this->_application = null; } } } else { //expire the store for non users - so there are no navigation or caching problems $this->_store->expire(); } if ($this->_config->getAdminSessionLifetime()) { setcookie('JazzeeAdminLoginTimeout', time() + $this->_config->getAdminSessionLifetime(), 0, '/'); } else { //if there is no seesion limiter then setup for 24 hours setcookie('JazzeeAdminLoginTimeout', time() + 86400, 0, '/'); } }
/** * Only allow change program if the user is in at least one program * At this top level always return false so nothing is allowed by default * @param string $controller * @param string $action * @param \Jazzee\Entity\User $user * @param \Jazzee\Entity\Program $program * @return bool */ public static function isAllowed($controller, $action, \Jazzee\Entity\User $user = null, \Jazzee\Entity\Program $program = null, \Jazzee\Entity\Application $application = null) { //Several actions are allowed as long as the user is in at least one program $specialActions = array('index', 'getAllowedPrograms', 'changeTo'); if ($user and in_array($action, $specialActions)) { $userPrograms = $user->getPrograms(); return parent::isAllowed($controller, 'anyprogram', $user) or !empty($userPrograms); } return parent::isAllowed($controller, $action, $user, $program, $application); }