public function DefaultController::username_check_callback in Username originality AJAX check 8
1 string reference to 'DefaultController::username_check_callback'
File
- src/
Controller/ DefaultController.php, line 18 - Contains \Drupal\username_check\Controller\DefaultController.
Class
- DefaultController
- Default controller for the username_check module.
Namespace
Drupal\username_check\ControllerCode
public function username_check_callback() {
$output = [];
$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.', [
'%username' => $username,
]);
}
else {
//$username = check_plain($username);
$username = SafeMarkup::checkPlain($username);
$ret = $this
->_username_check_is_user_exists($username);
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 username %username is already taken. If this is you, please ' . $login_link . ' or if you\'ve forgotten your password, ' . $forgot_link . '.', [
'%username' => $username,
]);
}
else {
$output['allowed'] = TRUE;
}
}
}
return new JsonResponse($output);
}