Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

71 lines
1.4 KiB
PHP

<?php
class Mailjet_SyncEventModuleFrontController extends ModuleFrontController
{
public function postProcess()
{
if (!Configuration::get('MAILJETSYNC_EVENT_TOKEN'))
{
header('HTTP/1.1 405 Method Not Allowed');
die('0');
}
if (!Tools::getIsset('token') ||
Tools::getValue('token') != Configuration::get('MAILJETSYNC_EVENT_TOKEN'))
{
header('HTTP/1.1 401 Unauthorized');
die('0');
}
$post = trim(Tools::file_get_contents('php://input'));
if (empty($post))
{
header('HTTP/1.1 421 No event');
die('0');
}
$t = Tools::jsonDecode($post, true);
if (!is_array($t) || !isset($t['event']))
{
header('HTTP/1.1 422 Not ok');
die('0');
}
switch ($t['event'])
{
case 'unsub':
if (!array_key_exists('email', $t))
{
header('HTTP/1.1 400 Bad Request');
die('0');
}
$c = new Customer();
if ($c->getByEmail($t['email']))
{
if ($c->newsletter == 0)
{
header('HTTP/1.1 304 Not Modified');
die('0');
}
else
{
$c->newsletter = 0;
$c->ip_registration_newsletter = null;
$c->newsletter_date_add = null;
$c->update();
header('HTTP/1.1 200 OK');
die('1');
}
}
else
{
header('HTTP/1.1 404 Not Found');
die('0');
}
break;
default:
header('HTTP/1.1 423 No handler');
die('0');
}
}
}