Download & Extend

Redirect By Role & First Time Redirect By Role

Project:Login Destination
Version:6.x-2.8
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I'd like this feature implemented in logindestination:

1. The ability to redirect a user to a particular node depending on what role they belong to.
2. The ability to redirect a user to a particular node the first time they log in depending on the role they belong to.
Regards,
Raj

Comments

#1

I'd love to see #1 in Drupal 6 version.

#2

I'd also like to see #1 in the 6.x version. It's actually what I downloaded the module for.

#3

here is how to do it in both 5.x and 6.x (taken from: http://drupal.org/node/179981 ) :

paste this in the URL window of the login destination administration menu, having ticked the "PHP snippet option:

global $user;
if (in_array('special users', $user->roles)) {
    return 'node/5'; // Custom page for 'special users'
}
else {
    return '<front>'; //User does not have 'special users' role.
}

replace special user with the role name
replace node/5 with your desired url

copy paste this:

if (in_array('special users', $user->roles)) {
    return 'node/5'; // Custom page for 'special users'
}

for all the roles you want to give special redirections to

"thank you drupal community!!!"

/reSet Sakrecoer the hyper-n00b

#4

OK - looking at the examples means I'm learning about how this code snippet thing works. Can you very helpful guys point me in the right dorection for working out what I want to do....

Basically I want to redirect based on weather the user has filled in their profile (which uses the content profile module). If they have then I want to go to a particular node so I return 'node/42' ... that's cool. It is how to test for if the profile node exists that I am stuck on. Any tips would be appreciated (or even a snippet that you use and work to do the same thing)

Many thanks

#5

Hey guys - any idea on the second issue Raj has pointed?

2. The ability to redirect a user to a particular node the first time they log in depending on the role they belong to.

I can't seem to find how to do this...

#6

It does not work for names with non-latin characters.I tried to replace role name with role ID but no success :(

Please help :)

#7

volocuga: i've noticed multiple issues with non-latin characters in roles, i found it's always best to stick with the latin chars...

#8

Awesome! Perfect!

Thanks!

#9

Thanks guys, I got this working on my site:

global $user;
if (in_array('customer', $user->roles)) {
    return 'down-uploads'; // Custom page for 'customers'
}
elseif (in_array('editor', $user->roles)) {
  return 'node/add'; // Page for 'editors'
}
elseif (in_array('partner', $user->roles)) {
  return 'partner'; // Page for 'partners'
}
else {
    return '<front>'; //User does not have 'special users' role.
}

#10

Version:5.x-1.0» 6.x-2.8

I entered the following code into the "Redirection conditions" PHP snippet area.
global $user;
if (in_array('school admin', $user->roles)) {
return 'user'; // Custom page for 'school admin'
}
if (in_array('editor', $user->roles)) {
return 'user'; // Page for 'editor'
}
if (in_array('student', $user->roles)) {
return 'games'; // Page for 'student'
}
else {
return ''; //User does not have 'special users' role.
}

---
"Destination URL settings" only has "Static URL" checked, no other code is entered. Should something be here too?

I recieve the following message after saving configuration:
Your settings: (double-check them)
[ld_url_type] => 'static'
[ld_url_destination] => ''

nobody click here