Posted by enboig on January 10, 2012 at 1:12pm
3 followers
Jump to:
| Project: | Masquerade |
| Version: | 6.x-1.7 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
I have coded a module which uses hook_user at login to set some user variables. When using masquerade to switch user, hook_user is not called and my variables are not set.
I think a "hook_user('load', $new_account)" call whould be the solution.
Comments
#1
Yes, this would be great. I have some rules that set user roles at login depending on various conditions, and to check how it all works via masquerade simulating user login is needed. Obviously, hook_user('login') should be called somewhere.
#2
@enboig and @gease I am interested in your use of login and rules for possible use in http://drupal.org/node/1416136. The second login has to get all the roles assigned to the fist login. I am looking at custom code. hook_user and/or Rules might be a cleaner way to do things.
#3
At hook_boot() I check global $user->uid versus $_SESSION['my_old_uid']; if its different, I reload anything I need and update $_SESSION['my_old_uid'].
function my_module_boot() {global $user;
if ($user->uid <> $_SESSION['mymodule_old_uid']) {
//my code to reload data
$_SESSION['mymodule_old_uid']=$user->uid;
}
}
#4
Sounds like your code would have to run after everything else that modifies the user. For my use, it would be something like:
$old = load user $_SESSION['mymodule_old_uid']
$user->roles = array_merge($user->roles, $old->roles);