예제 #1
0
 /**
  * Check if a user is logged in.
  *
  * @param Request $request
  * @param Closure $next
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function handle(Request $request, Closure $next)
 {
     if (!$this->auth->check()) {
         Flash::error(trans('dashboard::dashboard.flash.access_denied'));
         return redirect()->route('auth.login');
     }
     return $next($request);
 }
 /**
  * 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);
 }
예제 #3
0
 /**
  * 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->slug($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);
 }
예제 #4
0
 /**
  * Create default Group and User
  *
  * @return void
  */
 protected function createDefaultUser()
 {
     // Get the user configuration data.
     $config = $this->user;
     // Create default permission.
     $this->permissionRepo->create(['name' => 'Administrator (Full Access)', 'slug' => 'admin'], false);
     // Create default role.
     $this->roleRepo->create(['name' => 'Registered', 'slug' => 'registered'], false);
     // Create the admin role.
     $role = $this->roleRepo->create(['name' => 'Administrator', 'slug' => 'administrator', 'permissions' => ['admin' => true]], false);
     // Create the user.
     $user = $this->authRepo->registerAndActivate(['email' => array_get($config, 'email'), 'first_name' => array_get($config, 'first'), 'last_name' => array_get($config, 'last'), 'password' => array_get($config, 'pass'), 'role' => 'administrator'], false);
     // Attach user to admin role.
     $role->users()->attach($user);
 }