ranks of users

This commit is contained in:
2018-11-10 15:34:17 -06:00
parent 1de4dc509d
commit e2960cd237
2 changed files with 26 additions and 16 deletions

View File

@@ -16,13 +16,24 @@ class RequireRole
*/
public function handle($request, Closure $next, $role)
{
$confirmed = false;
$ranking = array([
'None' => 0,
'Guest' => 1,
'User' => 2,
'Admin' => 3,
]);
$check = DB::table('user_roles')->where('character_id', auth()->user()->character_id)->get(['role']);
printf($check);
printf($role);
if($check === $role) {
$confirmed = true;
} else {
$confirmed = false;
foreach($ranking as $rank => $value) {
if($role === $check['role']) {
$confirmed = true;
break;
} else {
if($rank[$check['role']] > $rank[$check['role']]) {
$confirmed = true;
break;
}
}
}
abort_unless(auth()->check() && $confirmed, 403, "You don't have permissions to access this area!");