-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebsiteUser.php
55 lines (42 loc) · 1.47 KB
/
WebsiteUser.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
<?php
require_once('./dao/abstractDAO.php');
class WebsiteUser extends abstractDAO {
private $username;
private $password;
private $authenticated = false;
function __construct() {
try{
parent::__construct();
} catch(mysqli_sql_exception $e){
throw $e;
}
}
public function authenticate($username, $password){
$loginQuery = "SELECT * FROM adminusers WHERE Username = ? AND Password = ?";
$stmt = $this->mysqli->prepare($loginQuery);
$stmt->bind_param('ss', $username, $password);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows == 1){
$this->username = $username;
$this->password = $password;
$this->authenticated = true;
$this->getUserData($username);
}
$stmt->free_result();
}
public function getUserData($username){
$result = $this->mysqli->query("SELECT AdminID, lastlogin from adminUsers WHERE username='$username'");
$user_data = mysqli_fetch_array($result);
$count_row = $result->num_rows;
if ($count_row == 1) {
mysqli_query("UPDATE adminUsers set lastlogin = CURRENT_DATE WHERE username='$username'");
$_SESSION['AdminID'] = $user_data['AdminID'];
$_SESSION['lastlogin'] = $user_data['lastlogin'];
}
}
public function isAuthenticated(){
return $this->authenticated;
}
}
?>