I am a newbie and really lost. I have several roles setup for users and I want to create a redirect page after login so that different splash pages are displayed depending on user role. What is the best way to make this happen?

Comments

ardas’s picture

Greetings,

The snippet will look like this:

  global $user;

  if (in_array('role1', $user->roles)) {

    // Redirect users will role1 role
    return 'role1-url';

  } elseif (in_array('role2', $user->roles)) {

    // Redirect users will role2 role
    return 'role2-url';

  } else {
    return 'default-url';
  }
ardas’s picture

Status: Active » Closed (fixed)
sander-martijn’s picture

Hi,

since this is probably the most logical way to use this module (role based over user based is always more maintainable unless each of your users have to do something completely different) it would be great to add this snippet to the main page.

wintervanilla’s picture

Title: Different User login destinations? » Should I use this Module?
Component: Miscellaneous » Code

I dont write PHP but I'd like to achieve the following functionality for a homepage:
- Logged in users with an account are forwarded to a dashboard-style page /user/dashboard
- Users without an account, or not logged in, are sent to the normal homepage.
- In the future, I may like to forward each role to a different url.

Can someone suggest a lower-brow module to achieve this. Or perhaps supply me with the snippets I need to achieve this with Login Destination?

Thanks!

wintervanilla’s picture

Component: Code » Miscellaneous
Status: Closed (fixed) » Active

I dont write PHP but I'd like to achieve the following functionality for a homepage:
- Logged in users with an account are forwarded to a dashboard-style page /user/dashboard
- Users without an account, or not logged in, are sent to the normal homepage.
- In the future, I may like to forward each role to a different url.

Can someone suggest a lower-brow module to achieve this. Or perhaps supply me with the snippets I need to achieve this with Login Destination?

Thanks!

iimitk’s picture

I couldn't agree more with the post above.

This is what I've downloaded this module for, and role-based login redirection is by far more important & useful than user-based redirection.

I, too, suggest that role-based redirection be built as the core functionality of this module. Particularly, the module's interface should be revised so as to populate the roles programmatically and enable admins to assign pages to them, instead of the PHP snippet method, which might confuse non-coders admins.

Edit: I'm sorry, just noticed this an old thread from an year ago. My suggestion is still viable though, as I'm using the latest D6 version and the functionality I've described applies to this newest version as well. :)

kenorb’s picture

There is 'front' module as well for set front page per role, but it's not working properly for me (tested on 6.x), but you can try it, you don't need to put any PHP code.

jimmb’s picture

Title: Add support for roles in the admin UI » Should I use this Module?
Version: 6.x-2.5 » 5.x-1.0
Category: feature » support
Priority: Minor » Normal
Status: Postponed » Active

+1

jimmb’s picture

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

It sure would be nice (and I assumed it was the case until installing/enabling it) that there would be checkboxes for each role, and you could choose which roles would experience the redirect when logging in.

Jim

p.s. - sorry for the double-post. I was trying to update it with my current version, 6.x-2.5.

rsvelko’s picture

Title: Should I use this Module? » Add support for roles in the admin UI
Version: 5.x-1.0 » 6.x-2.5
Category: support » feature
Priority: Normal » Minor
Status: Active » Postponed
wallbay1’s picture

Title: Should I use this Module? » Add support for roles in the admin UI
Category: support » feature
Priority: Normal » Minor
Status: Active » Postponed

subscribing

3cwebdev’s picture

I personally don't see a need for a user roles UI in the admin. You can easily add a PHP snippet in the condition and destination boxes to achieve this with a great deal of flexibility.

3cwebdev’s picture

Status: Postponed » Closed (won't fix)