* Get a single user’s info (admin flag, TOTP status, profile picture). */
(string $username)
| 993 | * Get a single user’s info (admin flag, TOTP status, profile picture). |
| 994 | */ |
| 995 | public static function getUser(string $username): array |
| 996 | { |
| 997 | self::ensureUserCaseMigration(); |
| 998 | $usersFile = USERS_DIR . USERS_FILE; |
| 999 | if (!file_exists($usersFile)) { |
| 1000 | return []; |
| 1001 | } |
| 1002 | |
| 1003 | foreach (file($usersFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { |
| 1004 | $parts = explode(':', $line); |
| 1005 | if (strcasecmp($parts[0], $username) !== 0) { |
| 1006 | continue; |
| 1007 | } |
| 1008 | $isAdmin = (isset($parts[2]) && $parts[2] === '1'); |
| 1009 | $totpEnabled = !empty($parts[3]); |
| 1010 | $pic = isset($parts[4]) ? $parts[4] : ''; |
| 1011 | |
| 1012 | if ($pic !== '') { |
| 1013 | $pic = fr_normalize_profile_pic_url($pic); |
| 1014 | } |
| 1015 | |
| 1016 | return [ |
| 1017 | 'username' => $parts[0], |
| 1018 | 'isAdmin' => $isAdmin, |
| 1019 | 'totp_enabled' => $totpEnabled, |
| 1020 | 'profile_picture' => $pic, |
| 1021 | ]; |
| 1022 | } |
| 1023 | |
| 1024 | return []; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * Persist profile picture URL as 5th field (keeps TOTP secret intact). |
no test coverage detected