当前位置: 首页>>代码示例>>PHP>>正文


PHP Guard::user方法代码示例

本文整理汇总了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);
 }
开发者ID:mnabialek,项目名称:laravel-authorize,代码行数:37,代码来源:Authorize.php

示例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);
 }
开发者ID:sibasbo,项目名称:sibas,代码行数:14,代码来源:IsUser.php

示例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);
 }
开发者ID:yewei-cao,项目名称:access-laravel,代码行数:14,代码来源:RoleMiddleware.php

示例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);
 }
开发者ID:asarmiento,项目名称:CPHon,代码行数:14,代码来源:VerifictSession.php

示例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);
 }
开发者ID:nich-mctishe,项目名称:laravel-framework,代码行数:14,代码来源:Role.php

示例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);
 }
开发者ID:jerryamatya,项目名称:broadcaster,代码行数:14,代码来源:RedirectIfAuthenticated.php

示例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);
 }
开发者ID:guduchango,项目名称:Cachet,代码行数:15,代码来源:Admin.php

示例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);
 }
开发者ID:bjrnblm,项目名称:blender,代码行数:15,代码来源:RedirectIfAuthenticated.php

示例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;
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:39,代码来源:DocumentLinkManager.php

示例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);
 }
开发者ID:gperis,项目名称:scuolacloud,代码行数:17,代码来源:Administrative.php

示例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'));
 }
开发者ID:gabemiller,项目名称:ethereal-auth,代码行数:39,代码来源:AuthMiddleware.php

示例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);
 }
开发者ID:vuonghuuphuc,项目名称:coder,代码行数:39,代码来源:Authenticate.php

示例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);
 }
开发者ID:satriashp,项目名称:tour,代码行数:14,代码来源:RedirectIfAuthenticated.php

示例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);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:37,代码来源:CheckForMaintenanceMode.php

示例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);
 }
开发者ID:Orvo,项目名称:mlraamattu,代码行数:14,代码来源:AdminAuthenticate.php


注:本文中的Illuminate\Contracts\Auth\Guard::user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。