public function filter(Route $route, Request $request) { if ($this->auth->check()) { $config = $this->config->get('c::redirect-login'); $url = $config ? $this->url->to($config) : '/'; return $this->redirect->to($url); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { if (!$this->auth->check()) { return new RedirectResponse(route('login')); } return $next($request); }
/** * 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); }
/** * 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; }
/** * Create new Income Service * * @param IncomeServiceRequest $request * @param Guard $guard * @param Response $response * @param Gate $gate * @return ItemResponse|\Symfony\Component\HttpFoundation\Response */ public function store(IncomeServiceRequest $request, Guard $guard, Response $response, Gate $gate) { if (!$gate->check('putPostDelete', new IncomeService())) { return $response->setContent('Unauthorized')->setStatusCode(401); } return new ItemResponse($this->dispatch(new CreateIncomeServiceCommand($request->get('service_id'), $request->get('service_date'), $guard->user()->id, 3, 'status'))); }
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]); }
public function getWardrobeAuth() { $provider = $this->createEloquentProvider(); $guard = new Guard($provider, App::make('session.store'), App::make('request')); $guard->setCookieJar(App::make('cookie')); return $guard; }
/** * Store a newly created file in storage. * * @param FilesRequest $request * @return Response */ public function store(FilesRequest $request) { $this->auth->basic('username'); $data = ['title' => $request->input('title') ?: null, 'password' => $request->input('password') ?: null, 'file' => $request->file('path')]; $file = $this->dispatchFrom(StoreNewFileCommand::class, $request, $data); return 'http://drk.sh/' . $file->slug->slug . PHP_EOL; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->check()) { return redirect('/admin/home'); } return $next($request); }
/** * 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; } } }
/** * 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')); } }
/** * 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); }
/** * 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 }); }
public function index(HomePageDataService $homePageDataService, Auth $auth) { $status = 1; $user = $auth->user(); $data = $homePageDataService->getDataForHomePage($status, $user); return View('home')->with($data); }
/** * 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'); }
/** * Bootstrap the application services. * * @return void */ public function boot(Guard $auth, Request $request) { // view()->composer('*', function ($view) use($auth, $request) { $uri = $request->path(); $uri = explode("/", $uri); $breadcrumb = "<li>Home</li>"; $stopped = false; $menuPath = ""; foreach ($uri as $segment) { if (is_numeric($segment)) { $stopped = true; } else { $breadcrumb .= "<li>" . ucfirst($segment) . "</li>"; if (!$stopped) { $menuPath = $menuPath . "/" . $segment; } } } $allSites = array(); foreach (Site::orderBy('name', 'ASC')->get() as $site) { $allSites[$site->id] = $site->name; } $view->with('user', $auth->user())->with('breadcrumb', $breadcrumb)->with('menupath', $menuPath)->with('siteList', $allSites); }); view()->composer('modals.pressJob', function ($view) use($auth, $request) { $presses = \App\Press::where('site_id', session('site'))->get(); $view->with('presses', $presses); }); }
public function index(Guard $guard) { if (!$guard->guest()) { return redirect(route('app.dashboard.index')); } return view('layouts.login.index'); }
/** * 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('/'); }
/** * Log the user out. * * @param UserAuthenticator $authenticator * @param Guard $auth * @return \Illuminate\Http\RedirectResponse|Redirector */ public function logout(UserAuthenticator $authenticator, Guard $auth) { if (!$auth->guest()) { $authenticator->logout(); } $this->messages->success('anomaly.module.users::message.logged_out'); return redirect('admin/login'); }
public function postProfile(Request $request, Guard $auth) { if ($auth->user()->getAuthIdentifier() == $request->get($this->model->getKeyName())) { $this->postEdit($request); return $this->getProfile($auth); } abort(403, trans('permission-util::errors.unthorized')); }
/** * 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); }
/** * 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); }
/** * @param CommentContract $comment * @param Guard $auth * @param CommentService $commentService * @param ReportService $report */ public function __construct(CommentContract $comment, Guard $auth, CommentService $commentService, ReportService $report) { $this->middleware('auth', ['only' => 'vote']); $this->currentUser = $auth->user(); $this->comment = $comment; $this->commentService = $commentService; $this->report = $report; }
/** * Logout the active user. * * @param UserAuthenticator $authenticator * @param Guard $auth * @return \Illuminate\Http\RedirectResponse */ public function logout(UserAuthenticator $authenticator, Guard $auth) { if (!$auth->guest()) { $authenticator->logout(); } $this->messages->success($this->request->get('message', 'anomaly.module.users::message.logged_out')); return $this->response->redirectTo($this->request->get('redirect', '/')); }
/** * 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; }
/** * @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; }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request\RegisterUserRequest $request, Guard $auth) { // $input = $request->only('email', 'password', 'name'); $input['password'] = bcrypt($input['password']); $user = User::create($input); $auth->login($user); return redirect('/'); }
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); }
public function submit($id, Request $request, Guard $auth) { $this->validate($request, ['comment' => 'required|max:250', 'link' => 'url']); $comment = new TicketComments($request->only('comment', 'link')); $comment->user_id = $auth->id(); $ticket = Ticket::findOrFail($id); $ticket->comments()->save($comment); session()->flash('success', 'Tu comentario fue guardado exitosamente'); return redirect()->back(); }
public function __construct(Request $request, Guard $auth) { // TODO: Add API keys and check here // Check the session token and authenticate the user. if ($sessionToken = $request->get('sessionToken')) { $user = $this->validateSessionToken($sessionToken); $auth->setUser($user); } parent::__construct($request, $auth); }