Skip to content
This repository was archived by the owner on Nov 23, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/BaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Backpack\Base;

use Illuminate\Routing\Router;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Route;

Expand All @@ -28,6 +29,8 @@ public function boot(\Illuminate\Routing\Router $router)
// - then the stock views that come with the package, in case a published view might be missing
$this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backpack');

View::composer('backpack::*', \Backpack\Base\app\Http\ViewComposers\AuthComposer::class);

$this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack');

// use the vendor configuration file as fallback
Expand Down
14 changes: 13 additions & 1 deletion src/app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -29,7 +30,10 @@ class ForgotPasswordController extends Controller
*/
public function __construct()
{
$this->middleware('guest');
$guard = config('backpack.base.guard')
?: config('auth.defaults.guard');

$this->middleware("guest:$guard");
}

// -------------------------------------------------------
Expand All @@ -47,4 +51,12 @@ public function showLinkRequestForm()

return view('backpack::auth.passwords.email', $this->data);
}

public function broker()
{
$passwords = config('backpack.base.passwords')
?: config('auth.defaults.passwords');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NL?


return Password::broker($passwords);
}
}
14 changes: 13 additions & 1 deletion src/app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Backpack\Base\app\Http\Controllers\Auth;

use Auth;
use Backpack\Base\app\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -31,7 +32,10 @@ class LoginController extends Controller
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
$guard = config('backpack.base.guard')
?: config('auth.defaults.guard');

$this->middleware("guest:$guard", ['except' => 'logout']);

// ----------------------------------
// Use the admin prefix in all routes
Expand Down Expand Up @@ -81,4 +85,12 @@ public function logout(Request $request)
// And redirect to custom location
return redirect($this->redirectAfterLogout);
}

protected function guard()
{
$guard = config('backpack.base.guard')
?: config('auth.defaults.guard');

return Auth::guard($guard);
}
}
14 changes: 13 additions & 1 deletion src/app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -30,7 +31,10 @@ class RegisterController extends Controller
*/
public function __construct()
{
$this->middleware('guest');
$guard = config('backpack.base.guard')
?: config('auth.defaults.guard');
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -113,4 +117,12 @@ public function register(Request $request)

return redirect($this->redirectPath());
}

protected function guard()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP Doc?

{
$guard = config('backpack.base.guard')
?: config('auth.defaults.guard');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NL?


return Auth::guard($guard);
}
}
23 changes: 22 additions & 1 deletion src/app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,7 +32,10 @@ class ResetPasswordController extends Controller
*/
public function __construct()
{
$this->middleware('guest');
$guard = config('backpack.base.guard')
?: config('auth.defaults.guard');
Copy link
Contributor

Choose a reason for hiding this comment

The 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';
Expand Down Expand Up @@ -58,4 +63,20 @@ public function showResetForm(Request $request, $token = null)
['token' => $token, 'email' => $request->email]
);
}

public function broker()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP Doc?

{
$passwords = config('backpack.base.passwords')
?: config('auth.defaults.passwords');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP Doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NL?


return Auth::guard($guard);
}
}
6 changes: 4 additions & 2 deletions src/app/Http/Middleware/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down
19 changes: 19 additions & 0 deletions src/app/Http/ViewComposers/AuthComposer.php
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP Doc?

{
$guard = config('backpack.base.guard')
?: config('auth.defaults.guard');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NL?


$view->with([
'backpackAuth' => Auth::guard($guard),
]);
}
}
10 changes: 9 additions & 1 deletion src/config/backpack/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. The default guard will
// be used if this is null.
'guard' => null,

// The password reset configuration for Backpack. The default configuration
// will be used if this is null.
'passwords' => null,

];
2 changes: 1 addition & 1 deletion src/resources/views/inc/menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did $backpackAuth come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Expand Down
6 changes: 3 additions & 3 deletions src/resources/views/inc/sidebar.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@if (Auth::check())
@if ($backpackAuth->check())
<!-- Left side column. contains the sidebar -->
<aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- Sidebar user panel -->
<div class="user-panel">
<div class="pull-left image">
<img src="https://placehold.it/160x160/00a65a/ffffff/&text={{ mb_substr(Auth::user()->name, 0, 1) }}" class="img-circle" alt="User Image">
<img src="https://placehold.it/160x160/00a65a/ffffff/&text={{ mb_substr($backpackAuth->user()->name, 0, 1) }}" class="img-circle" alt="User Image">
</div>
<div class="pull-left info">
<p>{{ Auth::user()->name }}</p>
<p>{{ $backpackAuth->user()->name }}</p>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
</div>
</div>
Expand Down