visitors as friends in envs #17

This commit is contained in:
m1k1o 2020-07-05 19:41:45 +02:00
parent 927d769045
commit 5d300a80ad
3 changed files with 29 additions and 4 deletions

View file

@ -66,6 +66,11 @@ class Config
$value = false;
}
// Associative arrays in environment variables
if($key === 'visitor' || $key === 'friends'){
$value = self::parse_env_assoc($value);
}
self::$_settings[$key] = $value;
}
}
@ -92,6 +97,22 @@ class Config
return $value;
}
// Parse associative array from string in format key:value
private static function parse_env_assoc($data){
if(!preg_match_all("/([^\s]+):([^\s]+)/s", $data, $matches)){
return [];
}
list($_, $keys, $values) = $matches;
$array = [];
foreach ($values as $key => $value) {
$array[$keys[$key]] = $value;
}
return $array;
}
}
class ConfigException extends Exception {}

View file

@ -35,7 +35,11 @@ class user
return ["logged_in" => true, "is_visitor" => false];
}
$visitors = Config::get_safe("visitor", []);
// Legacy: Visitors and Friends.
$visitors = array_merge(
Config::get_safe("friends", []),
Config::get_safe("visitor", [])
);
if(!empty($visitors) && isset($visitors[$nick]) && $visitors[$nick] === $pass){
$_SESSION[User::SESSION_NAME] = 'visitor';
return ["logged_in" => false, "is_visitor" => true];

View file

@ -39,9 +39,9 @@ force_login = true
nick = demo
pass = demo
[visitors]
;visitor[user] = pass
;visitor[user] = pass
[friends]
;friends[user] = pass
;friends[user] = pass
[directories]
images_path = data/i/