You are here

function username_check_callback in Username originality AJAX check 8

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

Main AJAX function: originality check menu callback.

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 {
    $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);
      $ret = _username_check_is_user_exists($username);
      if ($ret) {
        $output['allowed'] = FALSE;
        $output['msg'] = t('The username %username is already taken. If this is you, please ' . \Drupal::l('login,', \Drupal\Core\Url::fromRoute('user.page')) . ' or if you\'ve forgotten your password, ' . \Drupal::l('request a new password', \Drupal\Core\Url::fromRoute('user.pass')) . '.', array(
          '%username' => $username,
        ));
      }
      else {
        $output['allowed'] = TRUE;
      }
    }
  }
  drupal_json_output($output);
}