You are here

public function PasswordPolicyExpire::init in Password Policy 7.2

Checks on init if the user password has expired.

If the password has expired, we send the user to the user edit page until they set a new password.

File

plugins/item/expire.inc, line 198

Class

PasswordPolicyExpire
Policy item that handles password expirations.

Code

public function init($account) {

  // Do not do anything if expiration is disabled.
  $enabled = $this->config['expire_enabled'];
  if (!$enabled) {
    return;
  }

  // An expiration interval equal to zero means expiration is disabled.
  $expire_int = password_policy_parse_interval($this->config['expire_limit']);
  if (!$expire_int) {
    return;
  }

  // If this is a command line request (Drush, etc), skip processing.
  if (drupal_is_cli()) {
    return FALSE;
  }
  $stop = module_invoke_all('password_policy_expire_url_exclude', $account);
  if (!empty($stop)) {
    return FALSE;
  }

  // @TODO this should not be necessary
  password_policy_user_load(array(
    $account->uid => $account,
  ));
  if ($account->uid == 0) {
    return;
  }

  // If there is no password history, start one.
  if (!isset($account->password_history[0])) {
    $account->password_history[0] = (object) array(
      'uid' => $account->uid,
      'pass' => $account->pass,
      'created' => REQUEST_TIME,
      'is_generated' => FALSE,
    );
    password_policy_update_password_history($account->password_history[0]);
  }

  // Check to see that the password has expired.
  if ($account->password_history[0]->created + $expire_int < REQUEST_TIME) {

    // If we are on the check ajax page, then skip.
    if (current_path() != 'password_policy/check') {

      // If not on the password change page, go there.
      $password_change_path = $this
        ->getPasswordChangePath($account);
      if (current_path() != $password_change_path) {
        $this
          ->setExpiredWarningMessage();
        $this
          ->goToPasswordChangePath($account);
      }
    }
  }
}