You are here

function password_policy_password_tab_exit in Password Policy 6

Implements hook_exit().

This function acts on a drupal_goto from user_pass_reset form. The user is redirected to the password change tab instead of the account edit form.

File

contrib/password_tab/password_policy_password_tab.module, line 73
The password policy password tab module adds a separate tab to change password.

Code

function password_policy_password_tab_exit($destination = NULL) {
  static $processed = FALSE;

  // Check if this is a drupal_goto from the password reset page.
  if (!$processed && isset($destination) && arg(0) == 'user' && arg(1) == 'reset') {
    $url_parts = parse_url($destination);

    // Check if the redirect has a path.
    if (isset($url_parts['path'])) {

      // Check if the redirect path is user/%user/edit.
      $path = drupal_substr($url_parts['path'], 1);
      $args = arg(NULL, $path);
      if (count($args) == 3 && $args[0] == 'user' && $args[2] == 'edit') {

        // Prevent loops.
        $processed = TRUE;

        // Change the drupal_goto to our change password tab.
        $path .= '/password';
        $query = isset($url_parts['query']) ? $url_parts['query'] : NULL;
        $fragment = isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL;
        drupal_goto($path, $query, $fragment);
      }
    }
  }
}