public function testCheck() { $this->assertTrue(AccessHandler::check('admin', 'editor'), 'Admin users should have access to editor modules'); $this->assertTrue(AccessHandler::check('editor', 'user'), 'Admin should have access to users modules'); $this->assertTrue(AccessHandler::check('admin', 'admin'), 'Admin users should have access to admin modules'); $this->assertFalse(AccessHandler::check('user', 'admin'), 'Users should not have access to admin modules, routes, etc.'); }
public static function getRoleName($role) { if (!self::$roleNames) { self::$roleNames = array(t('Guest'), t('User'), t('Superuser'), t('Admin'), t('System admin')); } return self::$roleNames[$role]; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string $role * @return mixed */ public function handle($request, Closure $next, $role) { $user = auth()->user(); if (!AccessHandler::check($user->role, $role)) { abort(404); } return $next($request); }
/** * Stores given user object within database * @param string $access_token * @param stdClass $user */ public function store($access_token, $user) { AccessHandler::validate($access_token); // parse the user object, which is given as stdClass: // eg: $user = MyUserClass::fromJson($user); // And for the sake of example, return the sent user object $user->recieved = date('Y-m-d H:i:s'); return $user; }