/** * When visiting any page on the site, check if the user is already logged in, * or they are visiting a page that is allowed when logged out. Otherwise, * redirect to the login page. If visiting the login page, check the browser * supports cookies. */ public function check() { $uri = new URI(); // Skip check when accessing the data services, as it is redundant but would slow the services down. // Also no need to login when running the scheduled tasks. if ($uri->segment(1) == 'services' || $uri->segment(1) == 'scheduled_tasks') { return; } // check for setup request // if ($uri->segment(1) == 'setup_check') { // get kohana paths // $ipaths = Kohana::include_paths(); // check if indicia_setup module folder exists // clearstatcache(); foreach ($ipaths as $path) { if (preg_match("/indicia_setup/", $path) && file_exists($path)) { return; } } } // Always logged in $auth = new Auth(); if (!$auth->logged_in() and !$auth->auto_login() and $uri->segment(1) != 'login' and $uri->segment(1) != 'logout' and $uri->segment(1) != 'new_password' and $uri->segment(1) != 'forgotten_password') { $_SESSION['requested_page'] = $uri->string(); url::redirect('login'); } else { if ($auth->logged_in() and is_null($_SESSION['auth_user']->password) and $uri->segment(1) != 'new_password' and $uri->segment(1) != 'logout' and $uri->segment(1) != 'setup_check') { $_SESSION['requested_page'] = $uri->string(); url::redirect('new_password'); } } }
/** * Show invite only page if enabled */ public function login() { $uri = new URI(); // Redirect to invite page if not logged or signing in if (!in_array($uri->string(), array('invite', 'sign/in')) && strpos($uri->string(), 'sign/up') !== 0 && !Visitor::instance()->logged_in()) { // Stop execution if ajax, ie. expired session and trying to do ajax call if (request::is_ajax()) { exit; } url::redirect('invite'); } }