Hi,

I was wondering how I would go about seting up drupal so that after logging in users of a certain role would be taken to their own blog, whilst users of another role would be taken to a different page, any pointers as to how to go about this?

Cheers

Comments

shyamala’s picture

You could use frontpage module, will allow different accessgroups to have different frontpage. Or you could right a code to redirect frontpage depending on the access control.

new features (Drupal 5.x and Drupal 4.7.x version of the module only)

* Specify a different front page based on Role. You can specify a special front page for each role type
* Display a custom mission statement for registered users who have not visited the site for a while You can specify the special mission and the 'time away' setting.

refer:http://drupal.org/project/front

Shyamala
Team Leader (http://www.netlinkindia.com)

shyamala’s picture

Could try Login Destination

This module controls where users go after logging in. You can configure login destination on a settings page. It will be either static URL or a PHP snippet evaluating your own site's logic. You can also configure which pages redirection is applied

http://drupal.org/node/137834

Shyamala
Team Leader (http://www.netlinkindia.com)

keirlawson’s picture

The login destination module seems to be exactly what i need! I got the URL destination PHP working fine, however I cant seem to get the redirection condition code working, it looks like:

global $user;
$candidate = false;
foreach ($user->roles as $roleid => $rolename)
{
    if (strtolower(trim($rolename)) == 'candidate')
    {
        $candidate = true;
        break;
    }
}
return $candidate;

Even if the users role is set to "candidate", it fails to redirect, any ideas?

kingandy’s picture

I'm trying the same thing and it's not redirecting conditionally for me either. My conditional code uses PHP's in_array() function to search though:

global $user;
return in_array('Ambassadors',$user->roles);

++Andy

kingandy’s picture

Ahh, and I think I've figured it out ... the conditional is evaluated when the user tries to log in, not after a successful login.

Try moving your PHP snippet into the 'URL Destination Code' settings and determining a URL based on the role, like so:

  global $user;
  if (in_array('Ambassador',$user->roles)) $path = 'ambassadors';
  else $path = 'user';
  return $path;

++Andy

Oddible-1’s picture

Thanks - this worked perfectly.

ashiwebi’s picture

global $user;
if (in_array('teacher',$user->roles))
{
return 'teacher'; //Page for teacher
}
elseif(in_array('student',$user->roles))
{
return 'student; //Page for student
}
elseif(in_array('parents',$user->roles))
{
return 'parents'; //Page for Parents
}
else
{
return 'home';
}

The above code is for different user with diferent role on the website.I have student,teacher,parents role.kingandy code help me to write this.Thnks kingandy. The login destination module depends on user only.

ishmael-sanchez’s picture

This works with Drupal 7 and login destination.

socialnicheguru’s picture

i have been having problems with this. thanks

Chris

http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.

Dubber Dan’s picture

I've been trying the different versions of code listed above with no luck. Have also tried the code at http://drupal.org/node/342858 but nothing does it.

My code currently is, or at least I did try, but got a validation error with is:

global $user;
if (in_array('Patient',$user->roles)) {
return 'node/99';
}
else if (in_array('Script Team',$user->roles)) {
return 'admin/user/user';
}
else if (in_array('Admin',$user->roles)) {
return 'admin';
}
else {
return 'practice-information';
}

So I'm stuck how to get this working.

Any suggestions?

Dubber Dan’s picture

Scrub that... Logged out and back in and checked the code and it's working when using:

global $user;
if (in_array('Script Team',$user->roles)) $path = 'admin/user/user';
elseif (in_array('Patient',$user->roles)) $path = 'node/99';
elseif (in_array('Admin',$user->roles)) $path = 'admin';
else $path = 'user';
return $path;
FranCarstens’s picture

This works perfectly, it should be added to the "login_destination.module" documentation or readme.

-- If no-one asked Drupal questions there would be no Drupal answers --

prateek_t2’s picture

This worked nicely

peterum’s picture

how can i get the user id in the path? i'm a php newbie... :(

i want sth like user/$userid/blog

peterum’s picture

got that working..but now, if a user registers and logs in for the first time, he wont be redirected to the edit account page to change his password. is there a way to make an extra rule for "first time login" and after that the other rules apply?

jaypan’s picture

A bit of shameless self-promotion, but you can use the Force Password Change module to force users to change their password on first time login. The way this module is set up should force the user to change their password regardless of the module you have set up.

...or it will cause an infinite loop. Depends on how you have set up the redirect. Try it out and see what happens.

Contact me to contract me for D7 -> D10/11 migrations.

nisith’s picture

You can use the module mentioned below to create separate login pages for different kind of roles.

These pages can have their own redirection set after login.

https://www.drupal.org/project/role_login_page