/**
* Check if the user can access the application
*
* @param integer $itemid The item ID to check authorisation for
*
* @return void
*
* @since 3.2
*
* @throws \Exception When you are not authorised to view the home page menu item
*/
protected function authorise($itemid)
{
$menus = $this->getMenu();
$user = Factory::getUser();
if (!$menus->authorise($itemid)) {
if ($user->get('id') == 0) {
// Set the data
$this->setUserState('users.login.form.data', array('return' => Uri::getInstance()->toString()));
$url = Route::_('index.php?option=com_users&view=login', false);
$this->enqueueMessage(Text::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error');
$this->redirect($url);
} else {
// Get the home page menu item
$home_item = $menus->getDefault($this->getLanguage()->getTag());
// If we are already in the homepage raise an exception
if ($menus->getActive()->id == $home_item->id) {
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
// Otherwise redirect to the homepage and show an error
$this->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
$this->redirect(Route::_('index.php?Itemid=' . $home_item->id, false));
}
}
}