-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser.php
More file actions
47 lines (39 loc) · 1.2 KB
/
user.php
File metadata and controls
47 lines (39 loc) · 1.2 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
<?php
class User {
public $username;
public $password;
public $firstname;
public $lastname;
public $isAdmin; // false normal user; true admin user;
public function login($un, $pass) {
if($this->username === $un && $this->password === md5($pass)) {
$_SESSION['loggedin'] = true;
$_SESSION['user'] = serialize($this);
return true;
} else {
return false;
}
}
public function isAdmin() {
return $this->isAdmin == true;
}
public static function checkPerm() {
$user = unserialize($_SESSION['user']);
if (!$user->isAdmin()) {
die ('No permission to do this operation! <a href="criminal.php"> go back </a>');
}
}
public static function isLogined() {
return (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] !== true);
}
public static function fromRow($row) {
$user = new User;
$user->username = $row['username'];
$user->password = $row['password'];
$user->firstname = $row['firstname'];
$user->lastname = $row['lastname'];
$user->isAdmin = $row['isAdmin'];
return $user;
}
}
?>