This repository was archived by the owner on Nov 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 271
[Enhancement] Allows users and admins to have separate sessions #87
Closed
Closed
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a5ed4c2
added ability to separate users and admins via guards
39b8b63
Apply fixes from StyleCI
tabacitu 885b95b
tidied up the code a little to seem more convincing :D
0bb0121
Apply fixes from StyleCI
tabacitu e5ed923
No logout in ForgotPasswordController
tabacitu 47afe8f
No logout in RegisterController
tabacitu 7ac71b4
merged upgrade into separat-sessions
tabacitu 38cc798
Apply fixes from StyleCI
tabacitu ab48b9a
removed merge .orig file
tabacitu f778e51
Merge branch 'separate-sessions' of https://github.com/Laravel-Backpa…
tabacitu 0c36355
renamed middleware
tabacitu a7b11fa
registerGuards method
tabacitu 1f97c3f
merged master into separate-sessions branch
tabacitu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Backpack\Base\app\Http\Middleware; | ||
|
||
use Closure; | ||
|
||
class BackpackAdminGuard | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
if (config('backpack.base.separate_admin_session')) { | ||
if (!\Auth::guard(config('backpack.base.admin_guard.name'))->check()) { | ||
if ($request->ajax() || $request->wantsJson()) { | ||
return response(trans('backpack::base.unauthorized'), 401); | ||
} | ||
|
||
return redirect(config('backpack.base.route_prefix').'/login'); | ||
} | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Returns the name of the middleware | ||
* defined by the application config | ||
* if a param is passed in, it will chain | ||
* the backpack middelware to it. | ||
* e.g guest:backpack.admin. | ||
*/ | ||
if (!function_exists('backpack_middleware')) { | ||
function backpack_middleware($chainedWith = null) | ||
{ | ||
if (config('backpack.base.separate_admin_session')) { | ||
$middlware = config('backpack.base.admin_guard.name'); | ||
} else { | ||
$middlware = 'backpack.base.admin'; | ||
} | ||
|
||
if ($chainedWith && config('backpack.base.separate_admin_session')) { | ||
$middlware = $chainedWith.':'.$middlware; | ||
} elseif ($chainedWith) { | ||
$middleware = $chainedWith; | ||
} | ||
|
||
return $middlware; | ||
|
||
} | ||
} | ||
|
||
/* | ||
* Returns the name of the guard defined | ||
* by the application config | ||
*/ | ||
if (!function_exists('backpack_guard')) { | ||
function backpack_guard() | ||
{ | ||
if (config('backpack.base.separate_admin_session')) { | ||
$guard = config('backpack.base.admin_guard.name'); | ||
} else { | ||
$guard = null; | ||
} | ||
|
||
return $guard; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
/* | ||
* Returns the user instance if it exists | ||
* of the currently authenticated admin | ||
* based off the defined guard. | ||
*/ | ||
if (!function_exists('backpack_admin')) { | ||
function backpack_admin() | ||
{ | ||
return \Auth::guard(backpack_guard())->user(); | ||
} | ||
} | ||
|
||
/* | ||
* Returns back a user instance without | ||
* the admin guard, however allows you | ||
* to pass in a custom guard if you like. | ||
*/ | ||
if (!function_exists('backpack_user')) { | ||
function backpack_user($guard = null) | ||
{ | ||
return \Auth::guard($guard)->user(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not:
$request->expectsJson()
unless we don't like its pjson clause.That said, why couldn't someone access admin functionality via JSON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... this might be an issue. @OwenMelbz wouldn't this prevent ajax calls to pages that are behind the
backpack_middleware()
, if the new guard is used?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only applies is they are using separate sessions - if they're using the default laravel guard it will never affect it as that will have already handled the permission - baring in mind this whole implementation was based around the idea of using the default laravel guard for everything - then if turned on it simply adds another condition into the chain for the backend