X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/9c6d004933372ae88ff79a7625a3628aa447a5e6..ead5bed24e07383fbcf783c3b5c70a755dbc1982:/auth.inc.php diff --git a/auth.inc.php b/auth.inc.php index 4d9b29e..3901609 100644 --- a/auth.inc.php +++ b/auth.inc.php @@ -3,9 +3,9 @@ date_default_timezone_set('Europe/Amsterdam'); class User { - function __construct($dir) + function __construct($dir, $existing = TRUE) { - if (!file_exists($dir)) { + if (!file_exists($dir) and $existing) { throw new Exception("Gebruiker niet gevonden in $dir"); } $this->dir = $dir; @@ -29,7 +29,11 @@ class User function html() { - return $this->name ?: $this->login; + $name = htmlspecialchars($this->login); + if ($this->name and $this->name != $name) { + $name = "{$this->name} @$name"; + } + return $name; } function email() @@ -37,9 +41,24 @@ class User return rtrim(@file_get_contents("{$this->dir}/email.txt")); } - function admin() + function admin($permission = NULL) { - return @file_exists("{$this->dir}/.admin"); + if (isset($permission)) { + if (!$this->admin) { + return FALSE; # empty results + } + preg_match_all('{[ /]}', $permission, $parts, PREG_OFFSET_CAPTURE); + foreach ($parts[0] as $part) { + if (isset($this->admin[substr($permission, 0, $part[1])])) { + return TRUE; # partial match + } + } + return isset($this->admin[$permission]); # check level + } + if (!@file_exists("{$this->dir}/.admin")) { + return FALSE; # not an admin + } + return array_fill_keys(explode("\n", file_get_contents("{$this->dir}/.admin")), TRUE); } function seen()