Fix the possibility of repeatedly submitting a form with an existing e-mail address [MAILPOET-1115]
This commit is contained in:
committed by
pavel-mailpoet
parent
e4ab928e82
commit
8a91eb46e6
@ -184,8 +184,8 @@ class Subscriber extends Model {
|
|||||||
'subscribed_ip',
|
'subscribed_ip',
|
||||||
$subscriber_data['subscribed_ip']
|
$subscriber_data['subscribed_ip']
|
||||||
)->whereRaw(
|
)->whereRaw(
|
||||||
'TIME_TO_SEC(TIMEDIFF(NOW(), created_at)) < ?',
|
'(TIME_TO_SEC(TIMEDIFF(NOW(), created_at)) < ? OR TIME_TO_SEC(TIMEDIFF(NOW(), updated_at)) < ?)',
|
||||||
self::SUBSCRIPTION_LIMIT_COOLDOWN
|
array(self::SUBSCRIPTION_LIMIT_COOLDOWN, self::SUBSCRIPTION_LIMIT_COOLDOWN)
|
||||||
)->count();
|
)->count();
|
||||||
|
|
||||||
if($subscription_count > 0) {
|
if($subscription_count > 0) {
|
||||||
@ -205,6 +205,7 @@ class Subscriber extends Model {
|
|||||||
} else {
|
} else {
|
||||||
// store subscriber data to be updated after confirmation
|
// store subscriber data to be updated after confirmation
|
||||||
$subscriber->setUnconfirmedData($subscriber_data);
|
$subscriber->setUnconfirmedData($subscriber_data);
|
||||||
|
$subscriber->setExpr('updated_at', 'NOW()');
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore trashed subscriber
|
// restore trashed subscriber
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Test\API\JSON\v1;
|
namespace MailPoet\Test\API\JSON\v1;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Codeception\Util\Fixtures;
|
use Codeception\Util\Fixtures;
|
||||||
use MailPoet\API\JSON\v1\Subscribers;
|
use MailPoet\API\JSON\v1\Subscribers;
|
||||||
use MailPoet\API\JSON\Response as APIResponse;
|
use MailPoet\API\JSON\Response as APIResponse;
|
||||||
@ -519,6 +520,34 @@ class SubscribersTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItCannotMassResubscribe() {
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
|
|
||||||
|
$router = new Subscribers();
|
||||||
|
$response = $router->subscribe(array(
|
||||||
|
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||||
|
'form_id' => $this->form->id,
|
||||||
|
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||||
|
));
|
||||||
|
|
||||||
|
// Try to resubscribe an existing subscriber that was updated just now
|
||||||
|
$subscriber = Subscriber::findOne($response->data['id']);
|
||||||
|
$subscriber->created_at = Carbon::yesterday();
|
||||||
|
$subscriber->updated_at = Carbon::now();
|
||||||
|
$subscriber->save();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $router->subscribe(array(
|
||||||
|
$this->obfuscatedEmail => $subscriber->email,
|
||||||
|
'form_id' => $this->form->id,
|
||||||
|
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||||
|
));
|
||||||
|
$this->fail('It should not be possible to resubscribe a second time so soon');
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
expect($e->getMessage())->equals('You need to wait before subscribing again.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
Segment::deleteMany();
|
Segment::deleteMany();
|
||||||
Subscriber::deleteMany();
|
Subscriber::deleteMany();
|
||||||
|
Reference in New Issue
Block a user