Sunday, July 11, 2010

Drupal: Redirecting user to specific page after login

Task:
After user logged in, redirect them to custom page (dashboard) rather than the default user account page in Drupal (user). For users with admin role, redirect to something like (admin/dashboard).

Modules available:-
So I proceed with implementing some custom code, copying the trick used in user.module which used menu_set_active_item('dashboard') and menu_execute_active_handler() to render a page for a given request. This work perfectly because it does not use redirect such as in login_destination which would stop script execution, causing some hook and code not fired as in the bug with Content Profile module. This however would only work for real path defined in hook_menu.

No comments: