From 14333f2dd829593a0d3c578ccdd23693ab04a3ef Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 7 Jul 2018 22:27:19 +0200 Subject: [PATCH] login/list: retrieve optional user data on demand Generic interface to run methods for missing variables. Provides delay and caching to prevent unnecessary disk access. --- auth.inc.php | 10 ++++++++++ login/list.php | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/auth.inc.php b/auth.inc.php index e4e8bb9..af02ec3 100644 --- a/auth.inc.php +++ b/auth.inc.php @@ -8,6 +8,16 @@ class User $this->dir = $dir; $this->login = basename($dir); } + + function __get($col) + { + return $this->$col = $this->$col(); # run method and cache + } + + function name() + { + return @file_get_contents("{$this->dir}/name.txt"); + } } function login_password_verify($input, $test) diff --git a/login/list.php b/login/list.php index 86e8daf..eee2dc5 100644 --- a/login/list.php +++ b/login/list.php @@ -5,9 +5,7 @@ $users = glob("$basepath/*/"); if (!$users) return; foreach ($users as $col => $userdir) { - $user = new User($userdir); - $user->name = @file_get_contents("{$user->dir}/name.txt"); - $users[$col] = $user; + $users[$col] = new User($userdir); } print '