-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathUser.php
181 lines (150 loc) · 4.85 KB
/
User.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
require_once 'dbconfig.php';
class USER
{
private $conn;
public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}
public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}
public function lasdID()
{
$stmt = $this->conn->lastInsertId();
return $stmt;
}
public function register($firstname, $lastname, $email, $upass, $code)
{
try {
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO users (firstname, lastname, email, userPass, tokenCode )
VALUES(:firstname, :lastname, :user_mail, :user_pass, :active_code)");
$stmt->bindparam(":firstname", $firstname);
$stmt->bindparam(":lastname", $lastname);
$stmt->bindparam(":user_mail", $email);
$stmt->bindparam(':user_pass', $password);
$stmt->bindparam(":active_code", $code);
$stmt->execute();
return $stmt;
} catch (PDOException $ex) {
echo $ex->getMessage();
}
}
public function login($email, $upass)
{
try {
$stmt = $this->conn->prepare("SELECT * FROM users WHERE email=:email_id");
$userRow = $stmt->fetch(PDO::FETCH_ASSOC);
if ($stmt->rowCount() == 1) {
if ($userRow['userStatus'] == "Y") {
if ($userRow['userPass'] == md5($upass)) {
$_SESSION['userSession'] = $userRow['id'];
return true;
} else {
header("Location: index.php?error");
exit;
}
} else {
header("Location: index.php?inactive");
exit;
}
} else {
header("Location: index.php?error");
exit;
}
} catch (PDOException $ex) {
echo $ex->getMessage();
}
}
public function is_logged_in()
{
if (isset($_SESSION['userSession'])) {
header("Location: $url");
}
}
public function logout()
{
session_destroy();
$_SESSION['userSession'] = false;
}
function send_mail($email, $message, $subject)
{
require '/usr/share/php/libphp-phpmailer/class.phpmailer.php';
require '/usr/share/php/libphp-phpmailer/class.smtp.php';
// require_once('mailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->AddAddress($email);
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->SetFrom('[email protected]', 'Dragon Slayer');
$mail->AddReplyTo("[email protected]", "Dragon Slayer");
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
}
//get public key from id
public function getPublicKey($id, $db)
{
if (empty($id)) {
return false;
}
$query = "SELECT public_key FROM " . $this->table . " WHERE id=:id LIMIT 1";
$stmt = $db->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$results = $stmt->fetchAll();
if (count($results) > 0) {
$row = $results[0];
return $row['public_key'];
} else {
return false;
}
}
//get public key from id
public function getPrivateKey($id, $db)
{
$query = "SELECT private_key FROM " . $this->table . " WHERE id=:id LIMIT 1";
$stmt = $db->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$results = $stmt->fetchAll();
if (count($results) > 0) {
$row = $results[0];
return $row['private_key'];
} else {
return false;
}
}
//get public key from id
public function getAccounts($id, $db)
{
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "SELECT accounts.id, banks.name FROM accounts inner join banks on accounts.bank_id = banks.id WHERE Intern_id=:id ";
$stmt = $db->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$results = $stmt->fetchAll();
if (count($results) > 0) {
$row = $results;
return $row;
} else {
return false;
}
}
//member class ends here
}