From: Wouter H Date: Fri, 4 Oct 2019 13:06:29 +0000 (+0200) Subject: Check email when creating a user in drupal 8 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a75f81d1a86b5d3e7c2af804d6a86451354432a0;p=civicrm-core.git Check email when creating a user in drupal 8 When visiting a contribution page as an anonymous user & it is possible to create a new Drupal 8 user, there is currently no correct validation on email address within the profile form. So when using an email address of an existing Drupal 8 user in the profile form and you continue on the confirmation page you will be redirected to the home page instead of for example the online payment page. I noticed that in the function "checkUserNameEmailExists" the variable "$emailName" does not match the key in the "$params" array. --- diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 38ed2933c6..e52bcb31a6 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -153,27 +153,27 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { // This checks for both username uniqueness and validity. $violations = iterator_to_array($user->validate()); // We only care about violations on the username field; discard the rest. - $violations = array_filter($violations, function ($v) { + $violations = array_values(array_filter($violations, function ($v) { return $v->getPropertyPath() == 'name'; - }); + })); if (count($violations) > 0) { $errors['cms_name'] = (string) $violations[0]->getMessage(); } } // And if we are given an email address, let's check to see if it already exists. - if (!empty($params[$emailName])) { - $mail = $params[$emailName]; + if (!empty($params[$emailName]) || !empty($params['mail'])) { + $key = (!empty($params[$emailName])) ? $emailName : 'mail'; $user = entity_create('user'); - $user->setEmail($mail); + $user->setEmail($params[$key]); // This checks for both email uniqueness. $violations = iterator_to_array($user->validate()); // We only care about violations on the email field; discard the rest. - $violations = array_filter($violations, function ($v) { + $violations = array_values(array_filter($violations, function ($v) { return $v->getPropertyPath() == 'mail'; - }); + })); if (count($violations) > 0) { $errors[$emailName] = (string) $violations[0]->getMessage(); }