From 0f99d28a816339a73c87110972d8f89a832eb18a Mon Sep 17 00:00:00 2001 From: Hasin Hayder Date: Wed, 18 May 2022 22:13:23 +0600 Subject: [PATCH] Cleanup SPA Code - That will be a separate project --- app/Http/Controllers/LoginSPAController.php | 58 -------------- resources/js/app.js | 20 ----- resources/js/bootstrap.js | 2 +- resources/views/login.blade.php | 86 --------------------- resources/views/welcome.blade.php | 11 +-- routes/web.php | 8 +- 6 files changed, 4 insertions(+), 181 deletions(-) delete mode 100644 app/Http/Controllers/LoginSPAController.php delete mode 100644 resources/views/login.blade.php diff --git a/app/Http/Controllers/LoginSPAController.php b/app/Http/Controllers/LoginSPAController.php deleted file mode 100644 index 3f824de..0000000 --- a/app/Http/Controllers/LoginSPAController.php +++ /dev/null @@ -1,58 +0,0 @@ -validate([ - 'email' => ['required', 'email'], - 'password' => ['required'], - ]); - - if (Auth::attempt($credentials)) { - $request->session()->regenerate(); - return redirect()->route('home'); - } - - return back()->withErrors([ - 'email' => 'Invalid Credentials', - ])->onlyInput('email'); - } - - public function register(Request $request) { - $creds = $request->validate([ - 'email' => 'required|email', - 'password' => 'required' - ]); - - $user = User::where('email', $creds['email'])->first(); - if (!$user) { - User::create([ - 'name' => $request->name, - 'email' => $creds['email'], - 'password' => Hash::make($creds['password']) - ]); - } - - return $this->login($request); - } - - public function logout(Request $request) { - Auth::logout(); - $request->session()->invalidate(); - $request->session()->regenerateToken(); - return redirect('/'); - } - - function loginForm() { - if (Auth::check()) { - return redirect('/'); - } - return view('login'); - } -} diff --git a/resources/js/app.js b/resources/js/app.js index a4a4c86..e74d43c 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,22 +1,2 @@ -const { default: axios } = require('axios'); - require('./bootstrap'); -const app = { - init(){ - //do something - }, - login(){ - axios.get('/sanctum/csrf-cookie').then(response => { - axios.post('/login',{ - 'email':'email@example.com', - 'password':'ThisIsABadPassword' - }).then(response=>{ - location.href='/' - }) - }); - } -} - -window.app = app -app.init() diff --git a/resources/js/bootstrap.js b/resources/js/bootstrap.js index 87e1452..2bb9958 100644 --- a/resources/js/bootstrap.js +++ b/resources/js/bootstrap.js @@ -7,7 +7,7 @@ window._ = require('lodash'); */ window.axios = require('axios'); -window.axios.defaults.withCredentials = true; +// window.axios.defaults.withCredentials = true; window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; /** diff --git a/resources/views/login.blade.php b/resources/views/login.blade.php deleted file mode 100644 index 129a58e..0000000 --- a/resources/views/login.blade.php +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - Login - - - - - -
- -
- - -
-

Brand

- -

Welcome back!

- - {{-- -
- - - - - - -
- - Sign in with Google -
--}} -
- @csrf -
- - - Login / Register - - -
- -
- - -
- -
- - -
- -
-
- - -
- - -
- -
- -
- -
- - - or sign up - - -
-
- - {{-- --}} -
-
-
- - - diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index d79f55f..dd6a45d 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -25,14 +25,12 @@ @if (Route::has('login')) @@ -46,11 +44,6 @@ - @if (Auth::check()) -
-

Welcome, {{Auth::user()->name}}

-
- @endif
diff --git a/routes/web.php b/routes/web.php index 0aa4127..b130397 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1,6 @@ name('home'); - -Route::post('/register',[LoginSPAController::class,'register']); -Route::post('/login',[LoginSPAController::class,'login']); -Route::get('/logout',[LoginSPAController::class,'logout'])->name('logout'); -Route::get('/login',[LoginSPAController::class,'loginForm'])->name('login'); +});