本文整理汇总了PHP中Illuminate\Contracts\Auth\Guard::user方法的典型用法代码示例。如果您正苦于以下问题:PHP Guard::user方法的具体用法?PHP Guard::user怎么用?PHP Guard::user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Contracts\Auth\Guard
的用法示例。
在下文中一共展示了Guard::user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle an incoming request.
*
* @param Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
list($controller, $action) = $this->getControllerAndAction();
$bindings = $this->getBindings();
$authorized = false;
/** @var Roleable $user */
$user = $this->auth->user();
$args = func_get_args();
if (count($args) > 2) {
// Role based authorization
$roles = $this->getAllowedRoles(array_slice($args, 2));
if (!$user && in_array($this->getGuestRole(), $roles)) {
$authorized = true;
} elseif ($user && $user->hasRole($roles)) {
$authorized = true;
}
} else {
// Permission based authorization
if ($this->gate->forUser($user)->check($action, array_merge([$controller], $bindings))) {
$authorized = true;
}
}
// if user is not authorized, we will return errror response
if (!$authorized) {
$this->reportUnauthorizedAttempt($controller, $action, $request, $bindings);
return $this->errorResponse($request);
}
return $next($request);
}
示例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->user()->type->code !== 'ADT' && $this->auth->user()->type->code !== 'OPT') {
return redirect('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, $role)
{
if (!$this->auth->user()->hasRole($role)) {
throw new RoleDeniedException($role);
}
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->user()) {
return redirect('/');
}
return $next($request);
}
示例5: 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()->hasRole($this->role)) {
App::abort(401);
}
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() && $this->auth->user()->role_id == 1) {
return new RedirectResponse(route('adminHome'));
}
return $next($request);
}
示例7: handle
/**
* We're verifying that the current user is logged in to Cachet and is an admin level.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$this->auth->check() || $this->auth->check() && !$this->auth->user()->isAdmin) {
throw new HttpException(401);
}
return $next($request);
}
示例8: 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($this->auth->user()->getHomeUrl());
}
return $next($request);
}
示例9: update
/**
* updates Activity Document Link
* @param array $documentLink
* @param ActivityDocumentLink $activityDocumentLink
* @return bool
*/
public function update(array $documentLink, ActivityDocumentLink $activityDocumentLink)
{
try {
$this->database->beginTransaction();
$documentLinkExists = $activityDocumentLink->exists;
$activityId = $activityDocumentLink->activity_id;
$documentManager = app(DocumentManager::class);
if ($documentLinkExists) {
$url = $activityDocumentLink->document_link['url'];
$document = $documentManager->getDocument(session('org_id'), $url);
$activities = (array) $document->activities;
unset($activities[$activityId]);
$document->activities = $activities;
$documentManager->update($document);
}
$url = $documentLink[0]['url'];
$document = $documentManager->getDocument(session('org_id'), $url);
$activities = (array) $document->activities;
$identifier = $activityDocumentLink->activity->identifier['activity_identifier'];
$activities[$activityId] = $identifier;
$document->activities = $activities;
$documentManager->update($document);
$this->DocumentLinkRepo->update($documentLink, $activityDocumentLink);
$this->database->commit();
$this->logger->info(sprintf('Activity Document Link %s!', $documentLinkExists ? 'updated' : 'saved'), ['for' => $documentLink]);
$this->dbLogger->activity(sprintf("activity.document_link_%s", $documentLinkExists ? 'updated' : 'saved'), ['activity_id' => $activityDocumentLink->activity_id, 'document_link_id' => $activityDocumentLink->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
return true;
} catch (\Exception $exception) {
$this->database->rollback();
$this->logger->error($exception, ['documentLink' => $documentLink]);
}
return false;
}
示例10: handle
/**
* Handle an incoming request.
* This middleware must be handled after the
* Authentication middleware.
*
* @param Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if ($this->auth->user()->level() < 3) {
return abort(401, 'Non sei autorizzato');
}
return $next($request);
}
示例11: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, $role = null, $permission = null)
{
// Check the user is logged in
if ($this->auth->guest()) {
return back(403)->withError(trans('ethereal-auth::middleware.403'));
}
// If empty role and empty permission, authenticated user get access
if (empty($role) && empty($permission)) {
return $next($request);
}
// Get the authenticated user
$user = $this->auth->user();
// Check the user has the role with the right permission
if (!empty($role) && !empty($permission)) {
if ($user->is($role) && $user->can($permission, $role)) {
return $next($request);
}
}
// Check the user has the right role
if (empty($role) && !empty($permission)) {
if ($user->is($role)) {
return $next($request);
}
}
// Check the user has the right permission
if (!empty($role) && empty($permission)) {
if ($user->can($permission)) {
return $next($request);
}
}
return back(403)->withError(trans('ethereal-auth::middleware.403'));
}
示例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->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->route('auth.signin');
}
} else {
$user = $this->auth->user();
if ($user->ban) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
$this->auth->logout();
notify()->flash('Banned', 'error', ['text' => $user->ban_reason]);
return redirect()->route('auth.signin');
}
}
}
/*$ipInfo = getIpInfo($request->getClientIp());
if($ipInfo){
if(isset($ipInfo['timezone'])){
if($ipInfo['timezone'] != $this->auth->user()->timezone){
$this->auth->user()->update([
'timezone' => $ipInfo['timezone']
]);
}
}
}*/
return $next($request);
}
示例13: 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($this->auth->user()->role->redirect);
}
return $next($request);
}
示例14: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return void|mixed
*/
public function handle(Request $request, Closure $next)
{
if (!$this->app->isDownForMaintenance()) {
return $next($request);
}
if ($request->segment(1) == 'admin') {
return $next($request);
}
if (in_array($request->getClientIp(), $this->config->get('streams::maintenance.ip_whitelist', []))) {
return $next($request);
}
/* @var UserInterface $user */
$user = $this->guard->user();
if ($user && $user->isAdmin()) {
return $next($request);
}
if ($user && $this->authorizer->authorize('streams::maintenance.access')) {
return $next($request);
}
if (!$user && $this->config->get('streams::maintenance.auth')) {
/* @var Response|null $response */
$response = $this->guard->onceBasic();
if (!$response) {
return $next($request);
}
$response->setContent(view('streams::errors.401'));
return $response;
}
abort(503);
}
示例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() or !$this->auth->user()->canAccessAdminPanel()) {
return redirect('/auth/login?ref=admin');
}
return $next($request);
}