-
Notifications
You must be signed in to change notification settings - Fork 271
[Feature][0.9][Merged] Custom auth guard #165
Changes from 6 commits
ccbf8fb
a592571
2fd3f86
08b9390
feac647
87839c9
2813799
37b49e1
107c1f3
a5a8015
2e1eea2
83758c6
edb3e52
5cd6190
353d230
5b50727
b153b4e
bb99618
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
use Backpack\Base\app\Http\Controllers\Controller; | ||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails; | ||
use Illuminate\Support\Facades\Password; | ||
|
||
class ForgotPasswordController extends Controller | ||
{ | ||
|
@@ -29,7 +30,9 @@ class ForgotPasswordController extends Controller | |
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('guest'); | ||
$guard = config('backpack.base.guard') ? config('backpack.base.guard') : config('auth.defaults.guard'); | ||
|
||
|
||
$this->middleware("guest:$guard"); | ||
} | ||
|
||
// ------------------------------------------------------- | ||
|
@@ -47,4 +50,16 @@ public function showLinkRequestForm() | |
|
||
return view('backpack::auth.passwords.email', $this->data); | ||
} | ||
|
||
/** | ||
* Get the broker to be used during password reset. | ||
* | ||
* @return \Illuminate\Contracts\Auth\PasswordBroker | ||
*/ | ||
public function broker() | ||
{ | ||
$passwords = config('backpack.base.passwords') ? config('backpack.base.passwords') : config('auth.defaults.passwords'); | ||
|
||
return Password::broker($passwords); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Backpack\Base\app\Http\ViewComposers; | ||
|
||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\View\View; | ||
|
||
class AuthComposer | ||
{ | ||
public function compose(View $view) | ||
{ | ||
$guard = config('backpack.base.guard') ? config('backpack.base.guard') : config('auth.defaults.guard'); | ||
|
||
$view->with([ | ||
'backpackAuth' => Auth::guard($guard), | ||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,11 +68,19 @@ | |
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| User Model | ||
| Authentication | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
// Fully qualified namespace of the User model | ||
'user_model_fqn' => '\App\User', | ||
|
||
|
||
// The guard that protects the Backpack admin panel. | ||
// If null, the config.auth.defaults.guard value will be used. | ||
'guard' => null, | ||
|
||
// The password reset configuration for Backpack. | ||
// If null, the config.auth.defaults.passwords value will be used. | ||
'passwords' => null, | ||
|
||
]; |
Uh oh!
There was an error while loading. Please reload this page.
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.
@jorenvanhee - I'm wondering if this is broad enough. Wouldn't this make the $backpackAuth guard available only in views that are loaded within the backpack namespace?
If so, I see the following problem:
I may be mistaken, though. It's been known to happen :-)
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.
Makes sense. What do you think about a helper function
backpackAuth()
?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... I think a more Laravely way to go would be a Facade. Something like
AdminAuth
orBackpackAuth
?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.
A more Laravely way would be to have both a Façade and a helper and then to have arguments on slack/gitter about which is best :(
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.
I'm ok with having both a facade and a helper function. Just like the
auth
helper in Laravel. The documentation says: "The auth function returns an authenticator instance. You may use it instead of the Auth facade for convenience:". I'll update the code if you're ok with that :)Uh oh!
There was an error while loading. Please reload this page.
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.
Having both is probably the better way, given that Laravel does that too. We might be able to avoid the arguments on slack/gitter bit though with a bit of luck (or just agreeing with me 👿).
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.
Agreed!