use hook_user() $op = login to add data to $user object ?
| Project: | Pubcookie |
| Version: | 6.x-1.2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
How can I add custom data to the $user object on login, regardless of whether the user logs in via the local Drupal form or is inserted/logged in via the pubcookie module?
I've got a module that makes use of hook_user() to add a small amount of data to the $user object on login. It works great when logging in via Drupal's login form. However, when a user that
1) has a valid pubcookie ID,
2) AND has no record in local Drupal
logs in with pubcookie, the hook_user() doesn't seem to get called. Looking at the pubcookie module code it seems that the user record is inserted via db_query at line 198? Does that bypass the "insert" and "login" values of the $op parameter in hook_user() ?
My preference is to do this on login, so the performance hit is small and infrequent.
Oh, by the way, thanks for writing this module and the "custom redirect" patch. Aside from my custom needs, it's been wonderful to work with 8^)
-James

#1
Ok, I've got a cheesy workaround that involves a "Welcome new NetID user" page and has the user click on a link that adds the custom data to the $user object.
I'd love to have a better way to accomplish this, but deadlines are looming and this works...*sigh* oh well.
#2
James, I think you ought to be able to do this easily with the standard user hook, on the insert op.
1. A new user has been authenticated and is going to be created (pubcookie.module lines 106 and 107).
2. user_external_login_register() calls user_save('', $userinfo) (user.module line 1413).
3. user_save creates the user record (user.module line 290 and following).
4. After the user record has been created, user_save() calls user_module_invoke('insert', $array, $user, $category) (user.module line 338).
Now's your chance! Implement yourmodulename_user() and catch the 'insert' op. Any data added to the $array will be saved in the user data field since $array is passed by reference. See user.module line 340 and following.
Note that the pubcookie module takes advantage of this same mechanism to manipulate the user's database row itself (pubcookie.module lines 137 and following).