-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
117 lines (106 loc) · 2.32 KB
/
action.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
112
113
114
115
116
117
<?php
include "connection.php";
session_start();
$sPostData = file_get_contents("php://input");
$oPostData = json_decode($sPostData);
$sActionID= $oPostData->action_id;
if(isset($_POST['action_id']))
{
$sActionID=$_POST['action_id'];
}
switch($sActionID)
{
case 'login':
$Username = $oPostData->username;
$Password = $oPostData->password;
$sQuery = "SELECT * FROM user WHERE username='$Username' AND password='$Password'";
$oRecord = $oConnection->query($sQuery);
$row = $oRecord->fetch();
$count = $oRecord->rowCount();
if( $count>0 )
{
$_SESSION['userID']=$row['id'];
$_SESSION['username']=$row['username'];
echo json_encode(array(
"status" => 1,
"user_id" => $_SESSION['userID']
));
}
else
{
echo json_encode(array(
"status" => 0
));
}
break;
case 'register':
$Username = $oPostData->username;
$Password = $oPostData->password;
$FirstName=$oPostData->firstname;
$LastName=$oPostData->lastname;
$Email=$oPostData->email;
$sQuery = "INSERT INTO user (firstname, lastname, username, password, email) VALUES (:firstname, :lastname, :username, :password, :email)";
$oStatement = $oConnection->prepare($sQuery);
$oData = array(
'firstname' => $FirstName,
'lastname' => $LastName,
'username' => $Username,
'password' => $Password,
'email' => $Email
);
try
{
//$oStatement=$oConnection->prepare($sQuery);
$oStatement->execute($oData);
echo 1;
}
catch(PDOException $error)
{
echo $error;
echo 0;
}
break;
case 'add_movie':
$Title = $oPostData->Title;
$Poster = $oPostData->Poster;
$Rating=$oPostData->Rating;
$UserRating=$oPostData->UserRating;
$User_ID=$_SESSION['userID'];
$sQuery = "INSERT INTO movie (title, poster, rating, user_id, user_rating) VALUES (:title, :poster, :rating, :user_id, :user_rating)";
$oStatement = $oConnection->prepare($sQuery);
$oData = array(
'title' => $Title,
'poster' => $Poster,
'rating' => $Rating,
'user_id' => $User_ID,
'user_rating'=> $UserRating
);
try
{
$oStatement->execute($oData);
echo 1;
}
catch(PDOException $error)
{
echo $error;
echo 0;
}
break;
case 'logout':
session_destroy();
break;
case 'check_logged_in':
if(isset($_SESSION['userID'])){
echo json_encode(array(
"status" => 1,
"user_id" => $_SESSION['userID']
));
}
else{
echo json_encode(array(
"status" => 0
));
}
break;
}
?>