From 71fc6ea4559e470c614366a783163715d5cab49c Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Wed, 17 Jul 2013 13:12:18 -0700 Subject: [PATCH] CRM-11316 Fix online contrib, event reg, PCP account, petition signature and mailing subscribe forms to NOT include ReCAPTCHA for logged in users. Fix notices in CRM_PCP_Form_PCPAccount for anonymous users due to undefined _defaults property. ---------------------------------------- * CRM-11316: http://issues.civicrm.org/jira/browse/CRM-11316 --- CRM/Campaign/Form/Petition/Signature.php | 7 +++---- CRM/Contribute/Form/ContributionBase.php | 3 ++- CRM/Event/Form/Registration.php | 6 +++--- CRM/Mailing/Form/Subscribe.php | 11 ++++++++--- CRM/PCP/Form/PCPAccount.php | 14 +++++++++++++- templates/CRM/Campaign/Form/Petition/Signature.tpl | 4 ++++ .../CRM/Contribute/Form/Contribution/Main.tpl | 2 +- templates/CRM/Event/Form/Registration/Register.tpl | 2 +- templates/CRM/Mailing/Form/Subscribe.tpl | 4 +++- 9 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CRM/Campaign/Form/Petition/Signature.php b/CRM/Campaign/Form/Petition/Signature.php index b00282c63e..b93b04526a 100644 --- a/CRM/Campaign/Form/Petition/Signature.php +++ b/CRM/Campaign/Form/Petition/Signature.php @@ -642,7 +642,8 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form { CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE); $this->_fields[$key] = $field; - if ($field['add_captcha']) { + // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor + if ($field['add_captcha'] && !$this->_contactId) { $addCaptcha = TRUE; } } @@ -650,9 +651,7 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form { // initialize the state country map CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - if ($addCaptcha && - !$viewOnly - ) { + if ($addCaptcha && !$viewOnly) { $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); $this->assign("isCaptcha", TRUE); diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index cba721e901..df47a2b74b 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -716,7 +716,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { ); $this->_fields[$key] = $field; } - if ($field['add_captcha']) { + // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor + if ($field['add_captcha'] && !$this->_userID) { $addCaptcha = TRUE; } } diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index ae41826ccb..a6f08e5d72 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -646,12 +646,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { //have been skip the additional participant. if ($button == 'skip') { $field['is_required'] = FALSE; - } - elseif ($field['add_captcha']) { + } + // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor + elseif ($field['add_captcha'] && !$contactID) { // only add captcha for first page $addCaptcha = TRUE; } - list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') { if (!array_key_exists($index, $stateCountryMap)) { diff --git a/CRM/Mailing/Form/Subscribe.php b/CRM/Mailing/Form/Subscribe.php index 041ecac285..9742f501cb 100644 --- a/CRM/Mailing/Form/Subscribe.php +++ b/CRM/Mailing/Form/Subscribe.php @@ -130,11 +130,15 @@ ORDER BY title"; $addCaptcha = TRUE; - // if recaptcha is not set, then dont add it + // if recaptcha is not configured, then dont add it + // CRM-11316 Only enable ReCAPTCHA for anonymous visitors $config = CRM_Core_Config::singleton(); + $session = CRM_Core_Session::singleton(); + $contactID = $session->get('userID'); + if (empty($config->recaptchaPublicKey) || - empty($config->recaptchaPrivateKey) - ) { + empty($config->recaptchaPrivateKey) || + $contactID) { $addCaptcha = FALSE; } else { @@ -152,6 +156,7 @@ ORDER BY title"; // add captcha $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); + $this->assign('isCaptcha', TRUE); } $this->addButtons(array( diff --git a/CRM/PCP/Form/PCPAccount.php b/CRM/PCP/Form/PCPAccount.php index 8f1be03544..7de81d9b28 100644 --- a/CRM/PCP/Form/PCPAccount.php +++ b/CRM/PCP/Form/PCPAccount.php @@ -56,6 +56,15 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { */ public $_single; + /** + * the default values for the form + * + * @var array + * @protected + */ + protected $_defaults; + + public function preProcess() { $session = CRM_Core_Session::singleton(); $config = CRM_Core_Config::singleton(); @@ -108,6 +117,7 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { } function setDefaultValues() { + $this->_defaults = array(); if ($this->_contactID) { foreach ($this->_fields as $name => $dontcare) { $fields[$name] = 1; @@ -177,7 +187,9 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { } CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE); $this->_fields[$key] = $field; - if ($field['add_captcha']) { + + // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor + if ($field['add_captcha'] && !$this->_contactID) { $addCaptcha = TRUE; } } diff --git a/templates/CRM/Campaign/Form/Petition/Signature.tpl b/templates/CRM/Campaign/Form/Petition/Signature.tpl index 0736f23007..bfa14f6297 100644 --- a/templates/CRM/Campaign/Form/Petition/Signature.tpl +++ b/templates/CRM/Campaign/Form/Petition/Signature.tpl @@ -56,6 +56,10 @@ Please check your email inbox for the confirmation email. If you don't find it, {include file="CRM/Campaign/Form/Petition/Block.tpl" fields=$petitionActivityProfile} + {if $isCaptcha} + {include file='CRM/common/ReCAPTCHA.tpl'} + {/if} +
{include file="CRM/common/formButtons.tpl" location="bottom"}
diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index c81cd8c12f..f60dd4139d 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -319,7 +319,7 @@ {/if} {if $isCaptcha} - {include file='CRM/common/ReCAPTCHA.tpl'} + {include file='CRM/common/ReCAPTCHA.tpl'} {/if}
{include file="CRM/common/formButtons.tpl" location="bottom"} diff --git a/templates/CRM/Event/Form/Registration/Register.tpl b/templates/CRM/Event/Form/Registration/Register.tpl index 887b790221..5837371c6a 100644 --- a/templates/CRM/Event/Form/Registration/Register.tpl +++ b/templates/CRM/Event/Form/Registration/Register.tpl @@ -163,7 +163,7 @@ {include file="CRM/UF/Form/Block.tpl" fields=$customPost} {if $isCaptcha} - {include file='CRM/common/ReCAPTCHA.tpl'} + {include file='CRM/common/ReCAPTCHA.tpl'} {/if}
diff --git a/templates/CRM/Mailing/Form/Subscribe.tpl b/templates/CRM/Mailing/Form/Subscribe.tpl index 7001c3f3a6..65da92d9ea 100644 --- a/templates/CRM/Mailing/Form/Subscribe.tpl +++ b/templates/CRM/Mailing/Form/Subscribe.tpl @@ -56,6 +56,8 @@ -{include file='CRM/common/ReCAPTCHA.tpl'} +{if $isCaptcha} + {include file='CRM/common/ReCAPTCHA.tpl'} +{/if}
{include file="CRM/common/formButtons.tpl" location="top"}
-- 2.25.1