-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.php
53 lines (44 loc) · 1.15 KB
/
auth.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
<?php
class auth
{
private $userid;
private $role;
public function __construct()
{
$this->userid = isset($_SESSION["userid"]) ? $_SESSION["userid"] : null;
if($this->userid == null){$this->role = 'g';}
else{
$db = dbrepo::getdbinstance();
$this->role = $db->getrolefromuserid($this->userid)->role;
$db->closeDB();
}
}
public function getUserid()
{
return $this->userid;
}
public function getLogedin(){
return ($this->userid != null);
}
public function getRole()
{
return $this->role;
}
public function logoff()
{
unset($_SESSION["userid"]);
$this->userid = null;
}
public function login($email,$password)
{
$db = dbrepo::getdbinstance();
$this->userid = $db->authenticateUser($email,$password);
$_SESSION["userid"] = $this->userid;
if($this->userid == null){$this->role = 'G';}
else{
$db = dbrepo::getdbinstance();
$this->role = $db->getrolefromuserid($this->userid)->role;
$db->closeDB();
}
}
}