本文整理汇总了PHP中Illuminate\Auth\Guard类的典型用法代码示例。如果您正苦于以下问题:PHP Guard类的具体用法?PHP Guard怎么用?PHP Guard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Guard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* 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);
}
示例2: store
/**
* 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')));
}
示例3: collections
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]);
}
示例4: getWardrobeAuth
public function getWardrobeAuth()
{
$provider = $this->createEloquentProvider();
$guard = new Guard($provider, App::make('session.store'), App::make('request'));
$guard->setCookieJar(App::make('cookie'));
return $guard;
}
示例5: handle
/**
* 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;
}
}
}
示例6: boot
/**
* 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
});
}
示例7: boot
/**
* 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);
});
}
示例8: index
public function index(Guard $guard)
{
if (!$guard->guest()) {
return redirect(route('app.dashboard.index'));
}
return view('layouts.login.index');
}
示例9: logout
/**
* 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');
}
示例10: postProfile
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'));
}
示例11: filter
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);
}
}
示例12: handle
/**
* 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);
}
示例13: store
/**
* 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;
}
示例14: store
/**
* 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;
}
示例15: handle
/**
* 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);
}