-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
98 lines (81 loc) · 1.88 KB
/
Copy pathUser.php
File metadata and controls
98 lines (81 loc) · 1.88 KB
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
<?php
require_once('Database.php');
class User
{
private $connection;
public function __construct()
{
$database = new Database();
$this->connection = $database->connect();;
}
public function runQuery($sql)
{
$stmt = $this->connection->prepare($sql);
return $stmt;
}
public function signup($fname, $lname, $username, $password, $creditCard, $address)
{
try
{
//$new_password = password_hash($upass, PASSWORD_DEFAULT);
$stmt = $this->connection->prepare("INSERT INTO customer(First_Name,Last_Name,Username,Password,Credit_Card, Address)
VALUES(:fname, :lname, :username, :password, :creditcard, :address)");
$stmt->bindparam(":fname", $fname);
$stmt->bindparam(":lname", $lname);
$stmt->bindparam(":username", $username);
$stmt->bindparam(":password", $password);
$stmt->bindparam(":creditcard", $creditCard);
$stmt->bindparam(":address", $address);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function login($uname, $pass)
{
try
{
$stmt = $this->connection->prepare("SELECT * FROM customer WHERE Username = :uname ");
$stmt->execute(array(':uname'=>$uname));
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if($pass === $result['Password'])
{
$_SESSION['user'] = $result;
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function isLoggedin()
{
if(isset($_SESSION['user']))
{
return true;
}
return false;
}
public function redirect($url)
{
header("Location: $url");
}
public function logout()
{
session_destroy();
unset($_SESSION['user']);
return true;
}
}
?>