tags:

views:

122

answers:

4

Hi, I'm trying to redirect any logged user attempts to access /user. In my module I've the next code to redirect after login:

function ccmm_user($op, &$edit, &$account, &$category = NULL)
{
    switch($op){
     case 'login':
      $_REQUEST['destination'] = 'admin/';
      break;
    }
}

And this is working great.. then I try with case 'view': but it's useless :-/ why?

Any comment will be appreciated, thanks

A: 

You could try the Login Destination module rather than writing your own code.

Jeremy French
I don't want use another module, thx anyway
br1
A: 

If you're not familiar with the Login Toboggan module, you should be.

Sean McSomething
+1  A: 

It sounds like you want the user to never get to the /user page, whether on login or even by going there manually.

In that case you should do a simple check in a hook_init function like this:

function ccmm_init() {
  if ( $_REQUEST['q'] == '/user' ) {
    drupal_goto('/admin'); // Or where ever you want to send them
  }
}

Of course there are a lot of checks you should do, and you may want to look into using the Global Redirect module, don't worry it's only 8k in size so the concern about adding yet another module is not such a problem in this case.

alxp
I don't know why, but that example is not working on my drupal (D6)..Anyway, how users will to get login? (excuse my english :$)
br1
fixed, change $_REQUEST['q'] -> arg(0)
br1
A: 

A better way could be to use hook_menu_alter in your module to just remove the menu entry for /user/%user_uid_optional, or move it to another URL.

That way you won't only be handling just logins (as you currently do), but ANY access to /user/ (caveat: including those by the admin user). Or you could use the same hook to modify the access check and only grant it to users with higher permissions, like administer users

FGM