Repository navigation
Expand file tree
/
Copy pathPrivilegedUser1.php
More file actions
60 lines (53 loc) · 1.57 KB
/
Copy pathPrivilegedUser1.php
File metadata and controls
60 lines (53 loc) · 1.57 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
<?php
class PrivilegedUser
{
private $roles;
// override User method
public static function getByUsername($username) {
include('dbconfig.php');
//select * from user where email='$user'
$sql = " SELECT * FROM faculty WHERE email = '$username' ";
$stmt = mysqli_query($conn,$sql);
$result = mysqli_fetch_array($stmt);
if ($result)
{
$privUser = new PrivilegedUser();
$privUser->id = $result["id"];
$privUser->name = $result["Name"];
//$privUser->password = $result["password"];
$privUser->email = $username;
$privUser->initRoles($privUser->id);
return $privUser;
}
else
{
return false;
}
}
// populate roles with their associated permissions
protected function initRoles($id)
{
include('dbconfig.php');
$this->roles = array();
$sql = "SELECT t1.role_id, t2.role_name FROM user_role1 as t1
JOIN roles as t2 ON t1.role_id = t2.role_id
WHERE t1.id = '$id' ";
$stmt = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($stmt))
{
$this->roles[$row["role_name"]] = Role::getRolePerms($row["role_id"]);
}
}
// check if user has a specific privilege
public function hasPrivilege($perm)
{
foreach ($this->roles as $role)
{
if ($role->hasPerm($perm))
{
return true;
}
}
return false;
}
}