How to redirect the user to a specific page after logging in, if they belong to a certain role?

We have specific users in our list of members who have the "supplier" role to them. All such members must be redirected to a specific page upon login. How can I do that?

+7
drupal drupal-6 drupal-modules drupal-fapi drupal-forms
source share
9 answers

You can define actions and triggers in Drupal:

Action ( Admin / Settings / Actions ) - Redirect to a specific page

Trigger ( admin / build / trigger / user ) - After a user logs in

Try it.

EDIT (see comments):

Create a small module to check the login process, what role it has, and then redirect if necessary. drupal_goto => redirection function in drupal

hook_user => triggers in user operations

And for user roles:

GLOBAL $user; $roles = $user->roles; $vendor = in_array('vendor', $roles); 

$ vendor then contains a true / false value that decides whether to redirect or not.

If you do not know how to do this, just write here and I will write you a module. But it would be good practice to write future drupa modules for you, maybe. :)

+4
source share

There are several ways to trick this cat ... This is my preferred Drupal 7 method:

 function hook_user_login(&$edit, $account) { $edit['redirect'] = 'node/123'; } 
+11
source share

For Drupal 7

Action -> admin / config / system / actions - Redirect to URL

then turn on your trigger module

Trigger -> / admin / structure / trigger / node

if you are trying to redirect login, just follow this example (select the user tab on the page)

go to → admin / structure / trigger / user

then Trigger: after user login

select action → Redirect to URL and assign.

Then clear the cache.

This will work for you!

+6
source share

There are 2 ways in DRUPAL 7

1) Use of action and trigger see http://drupal.org/node/298506

2) when using a custom module

 function YOURMODULE_user_login(&$edit, $account) { if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset' || variable_get('login_destination_immediate_redirect', FALSE)) { if(in_array('THE-ROLE-WANTED-TO-REDIRECT',$account->roles)): drupal_goto('PATH'); else: drupal_goto('user/'.$account->uid); endif; } } 
+4
source share

You can use rules

Events: User logged in.
Status: User has a role
Actions: page redirection

+4
source share

There are modules that do this (besides Trigger + Actions), for example LoginDestination: http://drupal.org/project/login_destination . This Drupal forum post contains a bit more information about this.

+2
source share

following condition for hook_user

 if($op =='login') drupal_goto("your path"); 
+2
source share

This can be achieved with a combination of content access and tobogang login . You can restrict access to them and invite users to enter the system.

+1
source share

First, set the conditions for preprocessing the form (for example, I want to redirect only users who are logged in using the form on the site page)

 function YOURMODULE_form_user_login_alter(&$form, &$form_state, $form_id) { $pathArguments = explode('/', current_path()); if (count($pathArguments) == 2 && $pathArguments[0] === 'node' && is_numeric($pathArguments[1])) { $form_state['nodepath'] = current_path(); } } 

how to determine a redirect:

 function YOURMODULE_user_login(&$edit, $account) { if (isset($edit['nodepath']) && !empty($edit['nodepath'])) { drupal_goto($edit['nodepath']); } } 
0
source share

All Articles