-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.php
More file actions
43 lines (35 loc) · 1 KB
/
Copy pathutils.php
File metadata and controls
43 lines (35 loc) · 1 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
<?php
require_once('conn.php');
function generateToken() {
$s = '';
for($i = 1; $i<=16; $i++) {
$s .= chr(rand(65, 90));
}
return $s;
}
function getUserFromUsername($username) {
global $conn;
$sql = sprintf("SELECT * From peipei_users WHERE username = '%s'", $username);
$result = $conn->query($sql);
$row = $result->fetch_assoc();
return $row;
}
function escape($str) {
return htmlspecialchars($str, ENT_QUOTES);
}
function hasPermission($user, $action, $comment) {
if ($user["roles"] === "ADMIN") {
return true;
}
if ($user["roles"] === "NORMAL") {
if ($action === "create") return true;
return $comment["username"] === $user["username"];
}
if ($user["roles"] === "BANNED") {
return $action !== "create";
}
}
function isAdmin($user) {
return $user["roles"] === "ADMIN";
}
?>