You are here

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

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

File

src/Controller/DefaultController.php, line 115
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_mail_callback() {
  $output = [];
  $mail = $_GET['mail'];
  $ret = valid_email_address($mail);
  if (!$ret) {
    $output['msg'] = $ret;
  }
  else {
    $ret = user_is_blocked($mail);
    $output['allowed'] = FALSE;
    if ($ret) {
      $output['allowed'] = FALSE;
      $output['msg'] = t('The e-mail address %mail is not allowed.', [
        '%mail' => $mail,
      ]);
    }
    else {
      $mail = SafeMarkup::checkPlain($mail);
      $ret = $this
        ->_username_check_is_mail_exists($mail);
      if ($ret) {
        $url = Url::fromRoute("user.page");
        $login_link = \Drupal::l(t('login'), $url);
        $forgot_link = \Drupal::l(t(' password'), $url);
        $output['allowed'] = FALSE;
        $output['msg'] = t('The e-mail address %mail is already in the system, you have an account here. Please ' . $login_link . ' or if you\'ve forgotten your password, ' . $forgot_link . '.', [
          '%mail' => $mail,
        ]);
      }
      else {
        $output['allowed'] = TRUE;
      }
    }
  }
  return new JsonResponse($output);
}