7

We have certain users in our member list that have a role "vendor" attached to them. All such members are to be redirected to a certain page upon login. How can this be accomplished?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169
  • Warning! Redirecting users after log in can have strange and definitely unwanted effects! http://drupal.org/node/1772880 – lumbric Dec 14 '12 at 23:56

9 Answers9

11

There is more than one way to skin this cat... This is my preferred Drupal 7 method:

function hook_user_login(&$edit, $account) {
  $edit['redirect'] = 'node/123';
}
Felix Eve
  • 3,811
  • 3
  • 40
  • 50
6

For Drupal 7

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

then enable your trigger module

Trigger --> /admin/structure/trigger/node

if your are trying to login redirect just follow this(select user tab in the page)

go to --> admin/structure/trigger/user

then Trigger: After a user has logged in

choose an action -->Redirect to URL and assign.

Then clear the cache.

It will work for you!

Harikrishnan
  • 61
  • 1
  • 2
4

You can use Rules

Events: User has logged in.
Condition: User has role
Actions: Page redirect

milkovsky
  • 8,772
  • 4
  • 28
  • 32
4

You can define actions and triggers in Drupal:

Action(admin/settings/actions) - Redirect to a specific page

Trigger (admin/build/trigger/user) - After user has logged in

Try this.

EDIT (see comments):

Create a small module to check on a user's login process what role he has and then redirect if neccesary. drupal_goto => redirect-function in drupal

hook_user =>triggers on user operations

And for the user's roles:

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

$vendor then holds a true/false value will decide to redirect or not.

If you don't know how to do this, just post here and I'll write the module for you. But this would be a good practice for writing future drupa modules for you perhaps. :)

Rakward
  • 1,657
  • 2
  • 18
  • 24
  • 1
    That's going to redirect all users, not ones with a specific role. – Dave Reid Aug 07 '10 at 16:03
  • Ah, I didn't read the question properly, my bad. You can create a small module then and use hook_user with $op = login, check the user's role and then do a redirect perhaps? – Rakward Aug 07 '10 at 16:33
4

There are 2 ways in DRUPAL 7

1) Using action and trigger see this http://drupal.org/node/298506

2)if using 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; 

} 

}
EdChum
  • 376,765
  • 198
  • 813
  • 562
VinodC
  • 41
  • 4
2

following condition for hook_user

if($op =='login') drupal_goto("your path");
j0k
  • 22,600
  • 28
  • 79
  • 90
mayur
  • 21
  • 1
2

There are modules that do this (besides Trigger+Actions), such as LoginDestination: http://drupal.org/project/login_destination. This Drupal forum post has a bit more info about it as well.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
1

This can be achieved by using a combination of content access and login toboggan modules. You'll be able to restrict pages and prompt user to login to access them.

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
1

First set the conditions in form preprocess (for example I want to redirect only users that logged in using the form at node 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();
    }

}

than define redirect:

function YOURMODULE_user_login(&$edit, $account)
{
    if (isset($edit['nodepath']) && !empty($edit['nodepath'])) {
        drupal_goto($edit['nodepath']);
    }
}
VikDru
  • 32
  • 4