/
functions.users.php
61 lines (58 loc) · 1.23 KB
/
functions.users.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
56
57
58
59
60
61
<?php
/*
* @summary Returns the path to a given user's data directory
*
* @param $username - The user's name
*
* @returns The path to the given user's data directory
*/
function user_dirname($username)
{
return "./data/users/$username/";
}
/*
* @summary Checks to see if a user exists.
*
* @param $username - The username to check.
*
* @returns Whether the user exists.
*/
function user_exists($user_to_check)
{
//changes commented out global getjson
//global getjson;
$userlist = getjson("data/userlist.json");
foreach($userlist as $user_in_list)
{
if($user_to_check == $user_in_list)
return true;
}
return false;
}
/*
* @summary Determines whether a user is an administrator.
*
* @param $username - The username to check.
*
* @returns Whether the user is an admin.
*/
function user_isadmin($username)
{
$isadmin = trim(file_get_contents(user_dirname($username) . "isadmin"));
if($isadmin == "true")
return true;
else
return false;
}
/*
* @summary Get a user's public key.
*
* @param $username = The username for which to fetch the public key.
*
* @returns The given username's public key.
*/
function user_publickey($username)
{
return trim(file_get_contents(user_dirname($username) . "publickey"));
}
?>