forked from fa/breadcrumb-the-shire
baseline
This commit is contained in:
27
lib/Support/helpers/auth.php
Normal file
27
lib/Support/helpers/auth.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
function accountUrl(): string
|
||||
{
|
||||
$user = $_SESSION['user'] ?? [];
|
||||
$uuid = (string) ($user['uuid'] ?? '');
|
||||
return $uuid !== '' ? lurl('profile') : lurl('login');
|
||||
}
|
||||
|
||||
function can(string $permissionKey): bool
|
||||
{
|
||||
$userId = (int) ($_SESSION['user']['id'] ?? 0);
|
||||
if ($userId <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (!class_exists('MintyPHP\\Service\\PermissionService')) {
|
||||
return false;
|
||||
}
|
||||
$keys = \MintyPHP\Service\PermissionService::getCachedPermissions($userId);
|
||||
if (!$keys) {
|
||||
$keys = \MintyPHP\Service\PermissionService::getUserPermissions($userId);
|
||||
if (!$keys) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return in_array($permissionKey, $keys, true);
|
||||
}
|
||||
Reference in New Issue
Block a user