-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
92 lines (73 loc) · 2.14 KB
/
api.php
File metadata and controls
92 lines (73 loc) · 2.14 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
// Do not answer on any request except POST-Request.
if ($_SERVER['REQUEST_METHOD'] != "POST") {
http_response_code(405)
?>
<!DOCTYPE html>
<html>
<head>
<title>Cevi-Logo Generator: API</title>
<meta name="og:image" content="https://logo.cevi.ch/assets/images/logo.svg">
<meta name="description" content="Logo Generator für dein eigenes Cevi-Logo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h1>This method is not allowed</h1>
</body>
</html>
<?php
// quit any request except POST.
return;
}
if (!isset($_POST['session_id'])) {
http_response_code(400);
echo '[1] data is missing.';
return;
}
require_once 'ApiHelper.php';
$apiHelper = new ApiHelper();
$session_id = $_POST['session_id'];
if (!$apiHelper->checkSessionId($session_id)) {
http_response_code(403);
echo 'Invalid Data.';
return;
}
if (!isset($_POST['type'])) {
http_response_code(400);
echo '[2] data is missing.';
return;
}
$type = $_POST['type'];
if (!isset($_POST['logo_left']) || !isset($_POST['logo_right']) || !isset($_POST['logo_right_second'])) {
http_response_code(400);
echo '[3] data is missing.';
return;
}
if ($type === 'share' && isset($_POST['claim_left']) && isset($_POST['claim_right'])) {
$apiHelper->saveDataShare($_POST);
}
if (!isset($_POST['image_type'])) {
http_response_code(400);
echo '[4] data is missing.';
return;
}
if ($type === 'logo') {
$apiHelper->saveDataLogo($_POST);
}
else if ($type === 'claim') {
if (!isset($_POST['claim_left']) || !isset($_POST['claim_right'])) {
http_response_code(400);
echo '[5] data is missing.';
return;
}
$apiHelper->saveDataClaim($_POST);
}
http_response_code(200);
header('Content-Type: application/json; charset=utf-8');
$return = [
'status' => 200,
'type' => $type,
'message' => 'success'
];
echo json_encode($return);
?>