diff --git a/appinfo/routes.php b/appinfo/routes.php index 4ce3e32..4e7abad 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -23,5 +23,5 @@ $application = new Application(); $application->registerRoutes($this, array('routes' => array( array('name' => 'sms#index', 'url' => '/', 'verb' => 'GET'), - array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'), + array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'), ))); diff --git a/controller/smscontroller.php b/controller/smscontroller.php index b5d2c7b..6ccbdaa 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -37,16 +37,42 @@ class SmsController extends Controller { /** * @NoAdminRequired */ - public function push($smsCount, $smsDatas) { + public function push ($smsCount, $smsDatas) { if ($smsCount != count($smsDatas)) { return "Error: sms count invalid"; } - $buf = ""; - foreach ($sms as $smsDatas) { - $buf .= $sms["id"]; + foreach ($smsDatas as $sms) { + if (!array_key_exists("id", $sms) || !array_key_exists("read", $sms) || + !array_key_exists("draft", $sms) || + !array_key_exists("date", $sms) || !array_key_exists("seen", $sms) || + !array_key_exists("body", $sms) || !array_key_exists("address", $sms)) { + return "Error: bad SMS entry"; + } + + if (!is_numeric($sms["id"])) { + return "Error: Invalid SMS ID"; + } + + if ($sms["read"] !== "true" && $sms["read"] !== "false") { + return "Error: Invalid SMS Read state"; + } + + if ($sms["seen"] !== "true" && $sms["seen"] !== "false") { + return "Error: Invalid SMS Seen state"; + } + + if ($sms["draft"] !== "true" && $sms["draft"] !== "false") { + return "Error: Invalid SMS Draft state"; + } + + if (!is_numeric($sms["date"]) && $sms["date"] != 0 && $sms["date"] != 1) { + return "Error: Invalid SMS date"; + } + + // @ TODO: test address and body ? } - return $buf; + return "OK"; } diff --git a/js/script.js b/js/script.js index 91f9ca9..498a7da 100644 --- a/js/script.js +++ b/js/script.js @@ -16,8 +16,8 @@ var data = { smsCount: 2, smsDatas: [ - {"read": 1, "date": 1410524385, "seen": 0, "address": "+33612121212", "body": "testSMS", "id": 10}, - {"read": 0, "date": 1400524385, "seen": 1, "address": "+33614121212", "body": "test SMS 2", "id": 14}, + {"read": true, "date": 1410524385, "seen": false, "draft": false, "address": "+33612121212", "body": "testSMS", "id": 10}, + {"read": false, "date": 1400524385, "seen": true, "draft": true, "address": "+33614121212", "body": "test SMS 2", "id": 14}, ] };