Added subscription limit in order to avoid mass subscriptions
This commit is contained in:
@@ -14,6 +14,8 @@ class Subscriber extends Model {
|
||||
const STATUS_UNSUBSCRIBED = 'unsubscribed';
|
||||
const STATUS_UNCONFIRMED = 'unconfirmed';
|
||||
|
||||
const SUBSCRIPTION_LIMIT_COOLDOWN = 60;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
@@ -158,9 +160,27 @@ class Subscriber extends Model {
|
||||
'signup_confirmation.enabled'
|
||||
);
|
||||
|
||||
// set user ip
|
||||
$subscriber_data['ip'] = (isset($_SERVER['REMOTE_ADDR']))
|
||||
? $_SERVER['REMOTE_ADDR']
|
||||
: null;
|
||||
|
||||
// make sure we don't allow too many subscriptions with the same ip address
|
||||
$subscription_count = Subscriber::where('ip', $subscriber_data['ip'])
|
||||
->whereRaw(
|
||||
'TIME_TO_SEC(TIMEDIFF(NOW(), created_at)) < ?',
|
||||
self::SUBSCRIPTION_LIMIT_COOLDOWN
|
||||
)
|
||||
->count();
|
||||
|
||||
if($subscription_count > 0) {
|
||||
throw new \Exception(__('You need to wait before subscribing again.', 'mailpoet'));
|
||||
}
|
||||
|
||||
$subscriber = self::findOne($subscriber_data['email']);
|
||||
|
||||
if($subscriber === false) {
|
||||
|
||||
// create new subscriber
|
||||
$subscriber = self::createOrUpdate($subscriber_data);
|
||||
if($subscriber->getErrors() !== false) {
|
||||
|
Reference in New Issue
Block a user