Ogri's Playground - ogri.me | Joomla 3: Redirect to same page after successful loginOn the site, authorization occurs through the mod_login module. In the module settings, the option Login Redirection Page is set to Default. After entering the correct username and password, however, Joomla redirects to a variety of places, depending on which extension owns the currently active page. Sometimes it redirects to the site root, other time to a category blog. It's inconvenient. When a user exits (redirection option is also Default), the page does not change, everything is good.

I had to dig around and find a place in the code where the redirect is implemented. It was found not in the authorization module, but in the com_userscomponent. Namely, in the file components\com_users\controllers\user.php. And a small change in its code resolved the issue.

The login() function has been modified. Here is the original one:

public function login()
{
  $this->checkToken('post');
 
......................
 
  $app->redirect(JRoute::_($app->getUserState('users.login.form.return'), false));
}

And now look at the changed one.

public function login()
{
  $this->checkToken('post');
 
......................
 
//comment out default redirect
//  $app->redirect(JRoute::_($app->getUserState('users.login.form.return'), false));
 
//redirect to the same page
  $return = $input->get('return', '', 'BASE64');
  $return = base64_decode($return);
  $app->redirect(JRoute::_($return, false));
}

As you can see, the last line is commented out and three new lines have been added instead. The logic is taken from the next function, logout().

It is unclear what prevents the developers from fixing this discrepancy. Perhaps it, like many others, will be fixed in Joomla 4.

Users must be registered and logged in to post comments.

By working with this site, you agree to our use of cookies necessary to keep the settings you select, as well as for the normal operation of Google services.