Show CAPTCHA from first signup
[MAILPOET-3788]
This commit is contained in:
@@ -43,12 +43,16 @@ class Captcha {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isRequired($subscriberEmail = null) {
|
public function isRequired($subscriberEmail = null) {
|
||||||
if ($this->isUserExemptFromCaptcha()) {
|
if ($this->isUserExemptFromCaptcha() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check limits per recipient
|
$subscriptionCaptchaRecipientLimit = $this->wp->applyFilters('mailpoet_subscription_captcha_recipient_limit', 0);
|
||||||
$subscriptionCaptchaRecipientLimit = $this->wp->applyFilters('mailpoet_subscription_captcha_recipient_limit', 1);
|
if ($subscriptionCaptchaRecipientLimit === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check limits per recipient if enabled
|
||||||
if ($subscriberEmail) {
|
if ($subscriberEmail) {
|
||||||
$subscriber = Subscriber::where('email', $subscriberEmail)->findOne();
|
$subscriber = Subscriber::where('email', $subscriberEmail)->findOne();
|
||||||
if ($subscriber instanceof Subscriber
|
if ($subscriber instanceof Subscriber
|
||||||
|
@@ -33,22 +33,37 @@ class CaptchaTest extends \MailPoetTest {
|
|||||||
$this->captchaSession->reset();
|
$this->captchaSession->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItDoesNotRequireCaptchaForTheFirstSubscription() {
|
public function testItRequiresCaptchaForFirstSubscription() {
|
||||||
|
$email = 'non-existent-subscriber@example.com';
|
||||||
|
$result = $this->captcha->isRequired($email);
|
||||||
|
expect($result)->equals(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItRequiresCaptchaForUnrepeatedIPAddress() {
|
||||||
|
$result = $this->captcha->isRequired();
|
||||||
|
expect($result)->equals(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItTakesFilterIntoAccountToDisableCaptcha() {
|
||||||
|
$wp = new WPFunctions;
|
||||||
|
$filter = function() {
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
$wp->addFilter('mailpoet_subscription_captcha_recipient_limit', $filter);
|
||||||
$email = 'non-existent-subscriber@example.com';
|
$email = 'non-existent-subscriber@example.com';
|
||||||
$result = $this->captcha->isRequired($email);
|
$result = $this->captcha->isRequired($email);
|
||||||
expect($result)->equals(false);
|
expect($result)->equals(false);
|
||||||
}
|
|
||||||
|
|
||||||
public function testItRequiresCaptchaForRepeatedRecipient() {
|
$result = $this->captcha->isRequired();
|
||||||
|
expect($result)->equals(false);
|
||||||
|
|
||||||
$subscriber = Subscriber::create();
|
$subscriber = Subscriber::create();
|
||||||
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
||||||
$subscriber->countConfirmations = 1;
|
$subscriber->countConfirmations = 1;
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
$result = $this->captcha->isRequired($subscriber->email);
|
$result = $this->captcha->isRequired($subscriber->email);
|
||||||
expect($result)->equals(true);
|
expect($result)->equals(true);
|
||||||
}
|
|
||||||
|
|
||||||
public function testItRequiresCaptchaForRepeatedIPAddress() {
|
|
||||||
$ip = new SubscriberIPEntity('127.0.0.1');
|
$ip = new SubscriberIPEntity('127.0.0.1');
|
||||||
$ip->setCreatedAt(Carbon::now()->subMinutes(1));
|
$ip->setCreatedAt(Carbon::now()->subMinutes(1));
|
||||||
$this->entityManager->persist($ip);
|
$this->entityManager->persist($ip);
|
||||||
@@ -56,6 +71,8 @@ class CaptchaTest extends \MailPoetTest {
|
|||||||
$email = 'non-existent-subscriber@example.com';
|
$email = 'non-existent-subscriber@example.com';
|
||||||
$result = $this->captcha->isRequired($email);
|
$result = $this->captcha->isRequired($email);
|
||||||
expect($result)->equals(true);
|
expect($result)->equals(true);
|
||||||
|
|
||||||
|
$wp->removeFilter('mailpoet_subscription_captcha_recipient_limit', $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItRendersImageAndStoresHashToSession() {
|
public function testItRendersImageAndStoresHashToSession() {
|
||||||
|
Reference in New Issue
Block a user