You are here

function username_check_mail_callback in Username originality AJAX check 8

Same name and namespace in other branches
  1. 7 username_check.unique.inc \username_check_mail_callback()

Main AJAX function: originality check menu callback for email.

File

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

Code

function username_check_mail_callback() {
  $output = array();
  $mail = $_GET['mail'];
  $ret = user_validate_mail($mail);
  if ($ret) {
    $output['allowed'] = FALSE;
    $output['msg'] = $ret;
  }
  else {
    $ret = user_is_blocked($mail);
    if ($ret) {
      $output['allowed'] = FALSE;
      $output['msg'] = t('The e-mail address %mail is not allowed.', array(
        '%mail' => $mail,
      ));
    }
    else {
      $mail = check_plain($mail);
      $ret = _username_check_is_mail_exists($mail);
      if ($ret) {
        $output['allowed'] = FALSE;
        $output['msg'] = t('The e-mail address %mail is already in the system, you have an account here. 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(
          '%mail' => $mail,
        ));
      }
      else {
        $output['allowed'] = TRUE;
      }
    }
  }
  drupal_json_output($output);
}