Newer
Older
* Adds a "Remember me" checkbox to login forms.
function remember_me_init() {
global $user;
// If we have a user logged in, then we have a session.
// If the user chose to be remembered, recreate the session using the
// configured session timeout.
if (!empty($user->data['remember_me']) && variable_get('remember_me_managed', 0)) {
_remember_me_set_lifetime(variable_get('remember_me_lifetime', 604800));
/**
* remember_me_init() callback helper function.
*/
function _remember_me_set_lifetime($cookie_lifetime) {
// We have session started.
// Lets close the session, change php cookie lifetime variable, and start
// session again.
// Prevent sess_write from persisting the session object at this time,
// it will happen on shutdown.
drupal_save_session(FALSE);
session_write_close();
drupal_save_session(TRUE);
// Set the cookie and session lifetime. A cookie lifetime of 0 indicates that
// the cookie should expire when the browser is closed. The session lifetime
// controls how long the session can live on the server without any activity.
ini_set('session.cookie_lifetime', $cookie_lifetime);
if ($cookie_lifetime > 0) {
ini_set('session.gc_maxlifetime', $cookie_lifetime);
}
drupal_session_started(FALSE);
drupal_session_initialize();
* Implements hook_user_login().
function remember_me_user_login(&$edit, $account) {
if ($account->uid) {
Mohammad Abdul-Qader
committed
$account->data['remember_me'] = !empty($edit['input']['remember_me']);
Aram Boyajyan
committed
db_update('users')
->fields(['data' => serialize($account->data)])
->condition('uid', $account->uid)
->execute();
* Implements hook_form_alter().
function remember_me_form_alter(&$form, $form_state, $form_id) {
// Only make changes to these forms.
if (in_array($form_id, array('user_login', 'user_login_block'))) {
// Configuration for the remember me checkbox.
$cbox['remember_me'] = array(
'#title' => t('Remember me'),
'#type' => variable_get('remember_me_checkbox_visible', 1) ? 'checkbox' : 'hidden',
'#default_value' => variable_get('remember_me_checkbox', 1),
'#attributes' => array('tabindex' => 1),
);
Mohammad Abdul-Qader
committed
// Now lets try and insert it right after the password field in the document
// and set the tabindex to 1 for each field so that we can jump in sequence.
Aram Boyajyan
committed
foreach ($form as $key => $val) {
switch ($key) {
case 'name':
case 'pass' :
$val['#attributes']['tabindex'] = 1;
case 'actions':
$form = $que + $cbox + $form;
$form[$key]['submit']['#attributes']['tabindex'] = 1;
Mohammad Abdul-Qader
committed
}
Mohammad Abdul-Qader
committed
}
/**
* Implements hook_theme().
*/
function remember_me_theme() {
return array(
'remember_me_settings_display' => array(
'variables' => array('vars' => array()),
}
* Implements hook_menu().
$items = array();
$items['admin/config/system/remember_me'] = array(
'title' => 'Remember me settings',
'description' => 'Configure settings like session time out for remember_me module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('remember_me_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
return $items;
}
/**
* Implements hook_help().
function remember_me_help($path, $arg) {
switch ($path) {
case 'admin/help#remember_me':
return t('Allows users to have persistent sessions via a checkbox "Remember me" on the login form.');
}