Browse Source

status confirm

master
Robin Thoni 9 years ago
parent
commit
58d871ab94
1 changed files with 26 additions and 0 deletions
  1. 26
    0
      status.php

+ 26
- 0
status.php View File

@@ -15,6 +15,32 @@ function check_token()
15 15
 function status_confirm($id)
16 16
 {
17 17
   $token = check_token();
18
+  $confirm = get_post("confirmation");
19
+
20
+  if (database_exec("SELECT `id` FROM status WHERE `id` = :id",
21
+    array(":id" => $id))->fetch() === false)
22
+    error(404, "Status not found");
23
+
24
+  if ($confirm != 0 && $confirm != 1)
25
+    error(422, "Bad confirmation value");
26
+
27
+  $u = database_exec("SELECT `id` FROM users WHERE `id` = ".
28
+    "(SELECT `user` FROM tokens WHERE `token` = :token)",
29
+    array(":token" => $token))->fetch();
30
+
31
+  if (database_exec("SELECT `id` FROM confirms WHERE `status` = :status ".
32
+    "AND `user` = :user AND `confirmation` = :confirm",
33
+    array(":status" => $id, ":user" => $u["id"], ":confirm" => $confirm))
34
+    ->fetch() !== false)
35
+    error(409, "Can not confirm twice with same value");
36
+
37
+  database_exec("INSERT INTO confirms (`confirmation`, `status`, `user`)".
38
+    "VALUES(:confirm, :status, :user)", array(":confirm" => $confirm,
39
+    ":status" => $id, ":user" => $u["id"]));
40
+
41
+  echo json_encode(array("user_id" => intval($u["id"]),
42
+    "status_id" => intval(database_get()->lastInsertId()),
43
+    "confirmation" => (bool)$confirm));
18 44
 }
19 45
 
20 46
 function status_create()

Loading…
Cancel
Save