-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.php
65 lines (54 loc) · 1.49 KB
/
common.php
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
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token , Authorization');
require_once("./api/database.php");
require_once("./api/validation.php");
require_once("./api/common.php");
function validation_at_first(){
if($_SERVER["REQUEST_METHOD"]!="POST"){
$data=array();
$data["code"]="3001";
$data["message"]="Requests must be POST";
echo json_encode($data);
return 0;
}
$json = file_get_contents('php://input');
$json_data=json_decode($json,true);
if(
(isset($json_data["data"])==false) ||
(empty($json_data["data"])==true) ||
(isset($json_data["action"])==false) ||
(empty($json_data["action"])==true)
){
$data=array();
$data["code"]="3002";
$data["message"]="Required fields are not found ";
echo json_encode($data);
return 0;
}
$action=$json_data["action"];
$data=$json_data["data"];
$objValidation=new Validation();
$avaliadle_action=array(
"change-password"
);
if(
($objValidation->validValues($avaliadle_action,$action)==false)
){
$data=array();
$data["code"]="3006";
$data["message"]="Can not find requested action";
echo json_encode($data);
return 0;
}
$objCommon=new Common();
$objCommon->data=$data;
if($action=="change-password"){
$objCommon->change_password();
}
}
validation_at_first();
?>