本文整理汇总了PHP中Illuminate\Auth\Guard::check方法的典型用法代码示例。如果您正苦于以下问题:PHP Guard::check方法的具体用法?PHP Guard::check怎么用?PHP Guard::check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Auth\Guard
的用法示例。
在下文中一共展示了Guard::check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: 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);
}
示例3: 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);
}
示例4: 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() && $this->auth->user()['status'] === 'student') {
return $next($request);
}
Session::push('messages', 'danger|Vous devez être étudiant pour accéder à cette page');
return redirect('/');
}
示例5: handle
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);
}
示例6: 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()) {
if ($this->auth->user()->allowRoutes($request->route()->getName())) {
return $next($request);
}
return response('Forbidden.', 403);
}
return $next($request);
}
示例7: 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()) {
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);
}
示例8: blueprints
/**
* Returns a view with all the blueprints
* available, irregardless of the user
* who uploaded them
*
* @param Blueprint $blueprint
* @param Guard $guard
*
* @return $this
*/
public function blueprints(Blueprint $blueprint, Guard $guard)
{
$blueprints = $blueprint->select('blueprint.author_name', 'blueprint.user_id', 'blueprint.id', 'blueprint.name', 'blueprint.bc_version', 'blueprint.screenshot', 'blueprint.archive_name', 'blueprint.description', 'blueprint.version')->with(['mods', 'votes' => function ($query) {
$query->select('blueprint_user_vote.vote', 'blueprint_user_vote.user_id');
}, 'user' => function ($query) {
$query->select('users.id', 'users.name');
}])->orderBy('uploaded_at', 'desc')->paginate(4);
$blueprintsAsArray = $blueprints->toArray()['data'];
foreach ($blueprintsAsArray 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()) {
$blueprintsAsArray[$key]['user_has_voted'] = true;
$blueprintsAsArray[$key]['user_vote'] = $vote['vote'];
}
}
}
$blueprintsAsArray[$key]['total_votes'] = $totalVotes;
} else {
$blueprintsAsArray[$key]['user_has_voted'] = false;
$blueprintsAsArray[$key]['total_votes'] = 0;
}
}
return view('buildcraft.singles')->with(['blueprints' => $blueprints, 'blueprintsAsArray' => $blueprintsAsArray]);
}
示例9: 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]);
}
示例10: undo
/**
* @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]);
}
示例11: 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()) {
$admin = 0;
if ($this->auth->user()->admin == 1) {
$admin = 1;
}
if ($admin == 0) {
return $this->response->redirectTo('/');
// frontend
}
return $next($request);
}
return $this->response->redirectTo('/');
// Go to frontend
}
示例12: postCreate
/**
* @param int $forumId
* @param CreateRequest $createRequest
*
* @return $this|bool|\Illuminate\Http\RedirectResponse
*/
public function postCreate($forumId, CreateRequest $createRequest)
{
// Forum permissions are checked in "CreateRequest"
if (!$this->guard->check()) {
$captcha = $this->checkCaptcha();
if ($captcha !== true) {
return $captcha;
}
}
$poll = null;
if ($createRequest->input('add-poll')) {
$pollCreateRequest = app()->make('MyBB\\Core\\Http\\Requests\\Poll\\CreateRequest');
$poll = ['question' => $pollCreateRequest->input('question'), 'num_options' => count($pollCreateRequest->options()), 'options' => $pollCreateRequest->options(), 'is_closed' => false, 'is_multiple' => (bool) $pollCreateRequest->input('is_multiple'), 'is_public' => (bool) $pollCreateRequest->input('is_public'), 'end_at' => null, 'max_options' => (int) $pollCreateRequest->input('maxoptions')];
if ($pollCreateRequest->input('endAt')) {
$poll['end_at'] = new \DateTime($pollCreateRequest->input('endAt'));
}
}
$topic = $this->topicRepository->create(['title' => $createRequest->input('title'), 'forum_id' => $createRequest->input('forum_id'), 'first_post_id' => 0, 'last_post_id' => 0, 'views' => 0, 'num_posts' => 0, 'content' => $createRequest->input('content'), 'username' => $createRequest->input('username')]);
if ($topic) {
if ($poll) {
$poll['topic_id'] = $topic->id;
$this->pollRepository->create($poll);
$this->topicRepository->setHasPoll($topic, true);
}
return redirect()->route('topics.show', ['slug' => $topic->slug, 'id' => $topic->id]);
}
return redirect()->route('topic.create', ['forumId' => $forumId])->withInput()->withErrors(['content' => trans('errors.error_creating_topic')]);
}
示例13: myVote
/**
* @return mixed
*/
public function myVote()
{
if (!isset($this->cache['myVote'])) {
if ($this->guard->check()) {
$this->cache['myVote'] = $this->pollVoteRepository->findForUserPoll($this->guard->user(), $this->wrappedObject);
} else {
$this->cache['myVote'] = null;
}
}
return $this->cache['myVote'];
}
示例14: login
/**
* Return the admin login form.
*
* @param LoginFormBuilder $form
* @param Redirector $redirect
* @param Repository $config
* @param Guard $auth
* @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function login(LoginFormBuilder $form, Redirector $redirect, Repository $config, Guard $auth)
{
/**
* If we're already logged in
* proceed to the dashboard.
*
* Replace this later with a
* configurable landing page.
*/
if ($auth->check()) {
return $redirect->to($config->get('anomaly.module.users::paths.home', 'admin/dashboard'));
}
return $form->setOption('redirect', $config->get('anomaly.module.users::paths.home', 'admin/dashboard'))->setOption('wrapper_view', 'theme::login')->render();
}
示例15: login
/**
* Return the admin login form.
*
* @param LoginFormBuilder $form
* @param Redirector $redirect
* @param Repository $config
* @param Guard $auth
* @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function login(NavigationCollection $navigation, LoginFormBuilder $form, Redirector $redirect, Repository $config, Guard $auth)
{
/**
* If we're already logged in
* proceed to the dashboard.
*
* Replace this later with a
* configurable landing page.
*/
if ($auth->check() && ($home = $navigation->home())) {
return $redirect->to($config->get($home->getHref()));
}
return $form->setOption('redirect', 'admin')->setOption('wrapper_view', 'theme::login')->render();
}