/src/Api.js
This commit is contained in:
parent
8cce215ce4
commit
deb9afe175
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
|
||||||
|
class Authenticate
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
if (!Session::get('isAuthenticated')) {
|
||||||
|
return redirect('/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Services\CookieService;
|
||||||
|
use App\Services\ApiService;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class CheckAuth
|
||||||
|
{
|
||||||
|
protected $cookieService;
|
||||||
|
protected $apiService;
|
||||||
|
|
||||||
|
public function __construct(CookieService $cookieService, ApiService $apiService)
|
||||||
|
{
|
||||||
|
$this->cookieService = $cookieService;
|
||||||
|
$this->apiService = $apiService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
$token = $this->cookieService->getCookie('TOKEN');
|
||||||
|
$publicRoutes = ['/', '/login', '/registration', '/change-password', '/topup-success-page', '/topup-error-page'];
|
||||||
|
|
||||||
|
if ($token) {
|
||||||
|
try {
|
||||||
|
$response = $this->apiService->post('adminProfile');
|
||||||
|
if ($response) {
|
||||||
|
Session::put('userInfo', $response);
|
||||||
|
Session::put('isAuthenticated', true);
|
||||||
|
|
||||||
|
if (in_array($request->path(), $publicRoutes)) {
|
||||||
|
return redirect('/user-management');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Failed to load user data', ['error' => $e->getMessage(), 'source' => 'CheckAuth']);
|
||||||
|
Session::flash('error', 'Something went wrong loading user data.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Foundation\Configuration\Exceptions;
|
use Illuminate\Foundation\Configuration\Exceptions;
|
||||||
use Illuminate\Foundation\Configuration\Middleware;
|
use Illuminate\Foundation\Configuration\Middleware;
|
||||||
|
use App\Http\Middleware\CheckAuth;
|
||||||
|
|
||||||
return Application::configure(basePath: dirname(__DIR__))
|
return Application::configure(basePath: dirname(__DIR__))
|
||||||
->withRouting(
|
->withRouting(
|
||||||
|
@ -12,7 +13,12 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||||
health: '/up',
|
health: '/up',
|
||||||
)
|
)
|
||||||
->withMiddleware(function (Middleware $middleware) {
|
->withMiddleware(function (Middleware $middleware) {
|
||||||
//
|
$middleware->web(append: [
|
||||||
|
CheckAuth::class,
|
||||||
|
]);
|
||||||
|
$middleware->alias([
|
||||||
|
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||||
|
]);
|
||||||
})
|
})
|
||||||
->withExceptions(function (Exceptions $exceptions) {
|
->withExceptions(function (Exceptions $exceptions) {
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,24 +1,16 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>@yield('title')</title>
|
<title>Laravel</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
|
|
||||||
@livewireStyles
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header class="mb-4">
|
<div class="container mt-5">
|
||||||
@livewire('header-dropdown', ['userInfo' => ['firstname' => 'John', 'lastname' => 'Doe']])
|
|
||||||
</header>
|
|
||||||
<div class="container">
|
|
||||||
@yield('content')
|
@yield('content')
|
||||||
</div>
|
</div>
|
||||||
<footer class="mt-5">
|
<script src="{{ asset('js/app.js') }}"></script>
|
||||||
@livewire('main-footer')
|
@stack('scripts')
|
||||||
</footer>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
||||||
@livewireScripts
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -133,3 +133,74 @@ Route::get('/multi-select-options', function () { return view('multi-select-opti
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('welcome');
|
return view('welcome');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <?php
|
||||||
|
|
||||||
|
// use Illuminate\Support\Facades\Route;
|
||||||
|
// use App\Http\Middleware\Authenticate;
|
||||||
|
// use App\Livewire\Login;
|
||||||
|
// use App\Livewire\Registration;
|
||||||
|
// use App\Livewire\ChangePassword;
|
||||||
|
// use App\Livewire\PublicTopSuccessPage;
|
||||||
|
// use App\Livewire\PublicTopErrorPage;
|
||||||
|
// use App\Livewire\MyProfile;
|
||||||
|
// use App\Livewire\Notifications;
|
||||||
|
// use App\Livewire\UserManagement;
|
||||||
|
// use App\Livewire\MemberManagement;
|
||||||
|
// use App\Livewire\PhotoSlider;
|
||||||
|
// use App\Livewire\Promotions;
|
||||||
|
// use App\Livewire\TopUp;
|
||||||
|
// use App\Livewire\CardTypes;
|
||||||
|
// use App\Livewire\Reports;
|
||||||
|
// use App\Livewire\SystemPreferences;
|
||||||
|
// use App\Livewire\StationLocator;
|
||||||
|
// use App\Livewire\Branches;
|
||||||
|
// use App\Livewire\Fuels;
|
||||||
|
// use App\Livewire\Page404;
|
||||||
|
|
||||||
|
// Route::middleware(['check.auth'])->group(function () {
|
||||||
|
// // Public Routes
|
||||||
|
// Route::get('/', fn () => redirect('/login'));
|
||||||
|
// Route::get('/login', Login::class)->name('login');
|
||||||
|
// Route::get('/registration', Registration::class)->name('registration');
|
||||||
|
// Route::get('/change-password', ChangePassword::class)->name('change-password');
|
||||||
|
// Route::get('/topup-success-page', PublicTopSuccessPage::class)->name('topup-success');
|
||||||
|
// Route::get('/topup-error-page', PublicTopErrorPage::class)->name('topup-error');
|
||||||
|
|
||||||
|
// // Private Routes (require authentication)
|
||||||
|
// Route::middleware(['auth'])->group(function () {
|
||||||
|
// Route::get('/user-management', UserManagement::class)->name('user-management');
|
||||||
|
// Route::get('/notifications', Notifications::class)->name('notifications');
|
||||||
|
// Route::get('/member-management', MemberManagement::class)->name('member-management');
|
||||||
|
// Route::get('/home-page', PhotoSlider::class)->name('home-page');
|
||||||
|
// Route::get('/promotions', Promotions::class)->name('promotions');
|
||||||
|
// Route::get('/top-up', TopUp::class)->name('top-up');
|
||||||
|
// Route::get('/about-us', CardTypes::class)->name('about-us');
|
||||||
|
// Route::get('/reports', Reports::class)->name('reports');
|
||||||
|
// Route::get('/stations', StationLocator::class)->name('stations');
|
||||||
|
// Route::get('/branches', Branches::class)->name('branches');
|
||||||
|
// Route::get('/fuels', Fuels::class)->name('fuels');
|
||||||
|
// Route::get('/system-parameters', SystemPreferences::class)->name('system-parameters');
|
||||||
|
// Route::get('/my-profile', MyProfile::class)->name('my-profile');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // 404 Route
|
||||||
|
// Route::get('/404', Page404::class)->name('404');
|
||||||
|
// Route::any('{any}', fn () => redirect()->route('404'))->where('any', '.*');
|
||||||
|
// });
|
||||||
|
|
Loading…
Reference in New Issue