/** * Check if user belongs to the specified role. * * @param Request $request * @param Closure $next * @param string|array $roles * * @return \Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next, $roles) { $accessDenied = true; if (!($user = $this->auth->getActiveUser())) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); return redirect()->route('auth.login'); } if (!is_array($roles)) { $roles = [$roles]; } foreach ($roles as $role) { if (!($role = $this->role->getBySlug($role))) { continue; } if ($user->inRole($role)) { $accessDenied = false; } } if ($accessDenied) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); // Redirect back to the previous page where request was made. return redirect()->back(); } return $next($request); }
/** * The constructor. * * @param \Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface $authRepositoryInterface * @param \Laraflock\Dashboard\Repositories\Permission\PermissionRepositoryInterface $permissionRepositoryInterface * @param \Laraflock\Dashboard\Repositories\Role\RoleRepositoryInterface $roleRepositoryInterface * @param \Laraflock\Dashboard\Repositories\User\UserRepositoryInterface $userRepositoryInterface * @param \Laraflock\Dashboard\Repositories\Module\ModuleRepositoryInterface $moduleRepositoryInterface */ public function __construct(AuthRepositoryInterface $authRepositoryInterface, PermissionRepositoryInterface $permissionRepositoryInterface, RoleRepositoryInterface $roleRepositoryInterface, UserRepositoryInterface $userRepositoryInterface, ModuleRepositoryInterface $moduleRepositoryInterface) { $viewNamespace = config('laraflock.dashboard.viewNamespace'); $this->authRepositoryInterface = $authRepositoryInterface; $this->permissionRepositoryInterface = $permissionRepositoryInterface; $this->roleRepositoryInterface = $roleRepositoryInterface; $this->userRepositoryInterface = $userRepositoryInterface; $user = $this->authRepositoryInterface->getActiveUser(); view()->share(['activeUser' => $user, 'viewNamespace' => $viewNamespace, 'modules' => $moduleRepositoryInterface]); }
/** * Check if user has permission. * * @param Request $request * @param Closure $next * @param string|array $permission * * @return \Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next, $permission) { // Check to see if the user is logged in. if (!($user = $this->auth->getActiveUser())) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); return redirect()->route('auth.login'); } if (!$user->hasAccess($permission)) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); // Redirect back to the previous page where request was made. return redirect()->back(); } return $next($request); }
/** * Check if user belongs to the specified role. * * @param Request $request * @param Closure $next * @param string|array $role * * @return \Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next, $role) { if (!($user = $this->auth->getActiveUser())) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); return redirect()->route('auth.login'); } if (!($role = $this->role->getBySlug($role))) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); // Redirect back to the previous page where request was made. return redirect()->back(); } if (!$user->inRole($role)) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); // Redirect back to the previous page where request was made. return redirect()->back(); } return $next($request); }
/** * Check if user has permission. * * @param Request $request * @param Closure $next * @param string|array $permissions * * @return \Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next, $permissions) { $accessDenied = true; if (!($user = $this->auth->getActiveUser())) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); return redirect()->back(); } if (!is_array($permissions)) { $permissions = [$permissions]; } foreach ($permissions as $permission) { if ($user->hasAccess($permission)) { $accessDenied = false; } } if ($accessDenied) { Flash::error(trans('dashboard::dashboard.flash.access_denied')); return redirect()->back(); } return $next($request); }