/
do_login.php
44 lines (27 loc) · 904 Bytes
/
do_login.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
<?PHP
session_start();
require('lib/db.php');
require("lib/class.base.php");
require("lib/class.cart.php");
require("lib/class.customer.php");
// Recieves JSON-data from client
$json = file_get_contents('php://input');
// Transfering json-string to PHP-array
$json = json_decode($json, true);
$email = $json["email"];
$password = $json["password"];
$session_id = session_id();
$customer = new Customer(0, $sql);
$customer->email = $email;
$customer->password = $password;
if($customer->login()) {
// setting customer_id to the cart
$cart = new Cart(0, $sql);
$cart->customer_id = $_SESSION['logged_id'];
$cart->session_id = $session_id;
$cart->addCustomerToCart();
echo json_encode("");
} else {
echo json_encode('<p style="padding: 10px; border-radius: 10px; color: white; background-color: rgb(122, 47, 47);">Email and password do not match.</p>');
}
?>