/**
  * Get all roles of the current user
  * @return array
  */
 protected function grantedRoles()
 {
     $userRoles = $this->guard->user()->roles->toArray();
     return array_map(function ($roles) {
         return $roles['pivot']['role_id'];
     }, $userRoles);
 }
Example #2
0
 /**
  * Store a newly created snippet in storage.
  *
  * @param SnippetsRequest $request
  * @return Response
  */
 public function store(SnippetsRequest $request, Guard $auth)
 {
     $data = ['user_id' => $auth->user() ? $auth->user()->id : null];
     $snippet = $this->dispatchFrom(StoreNewSnippetCommand::class, $request, $data);
     flash('Snippet was successfully created.');
     return redirect()->route('snippets.show', $snippet->slug->slug);
 }
 /**
  * Authorize the post.
  *
  * @param PostInterface $post
  */
 public function authorize(PostInterface $post)
 {
     if (!$post->isEnabled() && !$this->guard->user()) {
         abort(404);
     }
     $this->authorizer->authorize('anomaly.module.posts::view_drafts');
 }
 /**
  * Authorize the page.
  *
  * @param PageInterface $page
  */
 public function authorize(PageInterface $page)
 {
     /* @var UserInterface $user */
     $user = $this->guard->user();
     /**
      * If the page is not enabled and we
      * are not logged in then 404.
      */
     if (!$page->isEnabled() && !$user) {
         abort(404);
     }
     /**
      * If the page is not enabled and we are
      * logged in then make sure we have permission.
      */
     if (!$page->isEnabled()) {
         $this->authorizer->authorize('anomaly.module.pages::view_drafts');
     }
     /**
      * If the page is restricted to specific
      * roles then make sure our user is one of them.
      */
     $allowed = $page->getAllowedRoles();
     if (!$allowed->isEmpty() && (!$user || !$user->hasAnyRole($allowed))) {
         $page->setResponse($this->response->redirectTo('login'));
     }
 }
Example #5
0
 /**
  * Store a newly created snippet in storage.
  *
  * @param SnippetsRequest $request
  * @return Response
  */
 public function store(SnippetsRequest $request)
 {
     $this->auth->basic('username');
     $data = ['title' => $request->input('title') ?: null, 'user_id' => $this->auth->user() ? $this->auth->id() : null, 'password' => $request->input('password') ?: null, 'mode' => $request->input('mode') ?: 'markdown'];
     $snippet = $this->dispatchFrom(StoreNewSnippetCommand::class, $request, $data);
     return 'http://drk.sh/s/' . $snippet->slug->slug . PHP_EOL;
 }
Example #6
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->check() && $this->auth->user()['status'] === 'student') {
         return $next($request);
     }
     Session::push('messages', 'danger|Vous devez être étudiant pour accéder à cette page');
     return redirect('/');
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user = $this->auth->user();
     if ($user->user_type != SiteConstants::USER_ADMIN) {
         return redirect('auth/logout');
     }
     return $next($request);
 }
Example #8
0
 /**
  * Handle incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // check if this an auth.shield instance
     if ($this->config->get('auth.driver') === 'classid.shield') {
         $this->auth->user();
     }
     return $next($request);
 }
 /**
  * Create a new PreferenceRepositoryInterface instance.
  *
  * @param Guard           $auth
  * @param PreferenceModel $model
  */
 public function __construct(Guard $auth, PreferenceModel $model)
 {
     $this->auth = $auth;
     $this->model = $model;
     $this->preferences = new PreferenceCollection();
     if ($user = $this->auth->user()) {
         $this->preferences = $this->model->belongingToUser($auth->getUser())->get();
     }
 }
 public function show($id, Guard $auth)
 {
     if ($auth->user()->id == $id) {
         $personne = User::findOrFail($id);
         return view('parents.show', compact('personne'));
     }
     $personne = User::findOrFail($auth->user()->id);
     return redirect()->action('UserController@show', $auth->user()->id);
 }
 /**
  * Save activity
  *
  * @param $activity
  * @return bool
  */
 public function save($activity)
 {
     $activity['user_id'] = null;
     $user = $this->auth->user();
     if (isset($user->id)) {
         $activity['user_id'] = $user->id;
     }
     return $this->activity->create($activity) ? true : false;
 }
Example #12
0
 /**
  * @param Post $post
  * @param array $attributes
  * @return static
  */
 public function update($post, array $attributes = array())
 {
     $attributes['created_by'] = $this->user->user()->id;
     if (!isset($attributes['state']) || empty($attributes['state'])) {
         $attributes['state'] = 0;
     }
     $post->update($attributes);
     return $post;
 }
 /**
  * @param UserService    $user
  * @param CountryService $country
  * @param Guard          $auth
  */
 public function __construct(UserService $user, CountryService $countries, Guard $auth)
 {
     $this->middleware('auth');
     $this->user = $user;
     $this->auth = $auth;
     if (!$this->auth->user()->hasRole(['superadmin', 'admin', 'country-admin'])) {
         return redirect('/home')->withError(trans('contract.permission_denied'))->send();
     }
     $this->countries = $countries;
 }
Example #14
0
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         return redirect()->guest('login');
     }
     if ($this->auth->check() && !$this->auth->user()->isAdmin()) {
         App::abort('403');
     }
     return $next($request);
 }
Example #15
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->check()) {
         if ($this->auth->user()->allowRoutes($request->route()->getName())) {
             return $next($request);
         }
         return response('Forbidden.', 403);
     }
     return $next($request);
 }
Example #16
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $importKind = $request->import_task ? $request->import_task->kind()->first() : PosMemberImportKind::find($request->get('kind_id'));
     if (!$importKind || !$importKind->is_enabled) {
         return response()->view('errors.404', [], 404);
     }
     if (!in_array($this->auth->user()->corp, $importKind->allow_corps)) {
         return response()->view('errors.403', [], 403);
     }
     return $next($request);
 }
Example #17
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$this->auth->user()->isAdmin()) {
         $this->auth->logout();
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->to('auth/login');
         }
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$this->auth->check()) {
         flash()->message('Please Log In.');
         return new RedirectResponse(url('auth/login'));
     }
     if (!$this->auth->user()->is_admin) {
         flash()->message('Restricted Access!!!');
         return new RedirectResponse(url('user/dashboard'));
     }
     return $next($request);
 }
Example #19
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $action = $request->route()->getAction();
     if ($this->auth->guest() || !$this->auth->user()->can($action['permission'])) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->route('admin.login');
         }
     }
     return $next($request);
 }
Example #20
0
 public function filter(Route $route, Request $request)
 {
     /** @var \anlutro\Core\Auth\Users\UserModel $user */
     if (!($user = $this->auth->user())) {
         throw new \RuntimeException('auth filter must precede access filter');
     }
     // get an array of function arguments #3 and up
     $params = array_slice(func_get_args(), 2);
     foreach ($params as $access) {
         if (!$user->hasAccess($access)) {
             return $this->makeResponse($request);
         }
     }
 }
Example #21
0
 /**
  * @param User $user
  *
  * @return bool
  */
 public function isUnread(User $user = null)
 {
     if ($user == null) {
         $user = $this->guard->user();
     }
     $participantData = $this->wrappedObject->participants->find($user->id)->pivot;
     if ($participantData->last_read == null) {
         return true;
     }
     if ($participantData->last_read < $this->wrappedObject->lastMessage->created_at) {
         return true;
     }
     return false;
 }
 /**
  * Handle the command.
  *
  * @return array
  */
 public function handle()
 {
     $nav = [];
     /* @var UserInterface $user */
     $user = $this->guard->user();
     /**
      * Loop through the modules and build a navigation
      * array with the basic information available.
      *
      * Keep it generic but helpful.
      */
     foreach ($this->modules->enabled() as $module) {
         /**
          * If the group is set to false then
          * skip it - no backend navigation.
          */
         if ($module instanceof Module && $module->getNavigation() === false) {
             continue;
         }
         /**
          * If the user does not have access to anything
          * in the addon then don't add it to the navigation.
          */
         if ($this->config->get($module->getNamespace('permissions')) && !$user->hasPermission($module->getNamespace('*'))) {
             continue;
         }
         // Build the required data.
         $url = $this->getUrl($module);
         $title = $this->getTitle($module);
         $group = $this->getGroup($module);
         $active = $this->getActive($module);
         $item = compact('url', 'title', 'group', 'active');
         /**
          * If the module defined a $navigation property it
          * get's put into a dropdown of the same name.
          *
          * Otherwise just lop it onto the navigation array.
          */
         if ($group) {
             $this->addItemToGroup($nav, $item, $module);
         } else {
             $this->addItem($nav, $item, $module);
         }
     }
     // Finish up formatting.
     $this->finish($nav);
     return $nav;
 }
 /**
  * Handle the command.
  *
  * @param Guard $auth
  */
 public function handle(Guard $auth)
 {
     /* @var UserInterface|null $user */
     $user = $auth->user();
     /* @var PageInterface $page */
     foreach ($this->pages as $key => $page) {
         $roles = $page->getAllowedRoles();
         /**
          * If there are role restrictions
          * but no user is signed in then
          * we can't authorize anything!
          */
         if (!$roles->isEmpty() && !$user) {
             $this->pages->forget($key);
             continue;
         }
         /**
          * If there are role restrictions
          * and the user does not belong to
          * any of them then don't show it.
          */
         if (!$roles->isEmpty() && !$user->hasAnyRole($roles)) {
             $this->pages->forget($key);
             continue;
         }
     }
 }
 public function collections(Collection $collection, Guard $guard)
 {
     $collections = $collection->with(['votes' => function ($query) {
         $query->select('collection_user_vote.vote', 'collection_user_vote.user_id');
     }, 'user' => function ($query) {
         $query->select('users.id', 'users.name');
     }, 'blueprints' => function ($query) {
         $query->select('blueprint.id', 'blueprint.name');
     }])->paginate(8);
     $collectionsAsArray = $collections->toArray()['data'];
     foreach ($collectionsAsArray as $key => $value) {
         if (!empty($value['votes'])) {
             $totalVotes = 0;
             foreach ($value['votes'] as $vote) {
                 // get total number of votes
                 $totalVotes += $vote['vote'];
                 // check if the current user has voted
                 if ($guard->check()) {
                     if ($vote['user_id'] == $guard->user()->getAuthIdentifier()) {
                         $collectionsAsArray[$key]['user_has_voted'] = true;
                         $collectionsAsArray[$key]['user_vote'] = $vote['vote'];
                     }
                 }
             }
             $collectionsAsArray[$key]['total_votes'] = $totalVotes;
         } else {
             $collectionsAsArray[$key]['user_has_voted'] = false;
             $collectionsAsArray[$key]['total_votes'] = 0;
         }
     }
     return view('buildcraft.collections')->with(['collections' => $collections, 'collectionsAsArray' => $collectionsAsArray]);
 }
Example #25
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot(Guard $auth)
 {
     view()->composer(array('partials.navbar', 'runs.edit', 'index'), function ($view) use($auth) {
         $view->with('currentUserSuper', $auth->user()->super);
         // does what you expect
     });
 }
 /**
  * Get List of users
  *
  * @return array
  */
 public function getList()
 {
     if ($this->auth->user()->hasRole(config('nrgi.country_role'))) {
         return $this->user->getUsersWithCountryContract();
     }
     return $this->user->getList();
 }
 /**
  * Update Contract
  *
  * @param array $formData
  * @return bool
  */
 public function updateContract($contractID, array $formData)
 {
     try {
         $contract = $this->contract->findContract($contractID);
     } catch (Exception $e) {
         $this->logger->error('Contract not found', ['Contract ID' => $contractID]);
         return false;
     }
     $file_size = $contract->metadata->file_size;
     $metadata = $this->processMetadata($formData);
     $metadata['file_size'] = $file_size;
     $contract->metadata = $metadata;
     $contract->updated_by = $this->auth->user()->id;
     $contract->metadata_status = Contract::STATUS_DRAFT;
     $supportingDocuments = isset($formData['supporting_document']) ? $formData['supporting_document'] : [];
     try {
         if ($contract->save()) {
             $contract->syncSupportingContracts($supportingDocuments);
         }
         $this->logger->info('Contract successfully updated', ['Contract ID' => $contractID]);
         $this->logger->activity('contract.log.update', ['contract' => $contract->title], $contract->id);
         return true;
     } catch (Exception $e) {
         $this->logger->error(sprintf('Contract could not be updated. %s', $e->getMessage()), ['Contract ID' => $contractID]);
         return false;
     }
 }
Example #28
0
 public function index(HomePageDataService $homePageDataService, Auth $auth)
 {
     $status = 1;
     $user = $auth->user();
     $data = $homePageDataService->getDataForHomePage($status, $user);
     return View('home')->with($data);
 }
Example #29
0
 /**
  * @return boolean
  */
 public function logout()
 {
     $userInfoForEventTrigger = $this->auth->user();
     $this->auth->logout();
     \Event::fire(new LoggedOut($userInfoForEventTrigger));
     return true;
 }
Example #30
0
 /**
  * @param string $topicSlug
  * @param int    $topicId
  *
  * @return \Illuminate\Http\RedirectResponse
  *
  * @throws \Exception
  */
 public function undo($topicSlug, $topicId)
 {
     $topic = $this->topicRepository->find($topicId);
     if (!$topic) {
         throw new TopicNotFoundException();
     }
     if (!$topic->has_poll) {
         throw new PollNotFoundException();
     }
     $poll = $topic->poll;
     $pollPresenter = app()->make('MyBB\\Core\\Presenters\\Poll', [$poll]);
     if (!$this->guard->check()) {
         throw new PollNoGuestUndoException();
     }
     if ($pollPresenter->is_closed) {
         throw new PollClosedException();
     }
     $vote = $this->pollVoteRepository->findForUserPoll($this->guard->user(), $poll);
     if (!$vote) {
         // Error
         throw new PollNoUndoException();
     }
     $votes = explode(',', $vote->vote);
     $options = $pollPresenter->options();
     foreach ($votes as $option) {
         if (is_numeric($option) && 0 < $option && $option <= $pollPresenter->num_options()) {
             $options[$option - 1]['votes']--;
         }
     }
     $poll->update(['options' => $options]);
     $vote->delete();
     return redirect()->route('polls.show', [$topicSlug, $topicId]);
 }