How to track jos-Error in Joomla 2.5? - php

I made one of my menu items only for Guests (not logged in users). ANd If user logs in, it disappears from menu. It works fine...
But I noticed that when I put the link to the Guest menu item in browser, when I'm lnot ogged in , it shows very disgusting jos-Error: You are not authorised to view this resource.
I want to find a way to track such errors and redirect to custom 404 page or some other page.
Please, assist me in this issue.
Thanks

The string You are not authorised to view this resource located in JERROR_ALERTNOAUTHOR language string and fire in includes/application.php function:
public function authorise($itemid)
{
$menus = $this->getMenu();
$user = JFactory::getUser();
if (!$menus->authorise($itemid))
{
if ($user->get('id') == 0)
{
// Redirect to login
$uri = JFactory::getURI();
$return = (string)$uri;
$this->setUserState('users.login.form.data', array( 'return' => $return ) );
$url = 'index.php?option=com_users&view=login';
$url = JRoute::_($url, false);
$this->redirect($url, JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'));
}
else {
JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
}
}
}
You could alter this function and add redirection or change the text string with your desired message.
Redirect could be done with redirect() method.
An example of redirect syntax:
$app = JFactory::getApplication();
$app->redirect(JRoute::_(JURI::root().'index.php'));
Please make sure that you won't alter application.php without creating an override system plugin.
Hope this helps

Related

Language loading and back button issue with CodeIgniter

I made a multi-lang app for contents. In the backend, you create content, and show it in a frontend page. I have an issue with the back button (I think its a cache issue) following the next steps:
You click in a content link and access to the content view.
In the current content view (with the current language), you click to
switch language.
It redirects you to home with the new language.
When you press back button, it sends you to the previus content (in
the previus language).
A consideration:
- If I clear the browser cache between the steps 2-3, it works fine.
Here is the code:
In the language switcher controller
$this->lang_array = $this->Language_model->getLangsArray();
if(!isset($this->session->lang)){
if(array_key_exists($this->uri->segment(1), $this->lang_array)){
$this->session->lang = $this->uri->segment(1);
}else{
$this->session->lang = 'es';
}
}
if(isset($this->session->lang)){
if(array_key_exists($this->uri->segment(1), $this->lang_array) && $this->uri->segment(1) != $this->session->lang){
$this->session->lang = $this->uri->segment(1);
}
}
$this->lang->load($this->lang_array[$this->session->lang], $this->lang_array[$this->session->lang]);
To return the view with content, in the contents controller:
$content = $this->db->get_where('contents', array('slug' => $slug), 1)->result();
if(count($content)){
$content = $content[0];
$this->view('content_view', $content));
}else{
return array();
}

Joomla PHP how to programatically be taken to Edit Profile page

What is the best way to force users to the edit profile page.
Here is my code :
$user = JFactory::getUser();
if ($user->email === "fakemail#spam-disposable-domain.com") {
//Redirect user to the edit profile page forcing them to change their email.
//index.php?option=com_users&view=profile&layout=edit
}
I want to redirect users who's emails match that to force them to edit their profile the correct way to redirect them to the edit profile page is what I need to know.
Use the redirect() method of the application object:
$app = JFactory::getApplication();
$user = JFactory::getUser();
if ($user->email === "fakemail#spam-disposable-domain.com")
{
$app->enqueueMessage('Please change your email address!');
$app->redirect(
JRoute::_(
'index.php?option=com_users&view=profile&layout=edit'
)
);
}

WPML changes WordPress language to default when redirecting from login page

I am building a bilingual website using WordPress and WPML(the translation plugin WPML), also to handle login and registration I used Theme my login, however since it's not compatible with WPML, I had to find an alternative (tried clean-login ) but still no luck.
The problem I faced with theme my login; it's not supporting templates for both languages only the English part (the other language is Arabic), while using clean-login you can't modify it's templates (while I needed to add some fields to user registration).
Finally I followed the tutorial in this link to build my own login and registration plugin, the problem I'm facing now is that each time a login is made, I'm being redirected to the user profile (which is the correct behavior) but instead of keeping the same language from the login page, it redirects to the user profile with the default language although I was trying to login from the Arabic login page.
I tried several fixes for the language redirection problem; like trying to modify the locale using wp locale filter through a custom function, or by using a conditional on the $_GET['lang'], unfortunately nothing worked.
An example for the various solutions I tried using the $_GET['lang'] parameter;
setting a public variable ($site_lang) in the custom plugin class:
public $site_lang;
public function __construct() {
global $sitepress;
$current_lang = $sitepress->get_current_language();
if ( isset($_GET['lang']) && $_GET['lang'] == 'ar'){
$this->site_lang = 'ar';
}else{
$this->site_lang = 'en_US';
}
}
Another variation using session through the plugin WP_SESSION
global $sitepress;
$current_lang = $sitepress->get_current_language();
$wp_session = WP_Session::get_instance();
$wp_session['act_lang'] = 'ar';
if (!isset($_GET['lang'])){
$wp_session['act_lang'] = 'en';
}else{
$wp_session['act_lang'] = 'ar';
}
$this->site_lang = $wp_session['act_lang'];
and the redirect on registration error function, which is one of many functions that deals with redirect, I'm putting it here as an example on how I'm using the public variable for redirection
public function maybe_redirect_at_authenticate( $user, $username, $password ) {
if( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
$login_url = ($this->site_lang == 'ar') ? site_url( 'تسجيل-الدخول/?lang=ar' )
: home_url( 'member-login' );
$login_url = add_query_arg( array('login' => $error_codes), $login_url );
wp_redirect( $login_url );
}
}
If anyone has a solution on how to keep the language the same after redirection, I really do appreciate the help.

redirect customer to associated website on successful registration

I'd been working on a module where customer choose at the time of registration for which website he need to register. So far I'd done it working. A quick reference to that. On successful registration the customer is being redirected to customer/account/ in the current website regardless of which website he chosen. But I need him to be redirected to that particular website for which he had registered.
So far I'd tried overriding the Customer/AccountController's _welcomeCustomer():
protected function _welcomeCustomer($customer, $isJustConformed = false) {
$webid = $customer->getWebsiteId();
$successurl = parent::_welcomeCustomer($customer, $isJustConfirmed);
if (Mage::app()->getStore()->getWebsiteId() == $webid) {
return $successurl;
} else {
return Mage::app()->getWebsite($webid)->getDefaultStore()->getBaseUrl() . 'customer/account/index';
}
}
But instead of redirecting the customer to associated website it being redirected to home page of the current website. Any help? How could it be done? or this happening so?
Try adding the store code as a GET parameter to the URL (___store=xyz).
Probably you will also need to add the Session ID to the url (param name: SID).
this auto-login module helped me to achieve what I'm looking for.
Rest of the thing I've done to make it work proper is:
Overridden the Customer/AccountController's _welcomeCustomer()
protected function _welcomeCustomer($customer, $isJustConformed = false) {
$webid = $customer->getWebsiteId();
$encpw = ;//get customer password and encrypt it;
if (Mage::app()->getStore()->getWebsiteId() == $webid) {
return parent::_welcomeCustomer($customer, $isJustConfirmed);
} else {
$redr = Mage::app()->getWebsite($webid)->getDefaultStore()
->getBaseUrl() . 'customer/account/autoLogin/'
. 'user/' . $customer->getEmail() . '/pwd/' . $encpw .
'/';
return $redr;
}
}
One more thing might needed to be changed in _successProcessRegistration() is to replace $this->_redirectSuccess($url); with $this->_redirectUrl($url);

ignoring frontpage.php in codeigniter

I'm currently working on an existing website created in codeigniter.
Whenever a user enters a page, he gets redirected to frontpage.php, that checks if the user is logged in, if not he gets redirected to the login page.
Now, I have one page where this frontpage.php shouldnt be executed, and any user can enter it.
Any help is greatly appreciated.
Had a similar problem and solved it this way by using some online tutorials
1: Make a seperate loginpage (ex login.php) prior to the 'frontpage.php'.
2: Pass the login, password and a session variable to the frontpage.
3: Recode you 'frontpage.php' to check for the session variable passed by 'login.php'.
If u entered the page trough the normal way it will use the normal login.
if u entered the page trough the new 'login.php' page it will be picked up by the recoded 'frontpage.php' and bypass the normal way.
Hope this helps
Grtz
Re-route everything to your pages controller and use this as your default
$route['default_controller'] = 'pages';
$route['(.*)'] = 'pages/index/$1';
-
class Pages extends CI_Controller
{
protected $currentUser = null;
public function __construct()
{
parent::__construct();
$this->currentUser = Auth::getCurrentUserObject(); //check user is logged in
}
public function index($uri='home')
{
$sizeOfSegments = sizeof($this->uri->rsegments);
if ($sizeOfSegments >= 3)
{
$uri = $this->uri->rsegments[3];
}
else
{
$uri = 'home';
}
$pageFound = Page::find($uri); //query the database
if (!$pageFound)
{
return show_404($uri); // find out where there were headed
}
unset($sizeOfSegments, $uri);
if(is_null($this->currentUser) OR !$this->currentUserHasPermissionToViewThisPage OR !$pageIsNotPublic)
{
return redirect('login');
}
$this->load->view();
}
}
make new controller
class Newpage extends CI_Controller {
public function index(){
$this->load->view('newpage');
}
}
now goto
yourhost.com/index.php/newpage
May be your default Controller have a coding of checking whether user is logged or not. Please remove or change the code in controller.
I think you need to delete the controller, it works like that!

Categories