-
Notifications
You must be signed in to change notification settings - Fork 782
Closed
Description
Hi, i'm not sure if this has been discussed or not yet, but i feel like user roles is part of the user creation/login process. so with a few tweeks to the database to allow roles to be assigned to a user, we could then have a function in the Auth class to check if they have the required roles to view a view or a controller. here is a quick thrown together example
public static function canUserAccsess($requiredRoles = array()) {
$Count = count($requiredRoles);
$i = 0;
while ($i < $Count) {
$status = (session::get('user_' . $requiredRoles[$i]) ? true : false ) ;
//return true as soon as one of the required roles is present.
if($status == true){
return true;
}
$i++;
}
//of non of them passed then we don't have the roles
return false;
}
And then in the views or where ever we can simply do something like this.
if(Auth::canUserAccsess(['Sales','Admin'])){
echo "We got in!";
}
Metadata
Metadata
Assignees
Labels
No labels