Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
4f4d378d
Commit
4f4d378d
authored
Mar 21, 2016
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3685 from JosephSilber/multi-auth
Allow passing multiple gaurds to the auth middleware
parents
8aa5af73
703197e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
8 deletions
+29
-8
Authenticate.php
app/Http/Middleware/Authenticate.php
+29
-8
No files found.
app/Http/Middleware/Authenticate.php
View file @
4f4d378d
...
@@ -12,19 +12,40 @@ class Authenticate
...
@@ -12,19 +12,40 @@ class Authenticate
*
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param \Closure $next
* @param string
|null $guard
* @param string
...$guards
* @return mixed
* @return mixed
*/
*/
public
function
handle
(
$request
,
Closure
$next
,
$guard
=
null
)
public
function
handle
(
$request
,
Closure
$next
,
...
$guards
)
{
{
if
(
Auth
::
guard
(
$guard
)
->
guest
())
{
if
(
$this
->
check
(
$guards
))
{
if
(
$request
->
ajax
()
||
$request
->
wantsJson
())
{
return
$next
(
$request
);
return
response
(
'Unauthorized.'
,
401
);
}
}
else
{
return
redirect
()
->
guest
(
'login'
);
if
(
$request
->
ajax
()
||
$request
->
wantsJson
())
{
return
response
(
'Unauthorized.'
,
401
);
}
else
{
return
redirect
()
->
guest
(
'login'
);
}
}
/**
* Determine if the user is logged in to any of the given guards.
*
* @param array $guards
* @return bool
*/
protected
function
check
(
array
$guards
)
{
if
(
empty
(
$guards
))
{
return
Auth
::
check
();
}
foreach
(
$guards
as
$guard
)
{
if
(
Auth
::
guard
(
$guard
)
->
check
())
{
return
true
;
}
}
}
}
return
$next
(
$request
)
;
return
false
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment