add logout and authentification
This commit is contained in:
parent
4752b23f35
commit
77e5aa93f5
@ -50,4 +50,14 @@ public function authenticate(Request $request)
|
|||||||
return redirect('/home');
|
return redirect('/home');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function logout(Request $request)
|
||||||
|
{
|
||||||
|
auth()->logout();
|
||||||
|
|
||||||
|
$request->session()->invalidate();
|
||||||
|
$request->session()->regenerateToken();
|
||||||
|
|
||||||
|
return redirect('/home');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,18 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/home">Home</a></li>
|
<li><a href="/home">Home</a></li>
|
||||||
|
@auth
|
||||||
|
<li>Welcome {{ auth()->user()->name }}</li>
|
||||||
|
<li>
|
||||||
|
<form class="inline" method="POST" action="/logout">
|
||||||
|
@csrf
|
||||||
|
<button type="submit">Logout</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
@else
|
||||||
<li><a href="/register">Register</a></li>
|
<li><a href="/register">Register</a></li>
|
||||||
<li><a href="/login">Login</a></li>
|
<li><a href="/login">Login</a></li>
|
||||||
<li>Logout</li>
|
@endauth
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<main>
|
<main>
|
||||||
|
@ -22,15 +22,15 @@
|
|||||||
// index - show all devices
|
// index - show all devices
|
||||||
Route::get('/devices', [DeviceController::class, 'index']);
|
Route::get('/devices', [DeviceController::class, 'index']);
|
||||||
// create - show device create form
|
// create - show device create form
|
||||||
Route::get('/devices/create', [DeviceController::class, 'create']);
|
Route::get('/devices/create', [DeviceController::class, 'create'])->middleware('auth');
|
||||||
// store - store new device
|
// store - store new device
|
||||||
Route::post('/devices', [DeviceController::class, 'store']);
|
Route::post('/devices', [DeviceController::class, 'store'])->middleware('auth');
|
||||||
// edit - show edit form
|
// edit - show edit form
|
||||||
Route::get('devices/{device}/edit', [DeviceController::class, 'edit']);
|
Route::get('devices/{device}/edit', [DeviceController::class, 'edit'])->middleware('auth');
|
||||||
// update - update device
|
// update - update device
|
||||||
Route::put('devices/{device}', [DeviceController::class, 'update']);
|
Route::put('devices/{device}', [DeviceController::class, 'update'])->middleware('auth');
|
||||||
// destroy - delete device
|
// destroy - delete device
|
||||||
Route::delete('devices/{device}', [DeviceController::class, 'destroy']);
|
Route::delete('devices/{device}', [DeviceController::class, 'destroy'])->middleware('auth');
|
||||||
// show - show sigle device
|
// show - show sigle device
|
||||||
Route::get('/devices/{device}', [DeviceController::class, 'show']);
|
Route::get('/devices/{device}', [DeviceController::class, 'show']);
|
||||||
|
|
||||||
@ -39,6 +39,8 @@
|
|||||||
// store - store new user
|
// store - store new user
|
||||||
Route::post('/users', [UserController::class, 'store']);
|
Route::post('/users', [UserController::class, 'store']);
|
||||||
// login - show user login form
|
// login - show user login form
|
||||||
Route::get('/login', [UserController::class, 'login']);
|
Route::get('/login', [UserController::class, 'login'])->name('login');
|
||||||
// authenticate - log in user
|
// authenticate - log in user
|
||||||
Route::post('/users/authenticate', [UserController::class, 'authenticate']);
|
Route::post('/users/authenticate', [UserController::class, 'authenticate']);
|
||||||
|
// logout - log out user
|
||||||
|
Route::post('/logout', [UserController::class, 'logout']);
|
||||||
|
Loading…
Reference in New Issue
Block a user