From 63df688915378bea00a0000fa0d356dd0f6fff18 Mon Sep 17 00:00:00 2001 From: Herb vd Dool Date: Mon, 16 Oct 2017 12:01:12 -0400 Subject: [PATCH] CRM-21272: move definition of isPasswordUserGenerated to CMS classes --- CRM/Core/BAO/CMSUser.php | 4 ++-- CRM/Utils/System/Backdrop.php | 10 ++++++++++ CRM/Utils/System/Base.php | 9 +++++++++ CRM/Utils/System/Drupal8.php | 10 ++++++++++ CRM/Utils/System/DrupalBase.php | 11 ++++++++++- CRM/Utils/System/Joomla.php | 7 +++++++ CRM/Utils/System/WordPress.php | 7 +++++++ 7 files changed, 55 insertions(+), 3 deletions(-) diff --git a/CRM/Core/BAO/CMSUser.php b/CRM/Core/BAO/CMSUser.php index 3b23a1f746..c8452a41e6 100644 --- a/CRM/Core/BAO/CMSUser.php +++ b/CRM/Core/BAO/CMSUser.php @@ -127,7 +127,7 @@ class CRM_Core_BAO_CMSUser { $form->assign('isCMS', $required); if (!$userID || $action & CRM_Core_Action::PREVIEW || $action & CRM_Core_Action::PROFILE) { $form->add('text', 'cms_name', ts('Username'), NULL, $required); - if (($isDrupal && !variable_get('user_email_verification', TRUE)) OR ($isJoomla) OR ($isWordPress)) { + if ($config->userSystem->isPasswordUserGenerated()) { $form->add('password', 'cms_pass', ts('Password')); $form->add('password', 'cms_confirm_pass', ts('Confirm Password')); } @@ -197,7 +197,7 @@ class CRM_Core_BAO_CMSUser { $errors[$emailName] = ts('Please specify a valid email address.'); } - if (($isDrupal && !variable_get('user_email_verification', TRUE)) OR ($isJoomla) OR ($isWordPress)) { + if ($config->userSystem->isPasswordUserGenerated()) { if (empty($fields['cms_pass']) || empty($fields['cms_confirm_pass']) ) { diff --git a/CRM/Utils/System/Backdrop.php b/CRM/Utils/System/Backdrop.php index 47de8e6ec9..42eaf58ae3 100644 --- a/CRM/Utils/System/Backdrop.php +++ b/CRM/Utils/System/Backdrop.php @@ -422,6 +422,16 @@ AND u.status = 1 return TRUE; } + /** + * @inheritDoc + */ + function isPasswordUserGenerated() { + if (config_get('system.core', 'user_email_verification') == TRUE) { + return FALSE; + } + return TRUE; + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index af93951275..3bc5758c3a 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -404,6 +404,15 @@ abstract class CRM_Utils_System_Base { return FALSE; } + /** + * Check if user can create passwords or is initially assigned a system-generated one. + * + * @return bool + */ + function isPasswordUserGenerated() { + return FALSE; + } + /** * Get user login URL for hosting CMS (method declared in each CMS system class) * diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 9053629842..6e0f7ac43a 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -536,6 +536,16 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { return TRUE; } + /** + * @inheritDoc + */ + function isPasswordUserGenerated() { + if (\Drupal::config('user.settings')->get('verify_mail') == TRUE) { + return FALSE; + } + return TRUE; + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 848c446b35..2a191db72b 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -424,6 +424,16 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { return TRUE; } + /** + * @inheritDoc + */ + function isPasswordUserGenerated() { + if (variable_get('user_email_verification', TRUE)) { + return FALSE; + } + return TRUE; + } + /** * @inheritDoc */ @@ -653,5 +663,4 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } } } - } diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index 2ce306e306..29b1b0e02a 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -589,6 +589,13 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { return TRUE; } + /** + * @inheritDoc + */ + function isPasswordUserGenerated() { + return TRUE; + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index b3ce465567..8bfd797e9c 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -619,6 +619,13 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { return TRUE; } + /** + * @inheritDoc + */ + function isPasswordUserGenerated() { + return TRUE; + } + /** * @return mixed */ -- 2.25.1