-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
101 lines (92 loc) · 2.6 KB
/
Copy pathapi.php
File metadata and controls
101 lines (92 loc) · 2.6 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
93
94
95
96
97
98
99
100
101
<?php
include ('includes/model.php');
class api extends REST {
public function processApi() {
if (isset ( $_REQUEST ['rquest'] )) {
$func = strtolower ( trim ( str_replace ( "/", "", $_REQUEST ['rquest'] ) ) );
if (( int ) method_exists ( $this, $func ) > 0) {
$this->$func ();
} else {
$this->response ( 'Page not found', 404 );
}
} else {
$this->response ( 'Page not found', 404 );
}
// If the method not exist with in this class, response would be "Page not found".
}
function register() {
if ($this->get_request_method () != "POST") {
$this->response ( 'Not Acceptable', 406 );
} else {
// Get Data From Json
$input = json_decode ( file_get_contents ( 'php://input' ), true );
// Make New Object
$model = new model ();
// Check Empty Or not
if (! empty ( $input ['username'] ) && ! empty ( $input ['password'] )) {
// Register Data
$exe_status = $model->register ( $input ['username'], $input ['password'] );
if ($exe_status) {
$error = array (
'status' => "SUCCESS",
"msg" => "Insert Successfully.."
);
$this->response ( $this->json ( $error ), 200 );
} else {
$error = array (
'status' => "FAILED",
"msg" => "Something Wrong.."
);
$this->response ( $this->json ( $error ), 400 );
}
} else {
$error = array (
'status' => "FAILED",
"msg" => "Invalid Email address or Password"
);
$this->response ( $this->json ( $error ), 400 );
// If Empty
}
}
} // Register
function login() {
if ($this->get_request_method () != "POST") {
$this->response ( 'Not Acceptable', 406 );
}
else {
// Get Data From Json
$input = json_decode ( file_get_contents ( 'php://input' ), true );
// Make New Object
$model = new model ();
// Check Empty Or not
if (! empty ( $input ['username'] ) && ! empty ( $input ['password'] )) {
// Register Data
$user_detail = $model->login ( $input ['username'], $input ['password'] );
if ($user_detail != null) {
$error = array (
'status' => "SUCCESS",
"msg" => "Insert Successfully..",
"data" => $user_detail
);
$this->response ( $this->json ( $error ), 200 );
}
} else {
$error = array (
'status' => "FAILED",
"msg" => "Invalid Email address or Password"
);
$this->response ( $this->json ( $error ), 400 );
// If Empty
}
}
} // login
// Encode array into JSON
private function json($data) {
if (is_array ( $data )) {
return json_encode ( $data );
}
}
} // class api
$api = new api ();
$api->processApi ();
?>