Remove rest of usage old model SubscriberIP
[MAILPOET-3032]
This commit is contained in:
@ -32,9 +32,13 @@ class Subscription {
|
|||||||
/** @var WPFunctions */
|
/** @var WPFunctions */
|
||||||
private $wp;
|
private $wp;
|
||||||
|
|
||||||
public function __construct(UserSubscription\Pages $subscriptionPages, WPFunctions $wp) {
|
/** @var UserSubscription\Captcha */
|
||||||
|
private $captcha;
|
||||||
|
|
||||||
|
public function __construct(UserSubscription\Pages $subscriptionPages, WPFunctions $wp, UserSubscription\Captcha $captcha) {
|
||||||
$this->subscriptionPages = $subscriptionPages;
|
$this->subscriptionPages = $subscriptionPages;
|
||||||
$this->wp = $wp;
|
$this->wp = $wp;
|
||||||
|
$this->captcha = $captcha;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function captcha($data) {
|
public function captcha($data) {
|
||||||
@ -42,11 +46,10 @@ class Subscription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function captchaImage($data) {
|
public function captchaImage($data) {
|
||||||
$captcha = new UserSubscription\Captcha;
|
|
||||||
$width = !empty($data['width']) ? (int)$data['width'] : null;
|
$width = !empty($data['width']) ? (int)$data['width'] : null;
|
||||||
$height = !empty($data['height']) ? (int)$data['height'] : null;
|
$height = !empty($data['height']) ? (int)$data['height'] : null;
|
||||||
$sessionId = !empty($data['captcha_session_id']) ? $data['captcha_session_id'] : null;
|
$sessionId = !empty($data['captcha_session_id']) ? $data['captcha_session_id'] : null;
|
||||||
return $captcha->renderImage($width, $height, $sessionId);
|
return $this->captcha->renderImage($width, $height, $sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function confirm($data) {
|
public function confirm($data) {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace MailPoet\Subscription;
|
namespace MailPoet\Subscription;
|
||||||
|
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SubscriberIP;
|
use MailPoet\Subscribers\SubscriberIPsRepository;
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
use MailPoetVendor\Gregwar\Captcha\CaptchaBuilder;
|
use MailPoetVendor\Gregwar\Captcha\CaptchaBuilder;
|
||||||
@ -19,7 +19,14 @@ class Captcha {
|
|||||||
/** @var CaptchaSession */
|
/** @var CaptchaSession */
|
||||||
private $captchaSession;
|
private $captchaSession;
|
||||||
|
|
||||||
public function __construct(WPFunctions $wp = null, CaptchaSession $captchaSession = null) {
|
/** @var SubscriberIPsRepository */
|
||||||
|
private $subscriberIPsRepository;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
SubscriberIPsRepository $subscriberIPsRepository,
|
||||||
|
WPFunctions $wp = null,
|
||||||
|
CaptchaSession $captchaSession = null
|
||||||
|
) {
|
||||||
if ($wp === null) {
|
if ($wp === null) {
|
||||||
$wp = new WPFunctions;
|
$wp = new WPFunctions;
|
||||||
}
|
}
|
||||||
@ -28,6 +35,7 @@ class Captcha {
|
|||||||
}
|
}
|
||||||
$this->wp = $wp;
|
$this->wp = $wp;
|
||||||
$this->captchaSession = $captchaSession;
|
$this->captchaSession = $captchaSession;
|
||||||
|
$this->subscriberIPsRepository = $subscriberIPsRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isSupported() {
|
public function isSupported() {
|
||||||
@ -59,11 +67,10 @@ class Captcha {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscriptionCount = SubscriberIP::where('ip', $subscriberIp)
|
$subscriptionCount = $this->subscriberIPsRepository->getCountByIPAndCreatedAtAfterTimeInSeconds(
|
||||||
->whereRaw(
|
$subscriberIp,
|
||||||
'(`created_at` >= NOW() - INTERVAL ? SECOND)',
|
(int)$subscriptionCaptchaWindow
|
||||||
[(int)$subscriptionCaptchaWindow]
|
);
|
||||||
)->count();
|
|
||||||
|
|
||||||
if ($subscriptionCount > 0) {
|
if ($subscriptionCount > 0) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -30,10 +30,11 @@ class SetupTest extends \MailPoetTest {
|
|||||||
|
|
||||||
$settings = SettingsController::getInstance();
|
$settings = SettingsController::getInstance();
|
||||||
$referralDetector = new ReferralDetector($wpStub, $settings);
|
$referralDetector = new ReferralDetector($wpStub, $settings);
|
||||||
|
$subscriptionCaptcha = $this->diContainer->get(Captcha::class);
|
||||||
$populator = new Populator(
|
$populator = new Populator(
|
||||||
$settings,
|
$settings,
|
||||||
$wpStub,
|
$wpStub,
|
||||||
new Captcha(),
|
$subscriptionCaptcha,
|
||||||
$referralDetector,
|
$referralDetector,
|
||||||
$this->diContainer->get(FormsRepository::class),
|
$this->diContainer->get(FormsRepository::class),
|
||||||
$this->entityManager,
|
$this->entityManager,
|
||||||
@ -48,7 +49,6 @@ class SetupTest extends \MailPoetTest {
|
|||||||
expect($signupConfirmation)->true();
|
expect($signupConfirmation)->true();
|
||||||
|
|
||||||
$captcha = $settings->fetch('captcha');
|
$captcha = $settings->fetch('captcha');
|
||||||
$subscriptionCaptcha = new Captcha;
|
|
||||||
$captchaType = $subscriptionCaptcha->isSupported() ? Captcha::TYPE_BUILTIN : Captcha::TYPE_DISABLED;
|
$captchaType = $subscriptionCaptcha->isSupported() ? Captcha::TYPE_BUILTIN : Captcha::TYPE_DISABLED;
|
||||||
expect($captcha['type'])->equals($captchaType);
|
expect($captcha['type'])->equals($captchaType);
|
||||||
expect($captcha['recaptcha_site_token'])->equals('');
|
expect($captcha['recaptcha_site_token'])->equals('');
|
||||||
|
@ -18,6 +18,7 @@ use MailPoet\Entities\SegmentEntity;
|
|||||||
use MailPoet\Entities\SendingQueueEntity;
|
use MailPoet\Entities\SendingQueueEntity;
|
||||||
use MailPoet\Entities\SubscriberCustomFieldEntity;
|
use MailPoet\Entities\SubscriberCustomFieldEntity;
|
||||||
use MailPoet\Entities\SubscriberEntity;
|
use MailPoet\Entities\SubscriberEntity;
|
||||||
|
use MailPoet\Entities\SubscriberIPEntity;
|
||||||
use MailPoet\Entities\SubscriberSegmentEntity;
|
use MailPoet\Entities\SubscriberSegmentEntity;
|
||||||
use MailPoet\Form\Util\FieldNameObfuscator;
|
use MailPoet\Form\Util\FieldNameObfuscator;
|
||||||
use MailPoet\Listing\Handler;
|
use MailPoet\Listing\Handler;
|
||||||
@ -29,7 +30,6 @@ use MailPoet\Models\NewsletterOptionField;
|
|||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
use MailPoet\Models\SendingQueue;
|
use MailPoet\Models\SendingQueue;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SubscriberIP;
|
|
||||||
use MailPoet\Models\SubscriberSegment;
|
use MailPoet\Models\SubscriberSegment;
|
||||||
use MailPoet\Segments\SegmentsRepository;
|
use MailPoet\Segments\SegmentsRepository;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
@ -46,7 +46,6 @@ use MailPoet\Test\DataFactories\DynamicSegment;
|
|||||||
use MailPoet\UnexpectedValueException;
|
use MailPoet\UnexpectedValueException;
|
||||||
use MailPoet\WP\Functions;
|
use MailPoet\WP\Functions;
|
||||||
use MailPoetVendor\Carbon\Carbon;
|
use MailPoetVendor\Carbon\Carbon;
|
||||||
use MailPoetVendor\Idiorm\ORM;
|
|
||||||
|
|
||||||
class SubscribersTest extends \MailPoetTest {
|
class SubscribersTest extends \MailPoetTest {
|
||||||
|
|
||||||
@ -938,6 +937,6 @@ class SubscribersTest extends \MailPoetTest {
|
|||||||
$this->truncateEntity(CustomFieldEntity::class);
|
$this->truncateEntity(CustomFieldEntity::class);
|
||||||
$this->truncateEntity(SubscriberCustomFieldEntity::class);
|
$this->truncateEntity(SubscriberCustomFieldEntity::class);
|
||||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||||
ORM::raw_execute('TRUNCATE ' . SubscriberIP::$_table);
|
$this->truncateEntity(SubscriberIPEntity::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace MailPoet\Test\Router\Endpoints;
|
|||||||
use Codeception\Stub;
|
use Codeception\Stub;
|
||||||
use Codeception\Stub\Expected;
|
use Codeception\Stub\Expected;
|
||||||
use MailPoet\Router\Endpoints\Subscription;
|
use MailPoet\Router\Endpoints\Subscription;
|
||||||
|
use MailPoet\Subscription\Captcha;
|
||||||
use MailPoet\Subscription\Pages;
|
use MailPoet\Subscription\Pages;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
@ -14,9 +15,13 @@ class SubscriptionTest extends \MailPoetTest {
|
|||||||
/** @var WPFunctions */
|
/** @var WPFunctions */
|
||||||
private $wp;
|
private $wp;
|
||||||
|
|
||||||
|
/** @var Captcha */
|
||||||
|
private $captcha;
|
||||||
|
|
||||||
public function _before() {
|
public function _before() {
|
||||||
$this->data = [];
|
$this->data = [];
|
||||||
$this->wp = WPFunctions::get();
|
$this->wp = WPFunctions::get();
|
||||||
|
$this->captcha = $this->diContainer->get(Captcha::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItDisplaysConfirmPage() {
|
public function testItDisplaysConfirmPage() {
|
||||||
@ -24,7 +29,7 @@ class SubscriptionTest extends \MailPoetTest {
|
|||||||
'wp' => $this->wp,
|
'wp' => $this->wp,
|
||||||
'confirm' => Expected::exactly(1),
|
'confirm' => Expected::exactly(1),
|
||||||
], $this);
|
], $this);
|
||||||
$subscription = new Subscription($pages, $this->wp);
|
$subscription = new Subscription($pages, $this->wp, $this->captcha);
|
||||||
$subscription->confirm($this->data);
|
$subscription->confirm($this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +39,7 @@ class SubscriptionTest extends \MailPoetTest {
|
|||||||
'getManageLink' => Expected::exactly(1),
|
'getManageLink' => Expected::exactly(1),
|
||||||
'getManageContent' => Expected::exactly(1),
|
'getManageContent' => Expected::exactly(1),
|
||||||
], $this);
|
], $this);
|
||||||
$subscription = new Subscription($pages, $this->wp);
|
$subscription = new Subscription($pages, $this->wp, $this->captcha);
|
||||||
$subscription->manage($this->data);
|
$subscription->manage($this->data);
|
||||||
do_shortcode('[mailpoet_manage]');
|
do_shortcode('[mailpoet_manage]');
|
||||||
do_shortcode('[mailpoet_manage_subscription]');
|
do_shortcode('[mailpoet_manage_subscription]');
|
||||||
@ -45,7 +50,7 @@ class SubscriptionTest extends \MailPoetTest {
|
|||||||
'wp' => new WPFunctions,
|
'wp' => new WPFunctions,
|
||||||
'unsubscribe' => Expected::exactly(1),
|
'unsubscribe' => Expected::exactly(1),
|
||||||
], $this);
|
], $this);
|
||||||
$subscription = new Subscription($pages, $this->wp);
|
$subscription = new Subscription($pages, $this->wp, $this->captcha);
|
||||||
$subscription->unsubscribe($this->data);
|
$subscription->unsubscribe($this->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
namespace MailPoet\Test\Subscription;
|
namespace MailPoet\Test\Subscription;
|
||||||
|
|
||||||
use Codeception\Util\Fixtures;
|
use Codeception\Util\Fixtures;
|
||||||
|
use MailPoet\Entities\SubscriberIPEntity;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\SubscriberIP;
|
use MailPoet\Subscribers\SubscriberIPsRepository;
|
||||||
use MailPoet\Subscription\Captcha;
|
use MailPoet\Subscription\Captcha;
|
||||||
use MailPoet\Subscription\CaptchaSession;
|
use MailPoet\Subscription\CaptchaSession;
|
||||||
use MailPoet\Util\Cookies;
|
use MailPoet\Util\Cookies;
|
||||||
@ -24,9 +25,10 @@ class CaptchaTest extends \MailPoetTest {
|
|||||||
public function _before() {
|
public function _before() {
|
||||||
$cookiesMock = $this->createMock(Cookies::class);
|
$cookiesMock = $this->createMock(Cookies::class);
|
||||||
$cookiesMock->method('get')->willReturn('abcd');
|
$cookiesMock->method('get')->willReturn('abcd');
|
||||||
|
$subscriberIPsRepository = $this->diContainer->get(SubscriberIPsRepository::class);
|
||||||
$this->captchaSession = new CaptchaSession(new Functions());
|
$this->captchaSession = new CaptchaSession(new Functions());
|
||||||
$this->captchaSession->init(self::CAPTCHA_SESSION_ID);
|
$this->captchaSession->init(self::CAPTCHA_SESSION_ID);
|
||||||
$this->captcha = new Captcha(new WPFunctions, $this->captchaSession);
|
$this->captcha = new Captcha($subscriberIPsRepository, new WPFunctions, $this->captchaSession);
|
||||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
$this->captchaSession->reset();
|
$this->captchaSession->reset();
|
||||||
}
|
}
|
||||||
@ -47,10 +49,10 @@ class CaptchaTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testItRequiresCaptchaForRepeatedIPAddress() {
|
public function testItRequiresCaptchaForRepeatedIPAddress() {
|
||||||
$ip = SubscriberIP::create();
|
$ip = new SubscriberIPEntity('127.0.0.1');
|
||||||
$ip->ip = '127.0.0.1';
|
$ip->setCreatedAt(Carbon::now()->subMinutes(1));
|
||||||
$ip->createdAt = Carbon::now()->subMinutes(1);
|
$this->entityManager->persist($ip);
|
||||||
$ip->save();
|
$this->entityManager->flush();
|
||||||
$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);
|
||||||
@ -64,6 +66,6 @@ class CaptchaTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function _after() {
|
public function _after() {
|
||||||
SubscriberIP::deleteMany();
|
$this->truncateEntity(SubscriberIPEntity::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user