mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-21 10:27:27 +08:00
improve user_can()
This commit is contained in:
@@ -1088,7 +1088,10 @@ function user_can($permission, $fail = false, $uid = 0): bool
|
||||
$uid = get_user_id();
|
||||
$log .= ", set current uid: $uid";
|
||||
}
|
||||
if (!$fail && $uid <= 0) {
|
||||
if ($uid <= 0) {
|
||||
if ($fail) {
|
||||
goto FAIL;
|
||||
}
|
||||
do_log("$log, unauthenticated, false");
|
||||
return false;
|
||||
}
|
||||
@@ -1115,6 +1118,7 @@ function user_can($permission, $fail = false, $uid = 0): bool
|
||||
$userCanCached[$permission][$uid] = $result;
|
||||
return $result;
|
||||
}
|
||||
FAIL:
|
||||
do_log("$log, [FAIL]");
|
||||
if (IN_NEXUS && !IN_TRACKER) {
|
||||
global $lang_functions;
|
||||
@@ -1128,6 +1132,8 @@ function user_can($permission, $fail = false, $uid = 0): bool
|
||||
throw new \App\Exceptions\InsufficientPermissionException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function is_donor(array $userInfo): bool
|
||||
{
|
||||
return $userInfo['donor'] == 'yes' && ($userInfo['donoruntil'] === null || $userInfo['donoruntil'] == '0000-00-00 00:00:00' || $userInfo['donoruntil'] >= date('Y-m-d H:i:s'));
|
||||
|
||||
Reference in New Issue
Block a user