From 13a0dcbc603364a20e8b1d6980815d897412fe64 Mon Sep 17 00:00:00 2001 From: Jan_Hill Date: Thu, 19 Dec 2024 09:02:32 +0100 Subject: [PATCH] Login System implements --- app/Http/Controllers/AuthController.php | 33 +++++++++++ resources/js/app.js | 8 +++ resources/views/smart/login.blade.php | 74 +++++++++++++++++++++---- routes/web.php | 16 +++++- 4 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 app/Http/Controllers/AuthController.php diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php new file mode 100644 index 0000000..37edbca --- /dev/null +++ b/app/Http/Controllers/AuthController.php @@ -0,0 +1,33 @@ +validate([ + "email" => "required|email", + "password" => "required" + ]); + + if (Auth::attempt(["email" => $credits["email"], "password" => $credits["password"]])) { + $user = Auth::user(); + + return response()->json(["account" => $user->name], 200); + } + + return response()->json(["error" => "Invalid email or password."], 401); + } catch (\Illuminate\Validation\ValidationException $exception) { + return response()->json(['error' => $exception->errors()], 422); + } catch (\Exception $exception) { + return response()->json(['error' => 'An unexpected error occurred.'], 500); + } + + } +} diff --git a/resources/js/app.js b/resources/js/app.js index 2f0279d..bd18849 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1 +1,9 @@ import 'flowbite'; +import axios from 'axios'; +import Swal from 'sweetalert2'; +import 'animate.css'; + +window.axios = axios; +window.Swal = Swal; + +console.log('Libraries are now available globally:', { axios, Swal }); diff --git a/resources/views/smart/login.blade.php b/resources/views/smart/login.blade.php index 75d1373..edfe90d 100644 --- a/resources/views/smart/login.blade.php +++ b/resources/views/smart/login.blade.php @@ -10,31 +10,31 @@
-
- Brand - NCORE Smart Firewall - NCORE -
+
+ Brand - NCORE Smart Firewall + NCORE +

Secure Login

-
+
- +
- +
- +
@@ -42,6 +42,56 @@
+ + + diff --git a/routes/web.php b/routes/web.php index fb2d645..d0bdfb0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,13 +7,27 @@ Route::get('/', function () { return redirect('cp'); }); +// The Login form when you are not Logged in + Route::Group(['prefix' => 'cp', 'middleware' => 'web'], function () { Route::get('/', function (\Illuminate\Http\Request $request) { if (!Auth::check()) { return redirect()->route('auth'); } else { - return redirect()->route('dashboard'); + return redirect()->route('internal'); } }); Route::get('auth/',[\App\Http\Controllers\SmartController::class, 'index'])->name('auth'); }); + +// Calls for Controllers + +Route::Group(['prefix' => 'call', 'middleware' => 'web'], function () { + Route::post('login', [\App\Http\Controllers\AuthController::class, 'authenticate'])->name('post_login'); +}); + +// Internal Area when do you have permissions and logged in + +Route::Group(['prefix' => 'internal', 'middleware' => 'auth'], function () { + Route::get('dashboard/', [\App\Http\Controllers\SmartController::class, 'dashboard'])->name('dashboard'); +});