From f1c36fdeb1802d536f1c5fcf8889f70604adab61 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Thu, 27 Dec 2018 00:55:58 -0700 Subject: [PATCH] Add getRequestUser() function --- api/functions.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/functions.php b/api/functions.php index 7cd1706..530f011 100644 --- a/api/functions.php +++ b/api/functions.php @@ -75,6 +75,18 @@ function authenticate(): bool { return true; } +/** + * Get the User whose credentials were used to make the request. + */ +function getRequestUser(): User { + global $VARS; + if (!empty($_SERVER['PHP_AUTH_USER'])) { + return User::byUsername($_SERVER['PHP_AUTH_USER']); + } else { + return User::byUsername($VARS['username']); + } +} + function checkVars($vars, $or = false) { global $VARS; $ok = [];