User Specific Login Redirect

Your code modifications and patches you want to share with others.
sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: User Specific Login Redirect

Postby sraj49 » Tue Sep 01, 2009 3:52 pm

Thanks a lot. I have a small issue...When I login to the application through the Home page and when I log out I am not logged out of the main login. If I close the browser or click the back button, the user is still logged in and you have to click Log out twice to get back to the home page. Do you have any suggestion...Than you once again

iamwaggle
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Tue Sep 01, 2009 8:05 am

Re: User Specific Login Redirect

Postby iamwaggle » Tue Sep 01, 2009 5:05 pm

Hey sraj49!

I'm not experiencing the same problem that you are having. Do you need to upgrade your Joomla! system to the latest? I made some improvements to our little method however... Maybe this will help. I hope it does!

This is a compilation of work done by iamwaggle, sraj49, and Olaf:

~~~~Login Redirect Hack~~~~

1: create field for the url........For this you need to change the following codes:

a) admin/component/com_user/models/user.xml ...add this at the end....

Code: Select all

<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" />


b) admin/components/com_user/models/registered.xml...add this at the end...

Code: Select all

<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: After this go to components/com_user/controller.php...after line 146???

In the login function, change this:

Code: Select all

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


To this:

Code: Select all

if(!JError::isError($error))
{
$user =& JFactory::getUser();
$user->getParameters();
if (!$user->getParam('url') == ''){
$return = $user->getParam('url');
}

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


3: /administrator/components/com_login/admin.login.php... after line 66???

In the login function, change this:

Code: Select all

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


To this:

Code: Select all

$user =& JFactory::getUser();
$user->getParameters();
$return = $user->getParam('url');

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



Now when you create a user using the User Manager, you can specify the Front-End and Back-end URLs. These can be edited at any time. When you make this change to a user's parameters, the login automatically redirects the user to the specific URL in the user profile.

Many thanks to Raj and Olaf for laying all the groundwork!
~iamwaggle

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: User Specific Login Redirect

Postby sraj49 » Tue Sep 01, 2009 6:10 pm

Thanks a lot and youy are welcome..

cantorgreen
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Sep 01, 2009 6:10 pm

Re: User Specific Login Redirect

Postby cantorgreen » Tue Sep 01, 2009 6:14 pm

Raj - I added your code and it works when you create a new user (thank you!)

But when I go back in to EDIT the user, the URL field does not appear, so I can't change it, short of deleting and re-creating the user.

Any thoughts?
Thanks
Jason Green

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: User Specific Login Redirect

Postby sraj49 » Tue Sep 01, 2009 6:17 pm

When I go to the User Manager and try to create a New USer I do not fonr the fields for Front-end and Backend URL's

iamwaggle
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Tue Sep 01, 2009 8:05 am

Re: User Specific Login Redirect

Postby iamwaggle » Tue Sep 01, 2009 6:25 pm

The database doesn't have the new parameters for your users until you re-save. In the database under "users" the params field needs to have:

url=
adminurl=

Try creating a new user. Try editing an existing user and coming back. If those things don't work, go into your database and add

url=
adminurl=

to the 'params' part of the user entry in the jos_users table

Best,
iamwaggle

iamwaggle
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Tue Sep 01, 2009 8:05 am

Re: User Specific Login Redirect

Postby iamwaggle » Tue Sep 01, 2009 6:27 pm

I do get the Front-end/Back-end fields with a new user creation. I don't know why you wouldn't unless you didn't change the XML docs correctly. Maybe a cache thing?


snake3y3s
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Wed May 13, 2009 6:38 pm

Re: User Specific Login Redirect

Postby snake3y3s » Tue Sep 08, 2009 2:02 pm

sorry if im hijacking the thread a little, but pulling out hair is beginning to make me go bald, Im trying to get a user specific thing going too, but its not working.

I have managed to make a "redirect to" based on users.

But i want to add a menu item that pops up specific to that logged in user.

I.E. we look at the menu on our main page and it has items on it like: home, work, clients, latest news, about us, contact us and client login.
now i want an item to appear after client login once a user has logged in (just like if u set a menu items access level to "registered user") BUT i want that item to link to a page SPECIFIC TO THE CURRENT LOGGED IN USER.

Any help/ideas?
All help greatly appreciated

rdimou
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sat Sep 05, 2009 4:14 pm

Re: User Specific Login Redirect

Postby rdimou » Tue Sep 29, 2009 9:52 am

Hello to all, i am using Joomla! 1.5.13.
I need to have 2 pages show up as home page, one for public and one for users that are logged in/registered. I have created them both and i made one Public and the other Registered (Access Level ). When i am not log in i see the public page ok. But when i log in i see the article for registered users...but also below that article the public one also appears. What am i doing wrong?
can you help me?
thank you

mic
Joomla! Guru
Joomla! Guru
Posts: 692
Joined: Thu Aug 18, 2005 10:51 pm
Location: Austria
Contact:

Re: User Specific Login Redirect

Postby mic » Tue Sep 29, 2009 5:06 pm

1. use the lates Joomla version (actual 1.5.14)!
2. this is how Joomla works: each higher ACL level can see all his items AND what is for lower levels (same for frontend as well for the backend)
http://www.joomx.com - custom extensions and development
http://www.joomlasupportdesk.com - support, migration, training and consulting
Member of the German Joomla Translation Team

jackv
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri Jun 02, 2006 5:37 am

Re: User Specific Login Redirect

Postby jackv » Fri Oct 09, 2009 5:30 pm

I am so glad I found this. Thank you iamwaggle, sraj49, and Olaf! And it works great.

However, my user information details do not show the url field when I return after saving. I double checked all the edits/hack. I have even made sure the "url=" was added to the param in the database (per your suggestion iamwaggle). I don't believe it is a cache issue either.

Does anyone have another suggestion why I cannot see the url (except for the very first time a new user is created)?

Thanks all

umccoy
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Thu Oct 22, 2009 4:34 pm

Re: User Specific Login Redirect

Postby umccoy » Tue Oct 27, 2009 4:41 am

How do I get my login page to bring up the specific page? Where do I "link" it?

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

Re: User Specific Login Redirect

Postby ooffick » Tue Oct 27, 2009 9:33 am

Do you use the mod_login module?

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

umccoy
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Thu Oct 22, 2009 4:34 pm

Re: User Specific Login Redirect

Postby umccoy » Tue Oct 27, 2009 2:07 pm

Yes.

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

Re: User Specific Login Redirect

Postby ooffick » Tue Oct 27, 2009 2:13 pm

Did you look into the module parameters? There is an option to add the login URL.

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

umccoy
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Thu Oct 22, 2009 4:34 pm

Re: User Specific Login Redirect

Postby umccoy » Tue Oct 27, 2009 2:26 pm

I guess I don't see that in the module. Also, when I try to login now, I'm getting this error message: "Fatal error: Unsupported operand types in /home1/stonewor/public_html/includes/router.php on line 148". Do you know what this means? I am extremely new to Joomly and website creation in general. Thanks in advance.

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

Re: User Specific Login Redirect

Postby ooffick » Tue Oct 27, 2009 2:46 pm

My guess would be that the Menu Item which you selected doesn't exist, or that the article which linked from the menu item doesn't exists anymore.

capture#0140_2009-10-27.png


Olaf
You do not have the required permissions to view the files attached to this post.
Olaf Offick - Global Moderator
http://learnskills.org

umccoy
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Thu Oct 22, 2009 4:34 pm

Re: User Specific Login Redirect

Postby umccoy » Tue Oct 27, 2009 2:50 pm

Why can't I see all of my articles under "Paremeters" in the mod_login, for "Login Redirection Page" and "Logout Redirection Page"? I'm trying to link these to a page that I created but they don't show up.

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

Re: User Specific Login Redirect

Postby ooffick » Tue Oct 27, 2009 2:56 pm

You can only select a menu item? Do you will need to create a menu item first.

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

umccoy
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Thu Oct 22, 2009 4:34 pm

Re: User Specific Login Redirect

Postby umccoy » Tue Oct 27, 2009 3:01 pm

What if I don't want that page to show up in my menu on the frontend? (It's for certain level employees only.)

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

Re: User Specific Login Redirect

Postby ooffick » Tue Oct 27, 2009 3:21 pm

Try to create a new menu, a new menu item, and don't link the menu with a module.

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

greg218
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Jan 03, 2008 2:16 pm

Re: User Specific Login Redirect

Postby greg218 » Thu Nov 05, 2009 11:20 pm

ok.... i have used the trick described in the first page. I now upgraded to 1.5.14 now when i create a new user and input a redirect url.... it doesn't redirect.

For some reason, the user that i did this trick with before the upgrade do redirect.

Can someone post their controller.php code or file plus their other modification to their other files (user.xml etc) to get this redirect working.

Thanks
~G

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

Re: User Specific Login Redirect

Postby ooffick » Thu Nov 05, 2009 11:26 pm

Did you change all the files again?

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

greg218
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Jan 03, 2008 2:16 pm

Re: User Specific Login Redirect

Postby greg218 » Fri Nov 06, 2009 12:26 am

no i didnt change the files again....

oooo i looked into the 1.5.7 to 1.5.14 update file and i see that controller.php gets replaced.

So im assuming i just modify controller.php with any of the hacks above?

Thanks,
~Greg

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

Re: User Specific Login Redirect

Postby ooffick » Fri Nov 06, 2009 9:32 am

greg218 wrote:So im assuming i just modify controller.php with any of the hacks above?


Yes, or any other file which might have been replaced.

Olaf
Olaf Offick - Global Moderator
http://learnskills.org

greg218
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Jan 03, 2008 2:16 pm

Re: User Specific Login Redirect

Postby greg218 » Fri Nov 06, 2009 3:13 pm

The joomla 1.5.14 controller.php looks different and i can't find

Code: Select all

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

Code: Select all

if (!$user->bind($post))
      {
         $mainframe->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
         $mainframe->enqueueMessage($user->getError(), 'error');
         //$mainframe->redirect( 'index.php?option=com_users', $user->getError() );
         //return false;
         return $this->execute('edit');
      }


Can someone show how you would do this hack in joomla 1.5.14?

Thanks!
~Greg

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

Re: User Specific Login Redirect

Postby ooffick » Fri Nov 06, 2009 3:32 pm

Hi Greg,

Please make sure you are looking in the /components/com_users/controller.php and not in the /administrator/components/com_users/controller.php file.

Try to find this:

Code: Select all

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

      //preform the login action
      $error = $mainframe->login($credentials, $options);

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

         $mainframe->redirect( $return );
      }


and replace it with this:

Code: Select all

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

      //preform the login action
      $error = $mainframe->login($credentials, $options);

      if(!JError::isError($error))
      {
         $user =& JFactory::getUser();
         $user->getParameters();
         if (!$user->getParam('url') == ''){
            $return = $user->getParam('url');
         }

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

         $mainframe->redirect( $return );
      }


Olaf
Olaf Offick - Global Moderator
http://learnskills.org

greg218
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Jan 03, 2008 2:16 pm

Re: User Specific Login Redirect

Postby greg218 » Fri Nov 06, 2009 4:43 pm

Thanks Olaf, It worked!

joomwork
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Sun Jun 04, 2006 10:25 pm

Re: User Specific Login Redirect

Postby joomwork » Wed Nov 11, 2009 9:22 pm

I wish to have some time, to create a generic plugin for this.
If anyone has already created one, please let me know.


Return to “Core Hacks and Patches”

Who is online

Users browsing this forum: No registered users and 0 guests