You are here

user_pwreset_timeout.module in User Password Reset Link Timeout 7

Same filename and directory in other branches
  1. 8 user_pwreset_timeout.module

File

user_pwreset_timeout.module
View source
<?php

/**
 * @file
 * user_pwreset_timeout.module
 */

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Add a settings to control the user password reset link timeout.
 *
 * @see user_admin_settings()
 */
function user_pwreset_timeout_form_user_admin_settings_alter(&$form, &$form_state) {
  $form['password_reset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Password reset'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#weight' => 1,
  );
  $form['password_reset']['user_password_reset_timeout'] = array(
    '#type' => 'textfield',
    '#title' => t('User Password Reset Link Timeout'),
    '#description' => t('Set the timeout in seconds for one-time login links. The default is 86400 seconds (24 hours).'),
    '#default_value' => variable_get('user_password_reset_timeout', 86400),
    '#size' => 10,
    '#maxlength' => 8,
  );

  // Sort the form so password_reset fits in the UI where it makes sense.
  $form['personalization']['#weight'] = 2;
  $form['email_title']['#weight'] = 3;
  $form['email']['#weight'] = 4;

  // Validation callback.
  $form['#validate'][] = 'user_pwreset_timeout_validate';
}

/**
 * Form validations for the user.
 */
function user_pwreset_timeout_validate($form, &$form_state) {

  // Check to make sure the user password reset timeout is an integer between 1
  // and 31536000 (1 year).
  if (!preg_match('/(?<=\\s|^)\\d+(?=\\s|$)/', $form_state['values']['user_password_reset_timeout']) || ($form_state['values']['user_password_reset_timeout'] < 1 || $form_state['values']['user_password_reset_timeout'] > 31536000)) {
    form_set_error('user_password_reset_timeout', t('User Password Reset Link Timeout must be an integer between 1 and 31536000.'));
  }
}

Functions