當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。