You are here

function user_email_verification_verify in User email verification 7

Menu callback; process one time login link and redirects to the user page on success.

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

File

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

Code

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

  // Time out, in seconds, until login URL expires. Defaults to 24 hours =
  // 86400 seconds.
  $timeout = variable_get('user_email_verification_validate_interval', 86400);
  $current = REQUEST_TIME;

  // Some redundant checks for extra security ?
  $users = user_load_multiple(array(
    $uid,
  ), array(
    'status' => '1',
  ));
  if ($timestamp <= $current && ($account = reset($users))) {

    // No time out for first time login.
    if ($current - $timestamp > $timeout) {
      drupal_set_message(t('You have tried to use a one-time verify link that has expired. Please request a new one using the form below.'));
      drupal_goto('user/password');
    }
    elseif ($account->uid) {
      $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();
        if (module_exists('rules')) {

          // Invoke rules event
          rules_invoke_event('user_email_verification_verified_email', $account);
        }
        drupal_set_message(t('Thank you for verifying your e-mail address.'));
        watchdog('user', 'User "%name" verified e-mail address "%email".', array(
          '%name' => $account->name,
          '%email' => $account->mail,
        ));
        if ($account->status == 0) {
          global $language;
          if (module_exists('rules')) {

            // Invoke rules event
            rules_invoke_event('user_email_verification_verified_blocked', $account);
          }
          drupal_mail('user_email_verification', 'verify_blocked', variable_get('site_mail', ''), $language, array(
            'account' => $account,
          ));
          drupal_set_message(t('Your account has been blocked before the verification of the e-mail. ' . 'An administrator will make an audit and unblock your account if the reason for the blocking was the e-mail verification.'));
        }
        drupal_goto('user');
      }
      else {
        drupal_set_message(t('You have tried to use a one-time verify link that has either been used or is no longer valid. Please request a new one using the form below.'));
        drupal_goto('user/verify');
      }
    }
    else {
      drupal_set_message(t('You have tried to use a one-time verify link that has either been used or is no longer valid. Please request a new one using the form below.'));
      drupal_goto('user/verify');
    }
  }
  else {

    // Deny access, no more clues.
    // Everything will be in the watchdog's URL for the administrator to check.
    drupal_access_denied();
    drupal_exit();
  }
}