You are here

function user_email_verification_verify_extended in User email verification 7

Menu callback; processes extended verification links. Enables and verifies accounts if user clicks the link within specified time period.

1 string reference to 'user_email_verification_verify_extended'
user_email_verification_menu in ./user_email_verification.module
Implements hook_menu().

File

./user_email_verification.admin.inc, line 79
Administrative functions required in a specific case.

Code

function user_email_verification_verify_extended($form, &$form_state, $uid, $timestamp, $hashed_pass) {

  // Time out, in seconds, until extended verification URL expires. Defaults to
  // 7 days which is 604800 seconds.
  $extended_timeout = variable_get('user_email_verification_extended_validate_interval', 604800);
  $current = REQUEST_TIME;

  // Some redundant checks for extra security ?
  $users = user_load_multiple(array(
    $uid,
  ), array(
    'status' => '0',
  ));
  if ($timestamp <= $current && ($account = reset($users))) {
    if ($current - $timestamp < $extended_timeout) {
      $verified = user_email_verification_load_verify_flag($account->uid);
      if (!$verified && $hashed_pass == user_email_verification_hmac($account->uid, $timestamp)) {
        db_update('user_email_verification')
          ->fields(array(
          'verified' => 1,
        ))
          ->condition('uid', $account->uid, '=')
          ->execute();

        // Activate blocked account
        $account->status = 1;
        user_save($account);
        if (module_exists('rules')) {

          // Invoke rules event
          rules_invoke_event('user_email_verification_verified_extended_before', $account);
        }
        drupal_set_message(t('Thank you for verifying your e-mail address. Your account is now activated and you may login.'));
        watchdog('user', 'User "%name" verified e-mail address "%email" using extended verification url.', array(
          '%name' => $account->name,
          '%email' => $account->mail,
        ));
        drupal_goto('user');
      }
    }
    else {

      // Basically this should never happend, because accounts are deleted
      // after the extended timout is reached, but it's possible depending
      // on cron configuration
      if (module_exists('rules')) {

        // Invoke rules event
        rules_invoke_event('user_email_verification_verified_extended_after', $uid);
      }
      drupal_set_message(t('Your verify link has been exipred and account has been deleted.'));
      watchdog('user', 'User tried to verify e-mail address with an expired link for uid: %uid.', array(
        '%uid' => $uid,
      ));
    }
  }
  else {
    if (module_exists('rules')) {

      // Invoke rules event
      rules_invoke_event('user_email_verification_verified_extended_after', $uid);
    }
    drupal_set_message(t('Your account does not exist anymore. Please register a new one, or contact site administration.'));
    watchdog('user', 'User tried to verify e-mail address for uid: %uid.', array(
      '%uid' => $uid,
    ));
  }
}