$config = CRM_Core_Config::singleton();
- $isDrupal = $config->userSystem->is_drupal;
- $isJoomla = ucfirst($config->userFramework) == 'Joomla';
- $isWordPress = $config->userFramework == 'WordPress';
-
$errors = [];
- if ($isDrupal || $isJoomla || $isWordPress) {
- $emailName = NULL;
- if (!empty($form->_bltID) && array_key_exists("email-{$form->_bltID}", $fields)) {
- // this is a transaction related page
- $emailName = 'email-' . $form->_bltID;
- }
- else {
- // find the email field in a profile page
- foreach ($fields as $name => $dontCare) {
- if (substr($name, 0, 5) == 'email') {
- $emailName = $name;
- break;
- }
- }
- }
- if ($emailName == NULL) {
- $errors['_qf_default'] = ts('Could not find an email address.');
- return $errors;
- }
+ $emailName = $config->userSystem->getEmailFieldName($form, $fields);
- if (empty($fields['cms_name'])) {
- $errors['cms_name'] = ts('Please specify a username.');
- }
-
- if (empty($fields[$emailName])) {
- $errors[$emailName] = ts('Please specify a valid email address.');
- }
+ $params = [
+ 'name' => $fields['cms_name'],
+ 'mail' => isset($fields[$emailName]) ? $fields[$emailName] : '',
+ 'pass' => isset($fields['cms_pass']) ? $fields['cms_pass'] : '',
+ ];
- if ($config->userSystem->isPasswordUserGenerated()) {
- if (empty($fields['cms_pass']) ||
- empty($fields['cms_confirm_pass'])
- ) {
- $errors['cms_pass'] = ts('Please enter a password.');
- }
- if ($fields['cms_pass'] != $fields['cms_confirm_pass']) {
- $errors['cms_pass'] = ts('Password and Confirm Password values are not the same.');
- }
- }
+ // Verify the password.
+ if ($config->userSystem->isPasswordUserGenerated()) {
+ $config->userSystem->verifyPassword($params, $errors);
+ }
- if (!empty($errors)) {
- return $errors;
- }
+ // Set generic errors messages.
+ if ($emailName == '') {
+ $errors['_qf_default'] = ts('Could not find an email address.');
+ }
- // now check that the cms db does not have the user name and/or email
- if ($isDrupal or $isJoomla or $isWordPress) {
- $params = [
- 'name' => $fields['cms_name'],
- 'mail' => $fields[$emailName],
- 'pass' => $fields['cms_pass'],
- ];
- }
+ if (empty($params['name'])) {
+ $errors['cms_name'] = ts('Please specify a username.');
+ }
- $config->userSystem->checkUserNameEmailExists($params, $errors, $emailName);
+ if (empty($params['mail'])) {
+ $errors[$emailName] = ts('Please specify a valid email address.');
+ }
- // Verify the password.
- if ($config->userSystem->isPasswordUserGenerated()) {
- $config->userSystem->verifyPassword($params, $errors);
+ if ($config->userSystem->isPasswordUserGenerated()) {
+ if (empty($fields['cms_pass']) ||
+ empty($fields['cms_confirm_pass'])
+ ) {
+ $errors['cms_pass'] = ts('Please enter a password.');
+ }
+ if ($fields['cms_pass'] != $fields['cms_confirm_pass']) {
+ $errors['cms_pass'] = ts('Password and Confirm Password values are not the same.');
}
}
+
+ $config->userSystem->checkUserNameEmailExists($params, $errors, $emailName);
+
return (!empty($errors)) ? $errors : TRUE;
}
}
/**
- * Check if username and email exists in the Backdrop db.
- *
- * @param array $params
- * Array of name and mail values.
- * @param array $errors
- * Array of errors.
- * @param string $emailName
- * Field label for the 'email'.
+ * @inheritdoc
*/
- public static function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
+ public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
if ($backdrop_errors = form_get_errors()) {
// unset Backdrop messages to avoid twice display of errors
unset($_SESSION['messages']);
return FALSE;
}
+ /**
+ * Get email field name from form values
+ *
+ * @param CRM_Core_Form $form
+ * @param array $fields
+ *
+ * @return string
+ */
+ public function getEmailFieldName(CRM_Core_Form $form, array $fields):string {
+ return 'email';
+ }
+
+ /**
+ * Check if username and email exists in the CMS.
+ *
+ * @param array $params
+ * Array of name and mail values.
+ * @param array $errors
+ * Array of errors.
+ * @param string $emailName
+ * Field label for the 'email'.
+ */
+ public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
+ }
+
}
}
/**
- * Check if username and email exists in the drupal db.
- *
- * @param array $params
- * Array of name and mail values.
- * @param array $errors
- * Array of errors.
- * @param string $emailName
- * Field label for the 'email'.
+ * @inheritdoc
*/
- public static function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
- $config = CRM_Core_Config::singleton();
-
- $dao = new CRM_Core_DAO();
- $name = $dao->escape(CRM_Utils_Array::value('name', $params));
- $email = $dao->escape(CRM_Utils_Array::value('mail', $params));
- $errors = form_get_errors();
- if ($errors) {
- // unset drupal messages to avoid twice display of errors
+ public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
+ if ($drupal_errors = form_get_errors()) {
+ // unset Drupal messages to avoid twice display of errors
unset($_SESSION['messages']);
+ $errors = array_merge($errors, $drupal_errors);
}
if (!empty($params['name'])) {
}
/**
- * Check if username and email exists in the drupal db.
- *
- * @param array $params
- * Array of name and mail values.
- * @param array $errors
- * Errors.
- * @param string $emailName
- * Field label for the 'email'.
+ * @inheritdoc
*/
- public static function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
+ public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
// If we are given a name, let's check to see if it already exists.
if (!empty($params['name'])) {
$name = $params['name'];
return FALSE;
}
+ /**
+ * @inheritdoc
+ */
+ public function getEmailFieldName(CRM_Core_Form $form, array $fields):string {
+ $emailName = '';
+
+ if (!empty($form->_bltID) && array_key_exists("email-{$form->_bltID}", $fields)) {
+ // this is a transaction related page
+ $emailName = 'email-' . $form->_bltID;
+ }
+ else {
+ // find the email field in a profile page
+ foreach ($fields as $name => $dontCare) {
+ if (substr($name, 0, 5) == 'email') {
+ $emailName = $name;
+ break;
+ }
+ }
+ }
+
+ return $emailName;
+ }
+
}
}
/**
- * Check if username and email exists in the Joomla db.
- *
- * @param array $params
- * Array of name and mail values.
- * @param array $errors
- * Array of errors.
- * @param string $emailName
- * Field label for the 'email'.
+ * @inheritdoc
+ */
+ public function getEmailFieldName(CRM_Core_Form $form, array $fields):string {
+ $emailName = '';
+
+ if (!empty($form->_bltID) && array_key_exists("email-{$form->_bltID}", $fields)) {
+ // this is a transaction related page
+ $emailName = 'email-' . $form->_bltID;
+ }
+ else {
+ // find the email field in a profile page
+ foreach ($fields as $name => $dontCare) {
+ if (substr($name, 0, 5) == 'email') {
+ $emailName = $name;
+ break;
+ }
+ }
+ }
+
+ return $emailName;
+ }
+
+ /**
+ * @inheritdoc
*/
public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
$config = CRM_Core_Config::singleton();
}
/**
- * @param array $params
- * @param array $errors
- * @param string $emailName
+ * @inheritdoc
*/
- public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
- $config = CRM_Core_Config::singleton();
+ public function getEmailFieldName(CRM_Core_Form $form, array $fields):string {
+ $emailName = '';
- $dao = new CRM_Core_DAO();
- $name = $dao->escape(CRM_Utils_Array::value('name', $params));
- $email = $dao->escape(CRM_Utils_Array::value('mail', $params));
+ if (!empty($form->_bltID) && array_key_exists("email-{$form->_bltID}", $fields)) {
+ // this is a transaction related page
+ $emailName = 'email-' . $form->_bltID;
+ }
+ else {
+ // find the email field in a profile page
+ foreach ($fields as $name => $dontCare) {
+ if (substr($name, 0, 5) == 'email') {
+ $emailName = $name;
+ break;
+ }
+ }
+ }
+
+ return $emailName;
+ }
+ /**
+ * @inheritdoc
+ */
+ public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
if (!empty($params['name'])) {
if (!validate_username($params['name'])) {
$errors['cms_name'] = ts("Your username contains invalid characters");