-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
60 lines (52 loc) · 1.5 KB
/
Copy pathindex.php
File metadata and controls
60 lines (52 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
(c) Copyright 2019, Pongsakorn Ritrugsa <poundxi@protonmail.com>
This project is licensed under the terms of the MIT license.
*/
// Tell browser this content is in JSON format with UTF-8 encoding.
header('Content-Type: application/json; charset=utf-8');
// Tell browser this API is allow access from any origins (CORS)
header('Access-Control-Allow-Origin: *');
require_once('functions.php');
function do_generate_command() {
// Generate success
echo json_encode([
'idcard' => get_generated_idcard()
]);
}
function do_verify_command() {
// Check idcard request is set & not empty
if ( !empty($_REQUEST['idcard']) ) {
$idcard = $_REQUEST['idcard'];
if (is_13digits($idcard)) {
// Verify success
echo json_encode([
'idcard' => $idcard,
'valid' => is_idcard_valid($idcard)
]);
} else {
make_bad_request("Invalid idcard format (Please specify the idcard that contains 13 digits).");
}
} else {
// No idcard specified.
make_bad_request("No idcard specified.");
}
}
// Check command request is set & not empty
if ( !empty($_REQUEST['command']) ) {
$command = $_REQUEST['command'];
switch ($command) {
case "generate":
do_generate_command();
break;
case "verify":
do_verify_command();
break;
default:
// Unknown command
make_bad_request( sprintf("Unknown command '%s'. Avaliable commands are 'generate' & 'verify'.", $command) );
}
} else {
// No command specified.
make_bad_request("No command specified. Avaliable commands are 'generate' & 'verify'.");
}