Skip to content

Commit

Permalink
Redirect to home from login if already logged in: complete && changed…
Browse files Browse the repository at this point in the history
… if statement format
  • Loading branch information
Slymee committed Jan 16, 2024
1 parent 14b846e commit f719b97
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
/**
*
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/PasswordResetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
]);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/UserPasswordResetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
]);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Middleware/GuestAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions app/Http/Middleware/LoginPageAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit f719b97

Please sign in to comment.