You are here

function username_check_callback in Username originality AJAX check 6

Same name and namespace in other branches
  1. 8 username_check.unique.inc \username_check_callback()
  2. 5 username_check.module \username_check_callback()
  3. 7 username_check.unique.inc \username_check_callback()

Main AJAX function: originality check menu callback.

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

File

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

Code

function username_check_callback() {
  $output = array();
  $username = $_GET['username'];

  // Проверка на наличие недопустимых символов
  $ret = user_validate_name($username);
  if ($ret) {
    $output['allowed'] = FALSE;
    $output['msg'] = $ret;
  }
  else {

    // Проверка на соответствие Access Rules
    $ret = drupal_is_denied('user', $username);
    if ($ret) {
      $output['allowed'] = FALSE;
      $output['msg'] = t('The username %username is not allowed.', array(
        '%username' => $username,
      ));
    }
    else {
      $username = check_plain($username);
      $ret = _username_check_is_user_exists($username);
      if ($ret) {
        $output['allowed'] = FALSE;
        $output['msg'] = t('The name %username is already taken.', array(
          '%username' => $username,
        ));
      }
      else {
        $output['allowed'] = TRUE;
        $output['msg'] = t('The username %username is available.', array(
          '%username' => $username,
        ));
      }
    }
  }
  drupal_page_header();
  print drupal_to_js($output);
  exit;
}