Keyword

Re: 403 page when trying to view category as guest

  • Katharina
  • Katharina's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 4 months ago #66702 by Katharina
You have to set the category AND the menu entry to 'registered'. Then both disappear for guests.

Please Log in or Create an account to join the conversation.

More
12 years 2 months ago #66703 by Arvind Ragunathan
Replied by Arvind Ragunathan on topic Re: 403 page when trying to view category as guest
You can try this:

I am using Joomla v2.5.6 and K2 v2.5.7

If your K2 category is set to registered and you have assigned a menu item to the registered category then you will receive "403 - You are not authorized to view this resource"

To resolve this issue we need to manually change the code on the backend.

1) Go To [SITE ROOT]\components\com_k2\views\itemlist\view.html.php

2) Find the code "JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));" which is contained in

$user = &JFactory::getUser();
if(K2_JVERSION=='16'){
if (!in_array($category->access, $user->authorisedLevels())) {
JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
}
$languageFilter = $mainframe->getLanguageFilter();
$languageTag = JFactory::getLanguage()->getTag();
if($languageFilter && $category->language!=$languageTag && $category->language!='*') {
return;
}
}

3) Replace the code "JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));" with:

if ($this->error->code = '403') {
$return = $_SERVER;
$return = base64_encode($return);
$uri = JRoute::_("index.php?option=com_users&view=login&return=$return");
header('Location:'.$uri); die();
}

4) Final code should look like:

$user = &JFactory::getUser();
if(K2_JVERSION=='16'){
if (!in_array($category->access, $user->authorisedLevels())) {
/*JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));*/
if ($this->error->code = '403') {
$return = $_SERVER;
$return = base64_encode($return);
$uri = JRoute::_("index.php?option=com_users&view=login&return=$return");
header('Location:'.$uri); die();
}

}
$languageFilter = $mainframe->getLanguageFilter();
$languageTag = JFactory::getLanguage()->getTag();
if($languageFilter && $category->language!=$languageTag && $category->language!='*') {
return;
}
}

5) This should resolve the issue.

6) You can do the same for [SITE ROOT]\components\com_k2\views\item\view.html.php

7) Find the code "JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));" which is contained in

if(K2_JVERSION=='16'){
if (!in_array($item->access, $user->authorisedLevels()) || !in_array($item->category->access, $user->authorisedLevels())) {
JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
}
}

8) Replace the code "JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));" with:

if ($this->error->code = '403') {
$return = $_SERVER;
$return = base64_encode($return);
$uri = JRoute::_("index.php?option=com_users&view=login&return=$return");
header('Location:'.$uri); die();
}

9) Final code should look like:

if(K2_JVERSION=='16'){
if (!in_array($item->access, $user->authorisedLevels()) || !in_array($item->category->access, $user->authorisedLevels())) {
/*JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));*/
if ($this->error->code = '403') {
$return = $_SERVER;
$return = base64_encode($return);
$uri = JRoute::_("index.php?option=com_users&view=login&return=$return");
header('Location:'.$uri); die();
}

}
}

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum