Repository navigation
add on_groups in helper auth for manage routing Codeigniter 4 #597
coijiryuna
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
on AuthorizeInterface.php
Im add
public function nameGroup(int $userId);
on FlatAuthorization.php
Im add
public function nameGroup(int $userId)
{
if ($userId === 0) {
return false;
}
$userGroups = $this->groupModel->getGroupsForName((int) $userId);
if (empty($userGroups)) {
return false;
}
return $userGroups;
// return true;
}
on GroupModel.php
im add
public function getGroupsForName(int $userId)
{
if (null === $found = cache("{$userId}_groups")) {
$found = $this->join('auth_groups_users', 'auth_groups_users.group_id = auth_groups.id', 'left')
->where('user_id', $userId)->first();
cache()->save("{$userId}_groups", $found, 300);
}
return $found;
}
on auth_helper.php
im add
if (!function_exists('on_groups')) {
/**
* Example:
* on_groups()->name;
* on_groups()->id;
* on_groups()->description;
*
* @PARAM mixed $groups
*/
function on_groups()
{
$authenticate = service('authentication');
$authorize = service('authorization');
if ($authenticate->check()) {
return $authorize->nameGroup($authenticate->id());
}
return false;
}
}
All reactions