User Specific Login Redirect

Your code modifications and patches you want to share with others.
User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Mon May 24, 2010 9:41 pm

ok, and what happends when you login with the correct password?

Olaf
Olaf Offick - Global Moderator
learnskills.org

MickHill10
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed May 19, 2010 11:48 pm

Re: User Specific Login Redirect

Post by MickHill10 » Tue May 25, 2010 7:52 pm

If you look at this link this will show you what happens when you logged in (I have attached a photo in the content so that you can see)

http://www.ips-photography.co.uk/index. ... e&Itemid=1

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Tue May 25, 2010 9:11 pm

ok, so that means that the parameter is not working:

Code: Select all

$return = $user->getParam('url');
Try to hard code a URL to see if the other code is working.

Olaf
Olaf Offick - Global Moderator
learnskills.org

MickHill10
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed May 19, 2010 11:48 pm

Re: User Specific Login Redirect

Post by MickHill10 » Wed May 26, 2010 9:12 pm

tried to hard code and it didn't make any difference. I have put it back now to how it was: -

$return = $user->getParam('url');

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Wed May 26, 2010 9:15 pm

well, then you probably changing the wrong file.

Olaf
Olaf Offick - Global Moderator
learnskills.org

MickHill10
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed May 19, 2010 11:48 pm

Re: User Specific Login Redirect

Post by MickHill10 » Wed May 26, 2010 9:38 pm

I have just had a quick mess around and changed this bit: -

// Redirect if the return url is not registration or login
if ( ! $return ) {
$return = 'index.php?option=com_user';
}

to

// Redirect if the return url is not registration or login
if ( ! $return ) {
$return = 'http://www.ips-photography.co.uk/index. ... 2&Itemid=3';

and it worked

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Wed May 26, 2010 9:51 pm

I just tried this myself and that works as well:

Code: Select all

		if(!JError::isError($error))
		{
			$return = "index.php?test";
			// Redirect if the return url is not registration or login
			if ( ! $return ) {
				$return	= 'index.php?option=com_user';
			}

			$mainframe->redirect( $return );
		}
So if your url parameter is not working then it is probably not saved in the user object.

Olaf
Olaf Offick - Global Moderator
learnskills.org

MickHill10
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed May 19, 2010 11:48 pm

Re: User Specific Login Redirect

Post by MickHill10 » Thu May 27, 2010 6:59 am

This is what is in the user.xml (I am hoping this is what you meant): -

<form>
<params>
<param name="admin_language" type="languages" client="administrator" default="" label="Back-end Language" description="paramAdminLanguage" />
<param name="language" type="languages" client="site" default="" label="Front-end Language" description="paramLanguage" />
<param name="editor" type="editors" default="" label="User Editor" description="WYSIWYG Editor for this User" />
<param name="helpsite" type="helpsites" default="" label="Help Site" description="Help Site for this User" />
<param name="timezone" type="timezones" default="" label="Time Zone" description="Time Zone for this User" />
<param name="login" type="menuitem" default="" label="Login Redirection URL" description="What page will the login redirect to after user login, if let blank will load module default" />
<param name="logout" type="menuitem" default="" label="Logout Redirection URL" description="What page will the login redirect to after user logout, if let blank will load module default" />
</params>
</form>

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Thu May 27, 2010 8:58 am

ok, I so you added two parameters login and logout, correct?

However, in your controller you are trying to access the parameter url, which doesn't exist.

Try to find this

Code: Select all

getParam('url');
and replace it with this

Code: Select all

getParam('login');
Olaf
Olaf Offick - Global Moderator
learnskills.org

MickHill10
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed May 19, 2010 11:48 pm

Re: User Specific Login Redirect

Post by MickHill10 » Thu May 27, 2010 9:47 pm

Great stuff, its all working - many thanks for all your help on this, very appreciated.

ebajh69
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Sep 05, 2005 1:26 am

Re: User Specific Login Redirect

Post by ebajh69 » Tue Jun 08, 2010 2:30 pm

I didn't see this answered before.. So apologies if it was. I am running Joomla 1.5.18.

When a user registers on my site, I need them to enter some additional information. When they log into the site for the 1st time (or until such time as they have entered in the information) I want to redirect users one page (a form I have setup which prompts to collect additional user information). If they already entered the necessary information, I want them to be redirected to a different page upon subsequent logins.

Someone wrote me this piece of code that is supposed to check that the user entered the additional information, but I am not sure where I would put it to get the results I described above.

I am using the standard Login Module.

Code: Select all

<?php
// check if in noc_users table
$database = &JFactory::getDBO();
$USER =& JFactory::getUser();
$uid = $USER->id;
$qrstring = "SELECT * FROM #__noc_users WHERE user_id = '$uid' ";
$database->setQuery($qrstring);
$dberr="";

if (!$database->query()) {
   $dberr = $database->getErrorMsg();
   echo($dberr."<br>");
   echo($func." : ".$uid."-- ".time());
}
$rows = $database->loadObjectList();
$num_rows = count($rows);
   if($num_rows == 0){
      $host = $_SERVER["HTTP_HOST"];
      header("Location: /index.php?option=com_nocform&func=doform");
}
?> 
Thanks in advance.

Evan

kiminox
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Oct 04, 2008 8:20 pm

Re: User Specific Login Redirect for JOOMLA 1.5.17

Post by kiminox » Tue Jul 13, 2010 2:45 am

Hi,

For those who faced to the same problem, here is the process for the Joomla! 1.5.17.
1) open the XML file: administrator/components/com_users/models/user.xml
and the parameters that will be available for EACH user:

Code: Select all

<!-- Yoong Kim 13/07/2010: add custom redirection after logged -->
		<param name="url" type="text" default="" label="Front-end Login Redirect" description="URL redirect for a Front-end login" />
		<param name="adminurl" type="text" default="" label="Back-end Login Redirect" description="URL redirect for a Back-end login" />
2) Open the PHP file:administrator/components/com_login/admin.login.php
and modify the line number 66 (well, around 66 of course!)

Code: Select all

		// Yoong Kim 13/07/2010: add custom redirect
		$user =& JFactory::getUser();
		$user->getParameters();
		$returnAdminUrl = $user->getParam('adminurl');
		
		
		if (!JError::isError($result)) {
		   // Yoong Kim 13/07/2010: add custom redirect
		   $return = 'index.php';
		   if ( !empty($returnAdminUrl) ) {
		   	  $return = $returnAdminUrl;
		   }
		   $mainframe->redirect($return);
		}
3) if you want to configure a special url redirect for an user, go to the control panel, open the user manager. In the "Parameters" tab, you should see 2 ne parameters:
Front-end Login Redirect
Back-end Login Redirect

Fill the fields and save the user.

Yoong

PS: you can do the same thing for the frontend login.

miguelcravo
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sun Aug 15, 2010 3:35 pm

Re: User Specific Login Redirect

Post by miguelcravo » Sun Aug 15, 2010 3:38 pm

Qwomg wrote:Instructions for Joomla 1.5(.8 ) (with credit @barnett):

1. On the files
administrator/components/com_users/models/author.xml
administrator/components/com_users/models/registered.xml
administrator/components/com_users/models/user.xml
right before </params> add the following lines:

Code: Select all

<param name="login" type="menuitem" default="" label="Login Redirection URL" description="What page will the login redirect to after user login, if let blank will load module default" />
<param name="logout" type="menuitem" default="" label="Logout Redirection URL" description="What page will the login redirect to after user logout, if let blank will load module default" />
2. Go to components/com_user/controller.php and after line ~134:

Code: Select all

$error = $mainframe->login($credentials, $options);
add the following code:

Code: Select all

$user =& JFactory::getUser();
$menu =& JSite::getMenu();
$userRedirect = $user->getParam('login');
if ($userRedirect) {
        $item = $menu->getItem($userRedirect);
	$url = $item->link;
        $return = $url;
}
3. One the same file (controller.php) after line ~160:

Code: Select all

	function logout()
	{
		global $mainframe;
add:

Code: Select all

$user =& JFactory::getUser();
$menu =& JSite::getMenu();
$userRedirect = $user->getParam('logout');
if ($userRedirect) {
        $item = $menu->getItem($userRedirect);
	$url = $item->link;
        $return = $url;
}
then a couple of lines later, after

Code: Select all

		if(!JError::isError($error))
		{
add:

Code: Select all

if (!$return)
one line before the next if.

4. Set up individual user login and logout redirections from the user manager.
This is absolutely amazing!! IT WORKS WITH COMMUNITY BUILDER with no additional codes!
Thanks so much!! :D

Divit
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Oct 24, 2005 1:35 pm

Re: User Specific Login Redirect

Post by Divit » Wed Sep 08, 2010 7:43 am

I succeeded in getting the redirect to work. So after a login the user ends up on his personal page. But now I would like a button to get him (or her) back to that page after he (os she) has been browsing the site. From what I read in this topic this seems to be a wish more people have. Anyone succeeded in getting this button to work?

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Wed Sep 08, 2010 8:15 am

Why don't you create a module, generate the URL and output that as a link or button?

Olaf
Olaf Offick - Global Moderator
learnskills.org

Divit
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Oct 24, 2005 1:35 pm

Re: User Specific Login Redirect

Post by Divit » Wed Sep 08, 2010 8:34 am

Olaf
simply because I don't know how ;-) If I would, I wouldn't have posted my question in the first place don't you think.

;-)
Good to know this topic is still alive.

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Wed Sep 08, 2010 8:43 am

You would will find a Tutorial on how to create a module here: http://docs.joomla.org/How_to_create_a_module

And instead of outputing Hello World, you will need to output the link , similar to the redirect you have done earlier.

Code: Select all

<?php
$user =& JFactory::getUser();
$userRedirect = $user->getParam('YOUR_PARAMETER');
?>
<a href="<?php echo $userRedirect; ?>">YOUR_CLICK_HERE_TEXT</a>
You will need to change YOUR_CLICK_HERE_TEXT and YOUR_PARAMETER to whatever you need.

Olaf
Olaf Offick - Global Moderator
learnskills.org

Divit
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Oct 24, 2005 1:35 pm

Re: User Specific Login Redirect

Post by Divit » Wed Sep 08, 2010 9:02 am

Thanks Olaf
After I've finished trying to get Pages and Items fix my problem I'll have a look at your solution.

My problem is in fact quit simple. I need different users to have different access to documents. And NO DOCMAN is not a solution for me cause in Docman it is not possible to multi-select access-groups on a document. So every time users/groups/access changes I have to rearrange.

The idea is to get users (belonging to a certain group) to a page with weblinks to documents and to use the button to let them return to this page.

So far; http://www.pages-and-items.com/index.php looks promissing to me!

Thanks again!

Divit
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Oct 24, 2005 1:35 pm

Re: User Specific Login Redirect

Post by Divit » Thu Sep 09, 2010 11:40 am

Olaf
If I try rour example my test.php says;
Fatal error: Class 'JFactory' not found in /home/*****/domains/******/public_html/test.php on line 2

*** = censored ;-)

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Thu Sep 09, 2010 12:02 pm

yes, JFactory is a joomla class, so you will not be able to run it outside the joomla framework.
That's why I suggested to create a module with a link to the tutorial:
http://docs.joomla.org/How_to_create_a_module

Please note that you have to install the module in order to use the joomla framework.

Olaf
Olaf Offick - Global Moderator
learnskills.org

Divit
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Oct 24, 2005 1:35 pm

Re: User Specific Login Redirect

Post by Divit » Thu Sep 09, 2010 12:16 pm

I've tried to create a module for golfscores on my website but got stuck. Since this is a whole new subject I'll leave that for what it is. Pages and Items does the trick for me. I've created several pages and can redirect users to the pages they need to see together with a nice link in a menu. Thank you all for your time and effort!

weddingdj
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Wed Sep 08, 2010 5:50 pm
Location: Staffordshire, UK

Re: User Specific Login Redirect

Post by weddingdj » Sun Oct 10, 2010 6:53 pm

hi folks,

Will this help me accomplish what I am trying to do in http://forum.joomla.org/viewtopic.php?f=470&t=554894??

Divit
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Oct 24, 2005 1:35 pm

Re: User Specific Login Redirect

Post by Divit » Sun Oct 10, 2010 7:00 pm

I've you create a "special" page for each and everyone of your users you are correct. Simply redirect to the special page.

ekfrasi
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Jul 11, 2008 2:42 pm

Re: User Specific Login Redirect for JOOMLA 1.5.17

Post by ekfrasi » Thu Oct 21, 2010 11:51 am

PS: you can do the same thing for the frontend login.
HOW?

shadowzone
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Mon Aug 02, 2010 7:01 am

Re: User Specific Login Redirect

Post by shadowzone » Sat Nov 06, 2010 12:15 am

Hi
I'm running 1.5.18, but I can't seem to make this work. When I make the changes to admin.login.php, attempts to login just loops back to the login page. Following is the code for my admin.login.php
<?php
/**
* @version $Id: admin.login.php 14401 2010-01-26 14:10:00Z louis $
* @package Joomla
* @subpackage Joomla.Extensions
* @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

switch ( JRequest::getCmd('task'))
{
case 'login' :
LoginController::login();
break;

case 'logout' :
LoginController::logout();
break;

default :
LoginController::display();
break;
}


/**
* Static class to hold controller functions for the Login component
*
* @static
* @package Joomla
* @subpackage Login
* @since 1.5
*/
class LoginController
{
function display()
{
jimport('joomla.application.module.helper');
$module = & JModuleHelper::getModule('mod_login');
$module = JModuleHelper::renderModule($module, array('style' => 'rounded', 'id' => 'section-box'));
echo $module;
}

function login()
{
global $mainframe;

// Check for request forgeries
JRequest::checkToken('request') or jexit( 'Invalid Token' );

$credentials = array();

$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getVar('passwd', '', 'post', 'string', JREQUEST_ALLOWRAW);

// Yoong Kim 13/07/2010: add custom redirect
$user =& JFactory::getUser();
$user->getParameters();
$returnAdminUrl = $user->getParam('adminurl');


if (!JError::isError($result)) {
// Yoong Kim 13/07/2010: add custom redirect
$return = 'index.php';
if ( !empty($returnAdminUrl) ) {
$return = $returnAdminUrl;
}
$mainframe->redirect($return);
}





if (!JError::isError($result)) {
$mainframe->redirect('index.php');
}

LoginController::display();
}

function logout()
{
global $mainframe;

$result = $mainframe->logout();

if (!JError::isError($result)) {
$mainframe->redirect('index.php?option=com_login');
}

LoginController::display();
}
}
I'm new to this so be gentle with me. I'm wondering if it might be that I need to add the URL redirects for the login I'm using somewhere first, but I don't know where to do this.

bithesh123
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Thu Jul 22, 2010 4:48 am

Re: User Specific Login Redirect

Post by bithesh123 » Thu Jan 13, 2011 9:14 am

hai i am using joomla 1.5.20 i dont see the codes in \administrator\components\com_users.So pls specify the code for joomla1.5.20 for different login redirect
Last edited by ooffick on Thu Jan 13, 2011 12:17 pm, edited 1 time in total.
Reason: Mod Note: Duplicate post deleted, please do not post your question multiple times. Please read the forum rules for details.

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11615
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: User Specific Login Redirect

Post by ooffick » Thu Jan 13, 2011 12:31 pm

Which "codes" can you not see, did you read all the posts in this topic?

Olaf
Olaf Offick - Global Moderator
learnskills.org

TboneMofo
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Jan 25, 2011 10:48 pm

Re: User Specific Login Redirect

Post by TboneMofo » Tue Jan 25, 2011 10:52 pm

Can someone please post the complete instructions for this for Joomla! 1.5.22. I have tried several versions of the instructions in this thread, and none is working yet. I'm assuming it is because my version is newer than older sets of instructions.

Thank you in advance!

brergo
Joomla! Intern
Joomla! Intern
Posts: 59
Joined: Tue Mar 17, 2009 11:17 pm

Re: User Specific Login Redirect

Post by brergo » Mon Feb 07, 2011 1:15 am

TboneMofo wrote:Can someone please post the complete instructions for this for Joomla! 1.5.22. I have tried several versions of the instructions in this thread, and none is working yet. I'm assuming it is because my version is newer than older sets of instructions.

Thank you in advance!
I second TboneMofo's request....please

nicmehr
I've been banned!
Posts: 36
Joined: Fri Feb 04, 2011 12:19 pm

Re: User Specific Login Redirect

Post by nicmehr » Mon Feb 07, 2011 7:51 am

brergo wrote:
TboneMofo wrote:Can someone please post the complete instructions for this for Joomla! 1.5.22. I have tried several versions of the instructions in this thread, and none is working yet. I'm assuming it is because my version is newer than older sets of instructions.

Thank you in advance!
I second TboneMofo's request....please
i think this stracture is general and its not related to joomla version


Locked

Return to “Core Hacks and Patches”