| 7 user.api.php | hook_user_login(&$edit, $account) |
| 8 user.api.php | hook_user_login(&$edit, $account) |
The user just logged in.
Parameters
$edit: The array of form values submitted by the user.
$account: The user object on which the operation was just performed.
Related topics
4 functions implement hook_user_login()
1 invocation of hook_user_login()
File
- modules/
user/ user.api.php, line 292 - Hooks provided by the User module.
Code
function hook_user_login(&$edit, $account) {
// If the user has a NULL time zone, notify them to set a time zone.
if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) {
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
}
}
Login or register to post comments
Comments
Does this hook effect on user
Does this hook effect on user access the site?
As users may be always login.
Redirecting users on login
You can use this hook to redirect users to a different page on login, but you will have to make sure the password reset functionality is not impaired.
Here how the Login Destination module does it:
<?php/**
* Implements hook_user_login
*/
function login_destination_user_login(&$edit, $account) {
if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset' || variable_get('login_destination_immediate_redirect', FALSE)) {
login_destination_perform_redirect('login');
}
}
?>
Without Login Destination module
@pfrenssen: can you elaborate on impairing password reset functionality?
The next lines of code seem to work for me on Drupal 7.12, without the use of the Login Destination module:
<?phpfunction hook_user_login(&$edit, $account) {
$edit['redirect'] = 'node/123';
}
?>
Works for both regular login page and login forms loaded through
drupal_get_form('user_login'). The user login block redirects to the page the user logged on to.pfrenssen's comment is
pfrenssen's comment is actually very valuable, as it also checks to see if the user is not currently using a one-time link to reset his password.
Here's a piece of code that I use:
<?php
function mymodule_user_login(&$edit, $account)
{
// Your logic will set $redirection to the desired location
$redirection = 'node/394';
// Unless there is already a redirection going, or the user is trying to reset his password, we redirect to $redirection.
if (empty($_GET['destination'])
&& !is_null($redirection)
&& (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset'))
{
$_GET['destination'] = $redirection; // Should we use $edit['redirect'] instead..?
}
}
?>