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


PHP Guard::guest方法代码示例

本文整理汇总了PHP中Illuminate\Contracts\Auth\Guard::guest方法的典型用法代码示例。如果您正苦于以下问题:PHP Guard::guest方法的具体用法?PHP Guard::guest怎么用?PHP Guard::guest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Contracts\Auth\Guard的用法示例。


在下文中一共展示了Guard::guest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('auth/login');
         }
     }
     /** @var User $user */
     $user = $this->auth->user();
     if ($user instanceof User && intval($user->blocked) == 1) {
         Auth::logout();
         return redirect()->route('index');
     }
     // if logged in, set user language:
     $pref = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'));
     App::setLocale($pref->data);
     Carbon::setLocale(substr($pref->data, 0, 2));
     $locale = explode(',', trans('config.locale'));
     $locale = array_map('trim', $locale);
     setlocale(LC_TIME, $locale);
     setlocale(LC_MONETARY, $locale);
     return $next($request);
 }
开发者ID:webenhanced,项目名称:firefly-iii,代码行数:33,代码来源:Authenticate.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->guest()) {
         return redirect()->guest('/');
     }
     return $next($request);
 }
开发者ID:Apeiron0,项目名称:WhitePlates,代码行数:14,代码来源:Authenticate.php

示例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->guest()) {
         return response()->json(null, 401);
     }
     return $next($request);
 }
开发者ID:php-soft,项目名称:laravel-comments,代码行数:14,代码来源:Authenticate.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->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 403);
         } else {
             return redirect()->guest('auth/login');
         }
     }
     if (!$request->user()->isAdmin() && $request->user()->cannot('dashboard_view')) {
         $this->auth->logout();
         return redirect()->guest('auth/login')->withErrors(trans('messages.permission_denied'));
     }
     $route_array = explode('.', $request->route()->getName());
     $permission_name = array_search($route_array[2], array_dot($this->permission_fields));
     if ($permission_name) {
         $route_array[2] = explode('.', $permission_name)[0];
     }
     // $route_name = implode('_', $route_array);
     $route_name = $route_array[1] . '_' . $route_array[2];
     if (!$request->user()->isAdmin() && $request->user()->cannot($route_name)) {
         //PATCH 为null
         if ($request->ajax()) {
             return response()->json(['status' => trans('messages.permission_denied'), 'type' => 'error', 'code' => 403]);
         } else {
             return view('errors.403');
         }
     }
     return $next($request);
 }
开发者ID:hramose,项目名称:laravel-5-admin,代码行数:37,代码来源:Authenticate.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->guest()) {
         if ($request->ajax()) {
             return view('redminportal::users.notauthorized');
         } else {
             return redirect()->guest('login');
         }
     }
     $user = Auth::user();
     // Check if user has permission
     if ($user != null) {
         if (!$user->activated) {
             // User logged in but was deactivated after
             // Log out this user and bring to login page
             Auth::logout();
             return redirect()->guest('login');
         }
         // Proceed to check user permission
         if ($user->hasAccess($request)) {
             // Save login time
             $user->last_login = date('Y-m-d H:i:s');
             $user->save();
             return $next($request);
         }
     }
     return redirect('login/unauthorized');
 }
开发者ID:redooor,项目名称:redminportal,代码行数:35,代码来源:Authenticate.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->guest()) {
         abort(401);
     }
     return $next($request);
 }
开发者ID:harmjanhaisma,项目名称:clearboard,代码行数:14,代码来源:Authenticate.php

示例7: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next, $roleNames)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('auth/login');
         }
     }
     $hasNew = str_contains($roleNames, 'new');
     foreach (explode('+', $roleNames) as $role) {
         if ($role == 'new') {
             continue;
         }
         if ($this->auth->user()->access()->{$role}) {
             return $next($request);
         }
         if ($hasNew) {
             if ($this->auth->user()->access()->role == $role) {
                 return $next($request);
             }
         }
     }
     App::abort(403, 'Unauthorized action.');
 }
开发者ID:klsandbox,项目名称:rolemodel,代码行数:33,代码来源:RoleMiddleware.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->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('auth/login');
         }
     } elseif (session('role_id') == 3) {
         $route = $request->route();
         $routeName = $route->getName();
         if ($routeName == 'activity.show') {
             $activityId = $route->getParameter('activity');
             $orgId = Activity::select('organization_id')->find($activityId)->organization_id;
         } elseif ($routeName == 'organization.show') {
             $orgId = $route->getParameter('organization');
         } else {
             $orgId = session('org_id');
         }
         if ($orgId && $this->auth->user()->isSuperAdmin()) {
             $userId = User::select('id')->where('org_id', $orgId)->where('role_id', 1)->first()->id;
             app(OrganizationController::class)->masqueradeOrganization($orgId, $userId);
         } elseif (!$orgId && !isSuperAdminRoute()) {
             return redirect(config('app.super_admin_dashboard'));
         }
     } elseif (isSuperAdminRoute()) {
         $response = ['type' => 'warning', 'code' => ['message', ['message' => "You don't have correct privilege"]]];
         return redirect(config('app.admin_dashboard'))->withResponse($response);
     }
     return $next($request);
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:38,代码来源:Authenticate.php

示例9: handle

 /**
  * Handle an incoming request.
  *
  * @param Request $request
  * @param Closure $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     // If the user is already logged in, we don't need to reauthenticate.
     if (!$this->auth->check()) {
         // Retrieve the SSO login attribute.
         $auth = $this->getWindowsAuthAttribute();
         // Retrieve the SSO input key.
         $key = key($auth);
         // Handle Windows Authentication.
         if ($account = $request->server($auth[$key])) {
             // Usernames may be prefixed with their domain,
             // we just need their account name.
             $username = explode('\\', $account);
             if (count($username) === 2) {
                 list($domain, $username) = $username;
             } else {
                 $username = $username[key($username)];
             }
             // Create a new user LDAP user query.
             $query = $this->newAdldapUserQuery();
             // Filter the query by the username attribute
             $query->whereEquals($key, $username);
             // Retrieve the first user result
             $user = $query->first();
             if ($user instanceof User) {
                 $model = $this->getModelFromAdldap($user, str_random());
                 if ($model instanceof Model && $this->auth->guest()) {
                     // Double check user instance before logging them in.
                     $this->auth->login($model);
                 }
             }
         }
     }
     return $this->returnNextRequest($request, $next);
 }
开发者ID:ProyectoSanClemente,项目名称:proyectoapi5.1,代码行数:43,代码来源:WindowsAuthenticate.php

示例10: 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() || !Auth::user()->site_admin) {
         abort(404);
     }
     return $next($request);
 }
开发者ID:RobinJ1995,项目名称:VacStatus,代码行数:14,代码来源:AdminMiddleware.php

示例11: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     //check for user's role
     $has_role = false;
     if (!$this->auth->guest() && $this->auth->user() != null) {
         $required_role = $request->route()->getAction()['role'];
         if ($required_role == '*') {
             $has_role = true;
         } else {
             $roles = $this->auth->user()->roles;
             foreach ($roles as $role) {
                 if ($role->id_role == 'admin' || $role->id_role == $required_role) {
                     $has_role = true;
                     break;
                 }
             }
         }
     }
     if ($this->auth->guest() || !$has_role) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect(route('admin-login') . '?return_url=' . urlencode($request->url()));
         }
     }
     return $next($request);
 }
开发者ID:neonbug,项目名称:meexo-common,代码行数:34,代码来源:AuthenticateAdmin.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()->guest('auth/login');
         }
     } else {
         if ($this->auth->user()->doctor) {
             $queue = Queue::all();
             $patient = Patient::all();
             return view('doctor.dashboard')->with('queue', $queue)->with('patient', $patient);
         } else {
             if ($this->auth->user()->admin) {
                 $queue = Queue::all();
                 $patient = Patient::all();
                 return view('doctor.dashboard')->with('queue', $queue)->with('patient', $patient);
             } else {
                 $queue = Queue::all();
                 $patient = Patient::all();
                 return view('staff.dashboard')->with('queue', $queue)->with('patient', $patient);
             }
         }
     }
     return $next($request);
 }
开发者ID:nurali93,项目名称:clinic-alpha,代码行数:34,代码来源:Doctor.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->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest(route('_auth.login'));
         }
     }
     $current_route = $request->route()->getName();
     $user = Auth::user();
     $user_groups = $user->getGroups();
     $permits = array();
     foreach ($user_groups as $key => $group) {
         $perms = json_decode($group->permissions, true);
         // debug($perms);
         if (array_key_exists($current_route, $perms)) {
             $permits[] = $current_route;
         }
     }
     // debug(count($permits), $permits);
     if (!count($permits)) {
         Auth::logout();
         // return redirect()->guest(route('_auth.login'))->with('STATUS_FAIL', 'fail');
         return redirect(route('_auth.login'))->with('STATUS_FAIL', 'You do not have access to this page.');
     }
     return $next($request);
 }
开发者ID:kayrules,项目名称:laravel5-starter,代码行数:35,代码来源:Authenticate.php

示例14: 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()->guest('auth/login');
             return redirect()->guest('dangnhap');
         }
     }
     if ($request->is('giangvien/*')) {
         if (\Auth::user()->quyen != 'gv') {
             return redirect()->guest('dangnhap');
         }
     }
     if ($request->is('quantri/*')) {
         if (\Auth::user()->quyen != 'qt') {
             return redirect()->guest('dangnhap');
         }
     }
     if ($request->is('sinhvien/*')) {
         if (\Auth::user()->quyen != 'sv') {
             return redirect()->guest('dangnhap');
         }
     }
     /* $action = $request->route()->getActionName();
        echo $action; */
     return $next($request);
 }
开发者ID:HaNguyen1410,项目名称:laravProject1,代码行数:36,代码来源:Authenticate.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->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


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