From f719b971d7e87bf439dc4055efcbfc01bae80a77 Mon Sep 17 00:00:00 2001 From: Slymee Date: Tue, 16 Jan 2024 13:32:30 +0545 Subject: [PATCH] Redirect to home from login if already logged in: complete && changed if statement format --- app/Http/Controllers/AdminController.php | 4 ++-- app/Http/Controllers/CategoryController.php | 2 -- app/Http/Controllers/PasswordResetController.php | 4 ++-- app/Http/Controllers/UserController.php | 4 ++-- app/Http/Controllers/UserPasswordResetController.php | 4 ++-- app/Http/Middleware/GuestAuthenticate.php | 4 ++-- app/Http/Middleware/LoginPageAuthenticate.php | 4 ++-- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index c74f401..b7378c2 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -21,9 +21,9 @@ public function index(){ */ public function login(LoginRequest $request){ try{ - if(auth()->guard('admin')->attempt($request->only(['username', 'password']))): + if(auth()->guard('admin')->attempt($request->only(['username', 'password']))){ return redirect(route('admin.dashboard')); - endif; + } return redirect()->back()->with('message', 'Invalid Credentials'); /** * diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 5518a80..f1a6bf2 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -48,7 +48,6 @@ public function store(CategoryRequest $request) 'category_name' => $request->category_name, 'parent_id' => $request->parent_id, ]); - return redirect()->back()->with('message', 'Category Inserted.'); }catch(\Exception $e){ return redirect()->back()->with('message', $e->getMessage()); @@ -101,7 +100,6 @@ public function update(CategoryRequest $request) return redirect()->back()->with('message', 'Edit Success!'); - // return redirect()->back()->with('message', 'Edit Failed!'); }catch(\Exception $e){ return redirect()->back()->with('message', $e->getMessage()); } diff --git a/app/Http/Controllers/PasswordResetController.php b/app/Http/Controllers/PasswordResetController.php index d9c2d71..a3cde07 100644 --- a/app/Http/Controllers/PasswordResetController.php +++ b/app/Http/Controllers/PasswordResetController.php @@ -54,9 +54,9 @@ public function showNewPasswordForm(string $token){ public function submitAdminNewPassword(ResetPasswordRequest $request){ try{ $tokenData = DB::table('password_reset_tokens')->where('token', $request->validated()['token'])->first(); - if(!$tokenData): + if(!$tokenData){ return back()->with(['message' => 'Invalid token id!!']); - endif; + } Admin::where('email', $tokenData->email)->first()->update([ 'password' => Hash::make($request->validated()['new-password']), ]); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 010b8d4..698799a 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -37,9 +37,9 @@ public function registerUser(RegisterUserRequest $request){ //User Login module public function loginUser(LoginRequest $request){ try{ - if(Auth::guard('web')->attempt(['username' => $request->username, 'password' => $request->password])): + if(Auth::guard('web')->attempt(['username' => $request->username, 'password' => $request->password])){ return redirect()->intended(); - endif; + } return redirect()->back()->with('message', 'Invalid Credentials'); }catch(\Exception $e){ diff --git a/app/Http/Controllers/UserPasswordResetController.php b/app/Http/Controllers/UserPasswordResetController.php index 2b751b6..03250d5 100644 --- a/app/Http/Controllers/UserPasswordResetController.php +++ b/app/Http/Controllers/UserPasswordResetController.php @@ -48,9 +48,9 @@ public function showNewPasswordForm(string $token){ public function submitNewPassword(ResetPasswordRequest $request){ try{ $tokenData = DB::table('password_reset_tokens')->where('token', $request->validated()['token'])->first(); - if(!$tokenData): + if(!$tokenData){ return back()->with(['message' => 'Invalid token id!!']); - endif; + } User::where('email', $tokenData->email)->first()->update([ 'password' => Hash::make($request->validated()['new-password']), ]); diff --git a/app/Http/Middleware/GuestAuthenticate.php b/app/Http/Middleware/GuestAuthenticate.php index 44a8259..c3b410c 100644 --- a/app/Http/Middleware/GuestAuthenticate.php +++ b/app/Http/Middleware/GuestAuthenticate.php @@ -17,9 +17,9 @@ class GuestAuthenticate */ public function handle(Request $request, Closure $next): Response { - if(!Auth::guard('web')->check()): + if(!Auth::guard('web')->check()){ return redirect('/login'); - endif; + } return $next($request); } } diff --git a/app/Http/Middleware/LoginPageAuthenticate.php b/app/Http/Middleware/LoginPageAuthenticate.php index 9707729..0eddb45 100644 --- a/app/Http/Middleware/LoginPageAuthenticate.php +++ b/app/Http/Middleware/LoginPageAuthenticate.php @@ -16,9 +16,9 @@ class LoginPageAuthenticate */ public function handle(Request $request, Closure $next): Response { - if(Auth::guard('web')->check()): + if(Auth::guard('web')->check()){ return redirect('/home'); - endif; + } return $next($request); } }