-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
119 lines (93 loc) · 4.65 KB
/
test.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
<?php
class User extends Db {
public function jsonMessage($msg){
echo '{"data": [';
$response = array();
$response['message'] = $msg;
echo json_encode($response);
echo ']}';
}
protected function signUpUser($firstName,$lastName,$email,$password){
if(empty($firstName) || empty($lastName) || empty($email) || empty($password)){
$this->jsonMessage("Feilds Can't be empty");
}else{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->jsonMessage("Invalid email format");
}else{
if(strlen($password) <6 || strlen($password) > 15 ){
$this->jsonMessage("Password must be between 6 to 15 characters");
}else{
$query = "SELECT * FROM `users` WHERE email=?";
$result = $this->connect()->prepare($query);
$result->execute([$email]);
if($result->rowCount() > 0){
$this->jsonMessage("Email already exist!");
}else{
$query = "INSERT INTO `users` (`user_id`, `firstName`, `lastName`, `email`, `password`) VALUES (NULL, ?, ?, ?, ?)";
$result = $this->connect()->prepare($query);
$result->execute([$firstName,$lastName,$email,$password]);
$this->jsonMessage("success");
}
}
}
}
}
protected function loginUser($email,$password){
$query = "SELECT * FROM `users` WHERE email=?";
$result = $this->connect()->prepare($query);
$result->execute([$email]);
if($result->rowCount() < 1){
$this->jsonMessage("Email not registerd!");
}else{
$query = "SELECT * FROM `users` WHERE email=? AND password=?";
$result = $this->connect()->prepare($query);
$result->execute([$email,$password]);
if($result->rowCount() < 1){
$this->jsonMessage("Incorrect Password!");
}else{
$this->jsonMessage("success");
}
}
}
protected function checkProductCart($product_image,$user_email){
$query = "SELECT * FROM `cart` WHERE `product_image`=? and `user_email`=?";
$reslut = $this->connect()->prepare($query);
$reslut->execute([$product_image,$user_email]);
return $reslut->rowCount();
}
protected function insertIntoCart($product_image,$product_quantity,$product_price,$user_email){
$count = $this->checkProductCart($product_image,$user_email);
if($count < 1){
$query = "INSERT INTO `cart` (`cart_id`, `product_image`, `product_quantity`, `product_price`,`user_email`) VALUES (NULL, ?, ?, ?,?)";
$reslut = $this->connect()->prepare($query);
$reslut->execute([$product_image,$product_quantity,$product_price,$user_email]);
}else{
$query = "UPDATE cart set `product_quantity` = `product_quantity` + ? WHERE `product_image` = ? and `user_email` = ?";
$reslut = $this->connect()->prepare($query);
$reslut->execute([$product_quantity,$product_image,$user_email]);
}
}
protected function checkProductWishlist($product_image,$user_email){
$query = "SELECT * FROM `wishlist` WHERE `product_image`=? and `user_email`=?";
$reslut = $this->connect()->prepare($query);
$reslut->execute([$product_image,$user_email]);
return $reslut->rowCount();
}
protected function insertIntoWishlist($product_image,$product_quantity,$product_price,$user_email){
$count = $this->checkProductWishlist($product_image,$user_email);
if($count < 1){
$query = "INSERT INTO `wishlist` (`cart_id`, `product_image`, `product_quantity`, `product_price`,`user_email`) VALUES (NULL, ?, ?, ?,?)";
$reslut = $this->connect()->prepare($query);
$reslut->execute([$product_image,$product_quantity,$product_price,$user_email]);
}else{
$query = "UPDATE wishlist set `product_quantity` = `product_quantity` + ? WHERE `product_image` = ? and `user_email` = ?";
$reslut = $this->connect()->prepare($query);
$reslut->execute([$product_quantity,$product_image,$user_email]);
}
}
protected function removeWishlist($product_image,$user_email){
$query = "DELETE FROM `wishlist` WHERE `product_image` = ? and `user_email` = ?";
$reslut = $this->connect()->prepare($query);
$reslut->execute([$product_image,$user_email]);
}
}