March 21, 2011
In the controllers on_start() method do the following:
public function on_start()
{
// ******************* Demo Override *************
$u = new User();
// If the user is not admin (uID 1)
// or not logged in yet (uID NULL).
// The uID != NULL is used to be able to login the demo user
// Or yourself!
if ($u->uID != '1' && $u->uID != NULL) {
$page = Page::getByPath(str_replace('index.php/', '', $_SERVER['REQUEST_URI']));
$allowedPages = array(
'your_package_starting_page',
'other_dashboard_page_allowed',
'login',
'/index.php',
'/index.php?cID=1'
);
$session = \Core::make('session');
$continue = false;
foreach($allowedPages as $e){
if(strpos($page->getCollectionPath(), $e) !== false || strpos($_SERVER['REQUEST_URI'], 'login/logout') !== false){
$continue = true;
break;
}
}
if(!$continue){
$session->set('no_access', t('This is a demo site. You don\'t have access to the page \'%s\'', $page->getCollectionName()));
$response = \Redirect::to('/dashboard/your_package_starting_page');
$response->send();
exit;
}
}
// ******************* Demo Override *************
// Here goes the rest of the on_start method
}
And in the starting single page of your package you add the following code:
$session = \Core::make('session');
$m = $session->get('no_access');
if($session->has('no_access')) {
// Naturally you'll do some HTML message box in here, but it doesn't seem to be possible inside a HowTo
print $m;
}
$session->remove('no_access');
Loading Conversation