aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2020-10-28 00:19:52 +0100
committerMateja <mail@matejamaric.com>2020-10-28 00:19:52 +0100
commit806b02418b9ee53039de96baf9cfcca1c6fa9257 (patch)
tree1ce01e02f33bd1e6349f7e4a9a9d168f683496bc
parenta3d432a6a0710261149fdaecdc2a5a62a82fe303 (diff)
downloadyota-laravel-806b02418b9ee53039de96baf9cfcca1c6fa9257.tar.gz
yota-laravel-806b02418b9ee53039de96baf9cfcca1c6fa9257.zip
Authentication implemented.
-rw-r--r--app/Http/Controllers/PagesController.php14
-rw-r--r--resources/views/inc/navbar.blade.php2
-rw-r--r--resources/views/pages/login.blade.php3
-rw-r--r--routes/web.php1
4 files changed, 17 insertions, 3 deletions
diff --git a/app/Http/Controllers/PagesController.php b/app/Http/Controllers/PagesController.php
index 5041f05..f42ae3e 100644
--- a/app/Http/Controllers/PagesController.php
+++ b/app/Http/Controllers/PagesController.php
@@ -9,6 +9,7 @@ use function redirect;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
+use Illuminate\Support\Facades\Auth;
class PagesController extends Controller
{
@@ -40,6 +41,12 @@ class PagesController extends Controller
return view('pages.login');
}
+ public function logout(Request $request)
+ {
+ Auth::logout();
+ return Redirect::back();
+ }
+
public function activities(Request $request)
{
return view('pages.activities');
@@ -84,7 +91,6 @@ class PagesController extends Controller
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails()) {
- //return redirect('login')
return Redirect::back()
->withErrors($validator)
->withInput();
@@ -95,7 +101,11 @@ class PagesController extends Controller
//'password' => 'required',
//]);
//return redirect('login')->with('status', 'Submitted.');
- return Redirect::back()->with('status', 'Submitted.');
+ //return Redirect::back()->with('status', 'Submitted.');
+ if (Auth::attempt($request->only('email', 'password')))
+ return redirect()->intended(route('home'));
+ else return Redirect::back()
+ ->withErrors(['failed' => ['Bad credentials!']]);
}
diff --git a/resources/views/inc/navbar.blade.php b/resources/views/inc/navbar.blade.php
index 01b73f1..aa28eae 100644
--- a/resources/views/inc/navbar.blade.php
+++ b/resources/views/inc/navbar.blade.php
@@ -25,7 +25,7 @@
<a class="dropdown-item" href="#">Reservations</a>
</div>
</div>
- <a href="#" class="nav-item nav-link">Logout</a>
+ <a href="{{ route('logout') }}" class="nav-item nav-link">Logout</a>
@else
<a href="{{ route('login') }}" class="nav-item nav-link {{ request()->routeIs('login') ? 'active' : '' }}">Login</a>
@endif
diff --git a/resources/views/pages/login.blade.php b/resources/views/pages/login.blade.php
index b323872..473c23f 100644
--- a/resources/views/pages/login.blade.php
+++ b/resources/views/pages/login.blade.php
@@ -6,6 +6,9 @@
{{ session('status') }}
</div>
@endif
+@error('failed')
+ <div class="alert alert-danger mt-2">{{ $message }}</div>
+@enderror
<form action="{{ route('login') }}" method="POST">
@csrf
<div class="form-group">
diff --git a/routes/web.php b/routes/web.php
index 0d42dc9..7a156a4 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -40,6 +40,7 @@ Route::post('/reserve', [PagesController::class, 'reserveForm'])->name('reserveF
Route::get('/login', [PagesController::class, 'login'])->name('login');
Route::post('/login', [PagesController::class, 'loginForm'])->name('loginForm');
+Route::get('/logout', [PagesController::class, 'logout'])->name('logout');
//Route::get('/about', [PagesController::class, 'about'])->name('about');
//Route::get('/about', 'App\Http\Controllers\PagesController@about');