-
Notifications
You must be signed in to change notification settings - Fork 282
Add option to switch authentication guards #141
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| namespace Backpack\Base\app\Http\Controllers\Auth; | ||
|
|
||
| use Auth; | ||
| use Backpack\Base\app\Http\Controllers\Controller; | ||
| use Illuminate\Foundation\Auth\RegistersUsers; | ||
| use Illuminate\Http\Request; | ||
|
|
@@ -30,7 +31,10 @@ class RegisterController extends Controller | |
| */ | ||
| public function __construct() | ||
| { | ||
| $this->middleware('guest'); | ||
| $guard = config('backpack.base.guard') | ||
| ?: config('auth.defaults.guard'); | ||
|
Contributor
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. NL? |
||
|
|
||
| $this->middleware("guest:$guard"); | ||
|
|
||
| // Where to redirect users after login / registration. | ||
| $this->redirectTo = property_exists($this, 'redirectTo') ? $this->redirectTo | ||
|
|
@@ -113,4 +117,12 @@ public function register(Request $request) | |
|
|
||
| return redirect($this->redirectPath()); | ||
| } | ||
|
|
||
| protected function guard() | ||
|
Contributor
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. PHP Doc? |
||
| { | ||
| $guard = config('backpack.base.guard') | ||
| ?: config('auth.defaults.guard'); | ||
|
Contributor
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. NL? |
||
|
|
||
| return Auth::guard($guard); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,11 @@ | |
|
|
||
| namespace Backpack\Base\app\Http\Controllers\Auth; | ||
|
|
||
| use Auth; | ||
| use Backpack\Base\app\Http\Controllers\Controller; | ||
| use Illuminate\Foundation\Auth\ResetsPasswords; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\Password; | ||
|
|
||
| class ResetPasswordController extends Controller | ||
| { | ||
|
|
@@ -30,7 +32,10 @@ class ResetPasswordController extends Controller | |
| */ | ||
| public function __construct() | ||
| { | ||
| $this->middleware('guest'); | ||
| $guard = config('backpack.base.guard') | ||
| ?: config('auth.defaults.guard'); | ||
|
Contributor
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. NL? |
||
|
|
||
| $this->middleware("guest:$guard"); | ||
|
|
||
| // where to redirect after password was reset | ||
| $this->redirectTo = property_exists($this, 'redirectTo') ? $this->redirectTo : config('backpack.base.route_prefix', 'admin').'/dashboard'; | ||
|
|
@@ -58,4 +63,20 @@ public function showResetForm(Request $request, $token = null) | |
| ['token' => $token, 'email' => $request->email] | ||
| ); | ||
| } | ||
|
|
||
| public function broker() | ||
|
Contributor
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. PHP Doc? |
||
| { | ||
| $passwords = config('backpack.base.passwords') | ||
| ?: config('auth.defaults.passwords'); | ||
|
Contributor
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. NL?
Contributor
Author
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. Added the newline here to keep width of the line under 80 characters. I also did it in some other places where it may not be needed. I thought it was readable like that. But they can be removed of course :) |
||
|
|
||
| return Password::broker($passwords); | ||
| } | ||
|
|
||
| protected function guard() | ||
|
Contributor
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. PHP Doc?
Contributor
Author
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. Can add that for sure, if there's interest in merging this PR. |
||
| { | ||
| $guard = config('backpack.base.guard') | ||
| ?: config('auth.defaults.guard'); | ||
|
Contributor
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. NL? |
||
|
|
||
| return Auth::guard($guard); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,14 @@ class Admin | |
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @param \Closure $next | ||
| * @param string|null $guard | ||
| * | ||
| * @return mixed | ||
| */ | ||
| public function handle($request, Closure $next, $guard = null) | ||
| public function handle($request, Closure $next) | ||
| { | ||
| $guard = config('backpack.base.guard') | ||
| ?: config('auth.defaults.guard'); | ||
|
Contributor
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. NL? |
||
|
|
||
| if (Auth::guard($guard)->guest()) { | ||
| if ($request->ajax() || $request->wantsJson()) { | ||
| return response(trans('backpack::base.unauthorized'), 401); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| namespace Backpack\Base\app\Http\ViewComposers; | ||
|
|
||
| use Illuminate\Support\Facades\Auth; | ||
| use Illuminate\View\View; | ||
|
|
||
| class AuthComposer | ||
| { | ||
| public function compose(View $view) | ||
|
Contributor
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. PHP Doc? |
||
| { | ||
| $guard = config('backpack.base.guard') | ||
| ?: config('auth.defaults.guard'); | ||
|
Contributor
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. NL? |
||
|
|
||
| $view->with([ | ||
| 'backpackAuth' => Auth::guard($guard), | ||
| ]); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
|
|
||
| <!-- <li><a href="{{ url('/') }}"><i class="fa fa-home"></i> <span>Home</span></a></li> --> | ||
|
|
||
| @if (Auth::guest()) | ||
| @if ($backpackAuth->guest()) | ||
|
Contributor
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. Where did
Contributor
Author
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. From the AuthComposer. |
||
| <li><a href="{{ url(config('backpack.base.route_prefix', 'admin').'/login') }}">{{ trans('backpack::base.login') }}</a></li> | ||
| @if (config('backpack.base.registration_open')) | ||
| <li><a href="{{ url(config('backpack.base.route_prefix', 'admin').'/register') }}">{{ trans('backpack::base.register') }}</a></li> | ||
|
|
||
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.
NL?