Add sendmsg API

This commit is contained in:
Skylar Ittner 2018-01-23 19:03:44 -07:00
parent 32a9f49ecb
commit c9b7bc87d5

12
api.php
View File

@ -151,7 +151,17 @@ switch ($VARS['action']) {
} }
die('{"status": "OK", "msg": "Task updated."}'); die('{"status": "OK", "msg": "Task updated."}');
case "sendmsg": case "sendmsg":
$msg = strip_tags($VARS['msg']);
if (user_exists($VARS['to'])) {
$to = getUserByUsername($VARS['to'])['uid'];
} else {
die('{"status": "ERROR", "msg": "Invalid user."}');
}
if (is_empty($msg)) {
die('{"status": "ERROR", "msg": "Missing message."}');
}
$database->insert('messages', ['messagetext' => $msg, 'messagedate' => date("Y-m-d H:i:s"), 'from' => $userinfo['uid'], 'to' => $to]);
die('{"status": "OK"}');
default: default:
header("HTTP/1.1 400 Bad Request"); header("HTTP/1.1 400 Bad Request");
die("\"400 Bad Request\""); die("\"400 Bad Request\"");