fix user can back to previous page after logout
This commit is contained in:
@@ -4,7 +4,11 @@ namespace App\Http\Controllers\Auth;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Providers\RouteServiceProvider;
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
use Illuminate\Support\Facades\Redirect;
|
||||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
{
|
{
|
||||||
@@ -37,4 +41,31 @@ class LoginController extends Controller
|
|||||||
{
|
{
|
||||||
$this->middleware('guest')->except('logout');
|
$this->middleware('guest')->except('logout');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function login()
|
||||||
|
{
|
||||||
|
return view('auth.login');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function authenticate(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'email' => 'required|string|email',
|
||||||
|
'password' => 'required|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$credentials = $request->only('email', 'password');
|
||||||
|
|
||||||
|
if (Auth::attempt($credentials)) {
|
||||||
|
return view('homepage.home');
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect('login')->with('error', 'Oppes! You have entered invalid credentials');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout(){
|
||||||
|
Auth::logout();
|
||||||
|
Session::flush();
|
||||||
|
return Redirect::to('/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Services\CustomerService;
|
use App\Services\CustomerService;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class GadaianController extends Controller
|
class GadaianController extends Controller
|
||||||
{
|
{
|
||||||
@@ -16,7 +18,7 @@ class GadaianController extends Controller
|
|||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$noic = $request->noic;
|
$noic = $request->noic;
|
||||||
$customer_info = $this->customerService->getCustomerInfo($noic);
|
$customer_info = Http::get(config('api.url') . '/api/customers/'. $noic)->json();
|
||||||
$limit_pinjaman_semasa = $customer_info['limit_pinjaman'] - $customer_info['pinjaman_semasa'];
|
$limit_pinjaman_semasa = $customer_info['limit_pinjaman'] - $customer_info['pinjaman_semasa'];
|
||||||
return view('gadaian.index',compact('customer_info','limit_pinjaman_semasa'));
|
return view('gadaian.index',compact('customer_info','limit_pinjaman_semasa'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class Kernel extends HttpKernel
|
|||||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
\App\Http\Middleware\NoHttpCache::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
||||||
|
|
||||||
|
class NoHttpCache
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
$response = $next($request);
|
||||||
|
|
||||||
|
// This step is only needed if you are returning
|
||||||
|
// a view in your Controller or elsewhere, because
|
||||||
|
// when returning a view `$next($request)` returns
|
||||||
|
// a View object, not a Response object, so we need
|
||||||
|
// to wrap the View back in a Response.
|
||||||
|
if (!$response instanceof SymfonyResponse) {
|
||||||
|
$response = new Response($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $headers \Symfony\Component\HttpFoundation\HeaderBag
|
||||||
|
*/
|
||||||
|
$response->header('Pragma', 'no-cache');
|
||||||
|
$response->header('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT');
|
||||||
|
$response->header('Cache-Control', 'no-cache, must-revalidate, no-store, max-age=0, private');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-3
@@ -15,15 +15,17 @@ use Illuminate\Support\Facades\Route;
|
|||||||
|
|
||||||
Route::get('/',['as'=>'login','uses'=>'HomeController@index']);
|
Route::get('/',['as'=>'login','uses'=>'HomeController@index']);
|
||||||
|
|
||||||
Auth::routes();
|
// Auth::routes();
|
||||||
|
|
||||||
Route::middleware(['auth:juruwang,penilai,khazanah,PPC'])->group(function(){
|
Route::middleware(['auth:juruwang,penilai,khazanah,PPC'])->group(function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\LoginController@logout']);
|
||||||
|
|
||||||
// Route::get('register', 'Auth\RegisterController@register');
|
// Route::get('register', 'Auth\RegisterController@register');
|
||||||
// Route::post('register', 'Auth\RegisterController@store');
|
// Route::post('register', 'Auth\RegisterController@store');
|
||||||
// Route::get('login', 'Auth\LoginController@login')->name('login');
|
Route::get('login', 'Auth\LoginController@login')->name('login');
|
||||||
// Route::post('login', 'Auth\LoginController@authenticate');
|
Route::post('login', 'Auth\LoginController@authenticate');
|
||||||
// Route::get('logout', 'Auth\LoginController@logout')->name('logout');
|
// Route::get('logout', 'Auth\LoginController@logout')->name('logout');
|
||||||
|
|
||||||
Route::get('/', 'HomeController@index')->name('home');
|
Route::get('/', 'HomeController@index')->name('home');
|
||||||
|
|||||||
Reference in New Issue
Block a user