You are here

public function DefaultController::username_check_profile_callback in Username originality AJAX check 8

1 string reference to 'DefaultController::username_check_profile_callback'
username_check.routing.yml in ./username_check.routing.yml
username_check.routing.yml

File

src/Controller/DefaultController.php, line 62
Contains \Drupal\username_check\Controller\DefaultController.

Class

DefaultController
Default controller for the username_check module.

Namespace

Drupal\username_check\Controller

Code

public function username_check_profile_callback() {
  $output = [];
  $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.', [
        '%username' => $username,
      ]);
    }
    else {
      $username = SafeMarkup::checkPlain($username);

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