The Joomla! Forum ™





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 131 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
PostPosted: Wed Dec 20, 2006 4:59 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Fri Aug 19, 2005 12:52 pm
Posts: 76
Location: Nyack, NY
I wanted the ability to redirect specific users to a section or page of my site when they logged in.  I created this simple hack so that the administrator can add a specific Login and Logout Rediect for each user in the User Manager.  If no redirect is defined for the user then the login/logout checks to see if you've defined a rediect in the module.  This simple hack works like a charm on Joomla 1.0.11 with OpenSEF installled.  I've not tested it in conjunction with community builder.

Here is the Hack:

First Backup Your Files!

Step 1)

open file: /administrator/components/com_users/users.xml

after line 13 where you see this:
Code:
<param name="editor" type="editor_list" default="" label="User Editor" description="WYSYWYG Editor for this User" />


add this:
Code:
<param name="login" type="text" 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="text" default="" label="Logout Redirection URL" description="What page will the login redirect to after user logout, if let blank will load module default" />


Save the file.


Step 2)

open file index.php

around line #139 replace:
Code:
$mainframe->login();


with this:
Code:
        $mainframe->login();

        // Per User Redirection
        $temp_my = $mainframe->getUser();
        $params = new mosParameters( $temp_my->params );
        $userRedirect = $params->get( 'login', '' );
        if ($userRedirect) {
           $return = sefRelToAbs( $userRedirect );
        }
        $temp_my = '';



around line #168 replace this:
Code:
$mainframe->logout();


with this:
Code:
         // Per User Redirection
        $temp_my = $mainframe->getUser();
        $params = new mosParameters( $temp_my->params );
        $userRedirect = $params->get( 'logout', '' );
        if ($userRedirect) {
        $return = sefRelToAbs( $userRedirect );
        }
        $temp_my = '';

        $mainframe->logout();



Save the File.
And you're done!

Notes:
Now you can login to the Administrator end and set the individual redirects in the user manager.

Warning:
If you don't want the frontend users to be able to edit these redirects then you need to set the Frontend User Params: to NO in your Global Configuration.

Enjoy
-barnett

_________________
http://www.contemplatedesign.com/ - Joomla Development & Design


Top
 Profile  
 
PostPosted: Mon Feb 19, 2007 9:31 pm 
Joomla! Explorer
Joomla! Explorer

Joined: Sat Sep 16, 2006 8:50 pm
Posts: 271
Location: San Antonio, Texas
just what i was looking for...

works like a charm thanks!  :)

just on another note any ideas how i would get this to work with CB community Builders Login?? Thanks again! :)


Last edited by sa247 on Mon Feb 19, 2007 9:43 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Wed Mar 21, 2007 2:38 pm 
Joomla! Intern
Joomla! Intern

Joined: Sun Aug 28, 2005 11:27 pm
Posts: 92
I also would like to know how to do this with the community builder login!

Cause what I would like to do is to have them automatically go to their profile when they login.

If anyone knows how to do this,  please let me know!


Thanks AHEAD!


Last edited by Klaas Koopman on Wed Mar 21, 2007 2:41 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Wed Mar 28, 2007 11:02 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Dec 22, 2006 3:04 pm
Posts: 9
Check out the parameters for the log-in module - there is a place to specify a redirect on log-in or log-out.


Top
 Profile  
 
PostPosted: Thu Sep 27, 2007 11:49 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Dec 22, 2006 3:04 pm
Posts: 9
This used to work like a charm. Now that I've upgraded to 1.0.13 it no longer functions.

Do you have an update to this?

=============RESOLVED===============================

My bad  :-[ - it works just fine, I was looking in the wrong place!


Last edited by mdmen on Sun Sep 30, 2007 11:41 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sun Nov 11, 2007 10:58 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sat Nov 10, 2007 7:26 pm
Posts: 1
Excellent hack, I had a client who didn't understand the urls for Joomla so hacked a little more to get them a drop down list to select each page from. This was accomplished by changing the

type="text"

to

type="page_list" in the xml file.

adding in a method/function to the user.class.php -

function _form_page_list( $name, $value, &$node, $control_name ) {
global $database;

// compile list of the pages
$query = "SELECT id AS value, title AS text FROM jos_content"
;
$database->setQuery( $query );
$editors = $database->loadObjectList();

array_unshift( $editors, mosHTML::makeOption( '', '- Select Page -' ) );

return mosHTML::selectList( $editors, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value );
}

and then changing the redirects to

$return = sefRelToAbs( "index.php?option=com_content&task=view&id=".$userRedirect."&Itemid=".$userRedirect );

Sorted it for them. It's limited in that you can't pick menus, however, for their site it was ideal. I've documented the hack here -

http://www.econcepts.co.uk/joomla-specific-page-for-specific-user.php


Top
 Profile  
 
PostPosted: Tue Nov 20, 2007 1:56 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Feb 22, 2006 6:41 pm
Posts: 32
I tried to modify this hack to allow selection of menu items, and I'm hung up on a small technicality. The problem is in the $url variable. When I comment out ."&Itemid=".$page (leaving only $redirect;) it "almost" works, but in order to load the right page, it needs the Itemid.

Code:
function _form_page_list( $name, $value, &$node, $control_name ) {
global $database;
// compile list of the pages
$query = "SELECT link AS value, name AS text, id AS page FROM quiz_menu WHERE published=1 AND type='wrapper'";
$database->setQuery( $query );
$redirect = $database->loadObjectList();
array_unshift( $redirect, mosHTML::makeOption( '', '- Select Page -' ) );
$url = $redirect."&Itemid=".$page;
return mosHTML::selectList( $url, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value );
}


In index.php, I adjusted line 136 to say
Code:
$return = sefRelToAbs( $userRedirect );


I'm sure my problem has to do with my lack of knowledge about mosHTML:selectList. Can anybody think of a way to make this work?


Top
 Profile  
 
PostPosted: Wed Nov 21, 2007 11:40 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Feb 22, 2006 6:41 pm
Posts: 32
Yeah! Got it working.

Changed the query a little bit

Code:
$query = "SELECT id AS value, name AS text FROM quiz_menu WHERE published=1 AND type='wrapper'";


and changed index.php a little bit

Code:
$return = sefRelToAbs( "index.php?option=com_wrapper&Itemid=".$userRedirect );


And now it's doing what I wanted.  ;D


Top
 Profile  
 
PostPosted: Tue Jun 24, 2008 3:03 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Oct 10, 2006 12:19 pm
Posts: 6
Does anyone know if this hack works with 1.0.15?


Top
 Profile  
 
PostPosted: Wed Jul 30, 2008 2:31 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Jul 30, 2008 2:27 pm
Posts: 1
I don't know if this hack works with 1.0.15, but if you are using Community Builder, there is a more 'elegant' solution.

I recently wrote a Joomla! component/CB Plugin that will let you redirect a user upon login based on their user group.

You can download the Documentation/Install package at KeithsCode.com.

Using the component, you can setup different redirections for different user groups, set expirations for the redirection, choose to only redirect the user once (if you have a special announcement or something), and set the priority for the redirection in relation to other redirections that have been setup ...

This way you won't have to make modifications to any of the core files, and you can specify redirects for groups of users rather than each user individually.

Hope This Helps ...


Top
 Profile  
 
PostPosted: Wed Aug 20, 2008 2:53 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Aug 06, 2008 3:24 pm
Posts: 26
Anything like this for 1.5.6? Or will this work as is?

I am looking for a user specific redirect on login facility. Not really interested in redirecting according to user group, although Keith's offering looks good.

Thanks,

Ian . . .


Top
 Profile  
 
PostPosted: Thu Oct 23, 2008 3:01 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Jun 25, 2008 2:24 pm
Posts: 39
This is so close to what I need, and what I need seems so logical, but I can not find a way to do it. Maybe you can help, or maybe this will do it but I can't determine how.

When a user clicks on an article link and is directed to the CB Login I would like them to be sent to the article they were attempting to view upon successful login. Is there a way to accomplish this?

I am running Joomla 1.5.6 - so if your add on will help me I will be anxiously awaiting the next version.


Top
 Profile  
 
PostPosted: Fri Oct 24, 2008 6:42 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Aug 06, 2008 3:24 pm
Posts: 26
I haven't been able to find a solution so I have now added a menu item that links to a Simple Machines Forum which I have customised to meet my requirements. Clients have their own unique board that only they can see when they use the SMF login.

Not ideal, but it gets me 75% of what I wanted. I would have preferred to remain in Joomla, though. :(


Top
 Profile  
 
PostPosted: Sat Nov 08, 2008 10:19 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Oct 06, 2008 3:45 pm
Posts: 34
This looks like what i want too for Joomla 1.5.6, but dont really know where to look for files with the right code to start with this in the new version of Joomla.

The files are different than what was first posted in this topic by barnett..

The first xml file to change seems now to be:
/administrator/components/com_users/models/user.xml

as for the index.php i have no idea... can somebody help out? And by the way, would this code still be valid for the new Joomla version?

thanks


Top
 Profile  
 
PostPosted: Wed Dec 24, 2008 4:42 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Dec 03, 2008 9:25 am
Posts: 16
Couldn't find any solution for this with extensions, modules or hack for 1.5.x

anybody - any luck?


Top
 Profile  
 
PostPosted: Wed Dec 24, 2008 8:43 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Aug 06, 2008 3:24 pm
Posts: 26
Am I right in thinking that this is going to be a feature of 1.6? If so, I imagine there wouldn't be many developers wanting to spend time putting together an extension that would only have a short shelf life.


Top
 Profile  
 
PostPosted: Sun Jan 25, 2009 7:58 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sun Jan 25, 2009 7:09 pm
Posts: 1
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:
<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:
$error = $mainframe->login($credentials, $options);

add the following code:
Code:
$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:
   function logout()
   {
      global $mainframe;

add:
Code:
$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:
      if(!JError::isError($error))
      {

add:
Code:
if (!$return)

one line before the next if.

4. Set up individual user login and logout redirections from the user manager.


Top
 Profile  
 
PostPosted: Fri Jan 30, 2009 12:00 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Jan 29, 2009 11:49 pm
Posts: 2
Location: UK
Qwomg, if that works (and I will try tonight) then thank you!
videoIT wrote:
Am I right in thinking that this is going to be a feature of 1.6? If so, I imagine there wouldn't be many developers wanting to spend time putting together an extension that would only have a short shelf life.

I hope it will be a feature, its seems like such a simple thing (to someone that knows very little about programming :-[ ) but, it's something I personally want to use on my sites.


Top
 Profile  
 
PostPosted: Thu Mar 05, 2009 5:43 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Feb 12, 2009 9:45 am
Posts: 3
Thanks Qwomg and @barnett!

Your modifications did almost exactly what I wanted. But I would like the menu to expand as well, and have the breadcrumbs reflect the menu choice. I added an Itemid to the url, and that seems to work. See below.

Qwomg wrote:
Instructions for Joomla 1.5(.8 ) (with credit @barnett):
...
2. Go to components/com_user/controller.php and after line ~134:
Code:
$error = $mainframe->login($credentials, $options);

add the following code:
Code:
$user =& JFactory::getUser();
$menu =& JSite::getMenu();
$userRedirect = $user->getParam('login');
if ($userRedirect) {
        $item = $menu->getItem($userRedirect);
   $url = $item->link; // <---- Here
        $return = $url;
}

...


Itemid to make the menu expand:

Code:
   $url = $item->link [b]. "&Itemid=" . $userRedirect[/b];


Same thing with the logout.


Top
 Profile  
 
PostPosted: Sat Mar 28, 2009 6:09 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 14, 2009 10:42 pm
Posts: 34
Location: Houston TX, USA
I used Qwomg's instructions to set this up in Joomla! 1.5.9 and it seems to be working. I still need to do some more testing though.

components/com_user/controller.php appears to have had some changes made since v1.5.8 and this has changed the line numbers that Qwomg referenced.
I found the contents indicated for line 134 are now at 144 and line 160 at 167.

My thanks to barnett and everyone else who has contributed.


Top
 Profile  
 
PostPosted: Sun Mar 29, 2009 4:00 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 14, 2009 10:42 pm
Posts: 34
Location: Houston TX, USA
Note: In components/com_user/controller.php on lines 184 to 186 (for Joomla! 1.5.9) the code that executes the user redirect on logout seems to reject any target url with 'com_user' as one of the variables.
Code:
if ( $return && !( strpos( $return, 'com_user' )) ) {
$mainframe->redirect( $return );}


This had me scratching my head for a little while.


Top
 Profile  
 
PostPosted: Sun Apr 12, 2009 11:41 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Mar 16, 2008 11:25 pm
Posts: 16
This is a truly fantastic thread. I have got everything working as described. I would like to add more though.

Where are the default settings for login/logout redirection? Is it possible to add selection boxes to the global configuration page for defaults, just like we added them for the individual users?

Jason


Top
 Profile  
 
PostPosted: Mon Apr 13, 2009 4:30 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 14, 2009 10:42 pm
Posts: 34
Location: Houston TX, USA
mtlhead wrote:
Where are the default settings for login/logout redirection?
Good idea, lucky for you I came across a docs page recently that should help, lucky for me you thought of it because it solves a usability issue that's been nagging at the back of my brain.

http://docs.joomla.org/Tutorial:Template_parameters#Menuitem_parameter_type

Just find the item ID of the menu item you want and add it to the parameters that you created in the administrator/com_users/models files, they should already contain default=""
mtlhead wrote:
Is it possible to add selection boxes to the global configuration page for defaults, just like we added them for the individual users?
I'm not sure how to accomplish this.


Top
 Profile  
 
PostPosted: Mon Apr 13, 2009 6:24 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun May 06, 2007 9:40 pm
Posts: 8
Here's an interesting observation. In Joomla 1.5.9 if you want to set the redirection after login from 'Default Login Layout - parameters' do not use the full URL string. Example:

The full string doesn't work
- http://www.yourdomain.com/index.php?opt ... 7&Itemid=2

Just use the internal link within 'Login Redirection URL'
- index.php?option=com_content&view=article&id=47&Itemid=2


The login redirection will now work. If your using login SSL the redirection page will still show HTTPS until you click away to a menu item with SSL 'off'.


Top
 Profile  
 
PostPosted: Thu Apr 16, 2009 10:29 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Mar 16, 2008 11:25 pm
Posts: 16
I've given up on my additions. I was able to get a frame on the config page but no listboxes. It seemed to be getting heavy into core files. Rather I will set my defaults in the code.

I will also probably prepare a whitepaper suggestion to the Joomla architects for a future release.


Top
 Profile  
 
PostPosted: Sat May 30, 2009 7:15 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sat May 30, 2009 7:13 am
Posts: 1
after login --- to redirect the user back to the page which the user was trying to access --
--------------------------------------------------------------------
file 1: components/com_login/login.html.php
<input name="redirect" type="hidden" value="<?php
$url= $_SERVER['QUERY_STRING'];
$url = str_replace('option=com_login&', 'f', $url);
$url = str_replace('prop=admin', '', $url); // replace the name of the module with what you have
$url = substr_replace($url, 'index.php?', 0, 0);
echo $url ?>"/>


file 2:
if you have some user integration module in your component
inside the login handler
$_POST['redirect'] = $_POST['redirect'];
before calling $mainframe->login( )

AND finally file 3:
in includes/joomla.php - in login function
find the following 2 lines
$username = stripslashes( strval( mosGetParam( $_POST, 'username', '' ) ) );
$passwd = stripslashes( strval( mosGetParam( $_POST, 'passwd', '' ) ) );
and add this 3rd one
$redirect = stripslashes( strval( mosGetParam( $_POST, 'redirect', '' ) ) );


and then towards the bottom of that function
find the following line
mosCache::cleanCache();
add the following line after that
mosRedirect($redirect);

and thats it.

So now when you go to any page in your component that needs user login --- after login the user will be sent back to the correct page


Top
 Profile  
 
PostPosted: Tue Jun 02, 2009 11:20 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Mar 16, 2008 11:25 pm
Posts: 16
Thanks for the post ruralIndia. However:

file1 - I do not have
file3 - I have but only contains an include function for the application.php file. The application.php file does not have the lines specified

Are you using version 1.0 or 1.5?


Top
 Profile  
 
PostPosted: Wed Aug 05, 2009 6:30 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Jul 22, 2009 4:09 pm
Posts: 13
Hi,

I am running Joomla 1.5.11. I have tried to insert this code. When I put specific redirects in the user manager, it still directs me to the wrong page. The screen when you setup the default login still shows the fields for login/out redirects. I am assuming it is still calling those fields. I can't seem to find what I need to change... I could really use some help! It would be greatly appreciated!

Thanks


Top
 Profile  
 
PostPosted: Wed Aug 05, 2009 4:42 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Jul 06, 2009 8:45 pm
Posts: 32
I had gone through this issue and finally found a solution with the help of Olaf. Are you looking for redirecting specific users to specific urls? then it is easy.

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....

<param name="url" type="text" default="" label="url" description="url" />

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

<param name="url" type="text" default="" label="url" description="url" />

2 After this go to components/com_user/controller.php...after line 146???

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

change the code like this...

{
$user =& JFactory::getUser();
$user->getParameters();
$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 );
}
else

The only changehere is that you have added

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

Now when you create a user using User Manager , specify the url in the ' url ' field. If you want to edit later you can do that also. once you do this when the user logins it automtically redirects the user to the specific 'url' in the user profile.

May be I have been more elaborate than normal...

Raj


Top
 Profile  
 
PostPosted: Tue Sep 01, 2009 8:11 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Sep 01, 2009 8:05 am
Posts: 5
Hey sraj49!

Your hack works great! Here's the added redirect hack for the backend login:

/administrator/components/com_login/admin.login.php

Approximately Line 66???

Change this:

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

To this:

$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);
}


Last edited by iamwaggle on Tue Sep 01, 2009 4:06 pm, edited 1 time in total.

Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 131 posts ]  Go to page 1, 2, 3, 4, 5  Next



Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group