You are here

function username_check_profile_callback in Username originality AJAX check 7

Same name and namespace in other branches
  1. 8 username_check.unique.inc \username_check_profile_callback()

Main AJAX function: originality check menu callback for user profile

1 string reference to 'username_check_profile_callback'
username_check_menu in ./username_check.module
Implementation of hook_menu().

File

./username_check.unique.inc, line 57
AJAX callbacks for the username_check module.

Code

function username_check_profile_callback() {
  $output = array();
  $username = $_GET['profile'];
  $ret = user_validate_name($username);
  if ($ret) {
    $output['allowed'] = FALSE;
    $output['msg'] = $ret;
  }
  else {
    $ret = user_is_blocked($username);
    if ($ret) {
      $output['allowed'] = FALSE;
      $output['msg'] = t('The username %username is not allowed.', array(
        '%username' => $username,
      ));
    }
    else {
      $username = check_plain($username);

      // check to see if this username is the current users username
      $ret = _username_check_is_current_user($username);
      if ($ret) {
        $output['allowed'] = TRUE;
        $output['msg'] = t('The username %username is your username.', array(
          '%username' => $username,
        ));
      }
      else {
        $ret = _username_check_is_user_exists($username);
        if ($ret) {
          $output['allowed'] = FALSE;
          $output['msg'] = t('The username %username is already taken.', array(
            '%username' => $username,
          ));
        }
        else {
          $output['allowed'] = TRUE;
        }
      }
    }
  }
  drupal_json_output($output);
}