本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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');
}
示例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);
}
示例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.');
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}