Skip to content
Permalink
Newer
Older
100644 39 lines (35 sloc) 1.1 KB
1
<?php
2
defined('APP_DIR') or define('APP_DIR', __DIR__ . '/../app/');
3
include_once(APP_DIR . 'include/http.php');
4
include_once(APP_DIR . 'model/SecureMessage.php');
5
include_once(APP_DIR . 'model/User.php');
6
7
$data = User::authenticated();
8
if (!$data) {
9
echo json_encode(['unauthorized']);
10
exit();
11
}
12
13
/* POST API Routes */
14
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
15
$params = Http::post_params();
16
$action = $params['action'];
17
18
if ($action === 'mark_unread') {
19
$m = SecureMessage::getByID($params['message_id']);
20
$m->is_read = true;
21
$m->save();
22
echo json_encode(['success']);
23
} else if ($action === 'send_message') {
24
$user = User::getByID($params['user_id']);
25
$recipient = User::get($params['recipient']);
26
if (!$recipient) {
27
echo json_encode(['unknown_recipient']);
28
} else {
29
$m = new SecureMessage;
30
$m->message = $params['message'];
31
$m->sender_id = $user->id;
32
$m->receiver_id = $recipient->id;
33
$m->save();
34
echo json_encode(['success']);
35
}
36
}
37
38
}
39
?>
You can’t perform that action at this time.