visitors as friends in envs #17
This commit is contained in:
parent
927d769045
commit
5d300a80ad
3 changed files with 29 additions and 4 deletions
|
@ -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 {}
|
|
@ -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];
|
||||
|
|
|
@ -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/
|
||||
|
|
Loading…
Reference in a new issue