Get Newest Horizon (#109)
* Re-publish Horizon assets * Updated horizon config file * Newest Horizon now works by using Laravel’s own auth * For now, remove test for admin login
This commit is contained in:
parent
e7a44fb663
commit
c82c4524eb
23 changed files with 995 additions and 80 deletions
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class AuthController extends Controller
|
||||
|
@ -13,28 +13,29 @@ class AuthController extends Controller
|
|||
/**
|
||||
* Show the login form.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function showLogin(): View
|
||||
public function showLogin()
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
return view('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Log in a user, set a sesion variable, check credentials against
|
||||
* Log in a user, set a session variable, check credentials against
|
||||
* the .env file.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function login(): RedirectResponse
|
||||
{
|
||||
if (request()->input('username') === config('admin.user')
|
||||
&&
|
||||
request()->input('password') === config('admin.pass')
|
||||
) {
|
||||
session(['loggedin' => true]);
|
||||
$credentials = request()->only('name', 'password');
|
||||
|
||||
return redirect()->intended('admin');
|
||||
if (Auth::attempt($credentials, true)) {
|
||||
return redirect()->intended('/');
|
||||
}
|
||||
|
||||
return redirect()->route('login');
|
||||
|
|
|
@ -17,7 +17,7 @@ class User extends Authenticatable
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password',
|
||||
'name', 'password',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,34 +2,41 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Horizon\Horizon;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Horizon\HorizonApplicationServiceProvider;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class HorizonServiceProvider extends ServiceProvider
|
||||
class HorizonServiceProvider extends HorizonApplicationServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Horizon::auth(function (Request $request) {
|
||||
// return true/false
|
||||
if (app()->environment('production') !== true) {
|
||||
// we aren’t live so just let us into Horizon
|
||||
return true;
|
||||
}
|
||||
if ($request->session()->has('loggedin')) {
|
||||
// are we logged in as an authed user
|
||||
return $request->session()->get('loggedin');
|
||||
}
|
||||
parent::boot();
|
||||
|
||||
return false;
|
||||
// Horizon::routeSmsNotificationsTo('15556667777');
|
||||
// Horizon::routeMailNotificationsTo('example@example.com');
|
||||
// Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel');
|
||||
|
||||
Horizon::night();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Horizon gate.
|
||||
*
|
||||
* This gate determines who can access Horizon in non-local environments.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function gate()
|
||||
{
|
||||
Gate::define('viewHorizon', function ($user) {
|
||||
return in_array($user->name, [
|
||||
'jonny',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue