-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathapi_verification.php
111 lines (80 loc) · 3.14 KB
/
api_verification.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
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
102
103
104
105
106
107
108
109
110
111
<?php
include 'conn.php';
//flag 1 for login
//flag 2 for update register
//flag to check and to execute specific switch case based on flag value sent
$flag = $_POST['flag'];
(int) $flag;
switch ($flag) {
case 1:
//assigning data sent to $Email which can be either email or mobile no in return we'll be sending email only
$Email = $_POST['email'];
$Password = md5($_POST['password']);
$fcm_token = $_POST['fcm_token'];
//creating a query
$query = "SELECT * FROM user WHERE (Email='$Email' OR Mobile='$Email') AND Password = '$Password' AND status=1 ";
$result = mysqli_query($connect, $query);
if($result->num_rows>0){
while ($row = mysqli_fetch_assoc($result)) {
//Update FCM Token
$query2 = "UPDATE `user` SET `fcm_token`='$fcm_token' WHERE `id`='".$row['id']."' ";
$result2 = mysqli_query($connect, $query2);
$json['value'] = 1;
$json['message'] = 'User Successfully LoggedIn';
$json['email'] = $row['Email'];
$json['name'] = $row['Name'];
$json['id'] = $row['id'];
$json['status'] = 'success';
}
}else{
$json['value'] = 0;
$json['message'] = 'Failed to LogIn';
$json['email'] = '';
$json['name'] = '';
$json['id'] = '';
$json['status'] = 'failure';
}
// echo json_encode($json);
// mysqli_close($connect);
break;
//Ends case 1
case 2:
$Name = $_POST['name'];
$Email = $_POST['email'];
$Mobile = $_POST['mobile'];
$Password = md5($_POST['password']);
$fcm_token = $_POST['fcm_token'];
$sqlmax = "SELECT max(id) FROM `user`";
$resultmax = mysqli_query($connect, $sqlmax);
$rowmax = mysqli_fetch_array($resultmax);
if($rowmax[0]==null){
$idnomax=1;
}else{
$idnomax=$rowmax[0]+1;
}
$query = "SELECT * FROM user WHERE Email='$Email'";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result)>0){
$json['value'] = 2;
$json['message'] = ' Email Already Used: ' .$Email;
}else{
$query = "INSERT INTO user (id, Name, Email, Mobile, Password, fcm_token, status) VALUES ('$idnomax','$Name','$Email','$Mobile','$Password','$fcm_token', 1)";
$inserted = mysqli_query($connect, $query);
if($inserted == 1 ){
$json['value'] = 1;
$json['message'] = 'User Successfully Registered';
}else{
$json['value'] = 0;
$json['message'] = 'User Registration Failed';
}
}
// echo json_encode($json);
// mysqli_close($connect);
break;
//Ends case 2
default:
$inserted == 0;
}
echo json_encode($json);
mysqli_close($connect);
?>