Added new admin features, updated login functionality, and modified orders view

This commit is contained in:
UronShrestha
2024-07-15 13:51:36 +05:45
parent d8e17eef70
commit 9c427917b8
8 changed files with 203 additions and 38 deletions

View File

@ -100,18 +100,44 @@ class MainController extends Controller
// }
// }
//old loginUser
// public function loginUser(Request $data)
// {
// $user = User::where('email', $data->input('email'))->first();
// //if ($user && Hash::check($data->input('password'), $user->password)) {
// if ($user && Hash::check($data->input('password'), $user->password) && $user->status == 'Active') {
// session()->put('id', $user->id);
// session()->put('type', $user->type);
// if ($user->type == 'Customer') {
// return redirect('/');
// } else if ($user->type == 'Admin') {
// return redirect('/admin');
// }
// }
// return redirect('login')->with('error', 'Invalid email or password!');
// }
//new loginUser
public function loginUser(Request $data)
{
$user = User::where('email', $data->input('email'))->first();
if ($user && Hash::check($data->input('password'), $user->password)) {
session()->put('id', $user->id);
session()->put('type', $user->type);
if ($user->status == 'Active') {
session()->put('id', $user->id);
session()->put('type', $user->type);
if ($user->type == 'Customer') {
return redirect('/');
} else if ($user->type == 'Admin') {
return redirect('/admin');
if ($user->type == 'Customer') {
return redirect('/');
} elseif ($user->type == 'Admin') {
return redirect('/admin');
}
} elseif ($user->status == 'Blocked') {
return redirect('login')->with('error', 'Your account is blocked. Please contact support.');
}
}
@ -214,21 +240,6 @@ class MainController extends Controller
}
// public function myOrders()
// {
// if (session()->has('id')) {
// $orders = Order::where('customerId', session()->get('id'))->get();
// // dd($orders);
// $items = DB::table('products')
// ->join('order_items', 'order_items.productId', '=', 'products.id')
// ->select('products.name', 'products.picture', 'products.*')
// ->get();
// return view('orders', compact('orders', 'items'));
// }
// return view('login');
// }
//old myOrders
// public function myOrders()
@ -250,19 +261,22 @@ class MainController extends Controller
//new myOrders
public function myOrders()
{
if (session()->has('id')) {
$orders = Order::where('customerId', session()->get('id'))->get();
if (session()->get('type') == 'Customer') {
if (session()->has('id')) {
$orders = Order::where('customerId', session()->get('id'))->get();
$items = DB::table('products')
->join('order_items', 'order_items.productId', '=', 'products.id')
->select('products.name', 'products.picture', 'order_items.*')
$items = DB::table('products')
->join('order_items', 'order_items.productId', '=', 'products.id')
->select('products.name', 'products.picture', 'order_items.*')
->get();
->get();
return view('orders', compact('orders', 'items'));
return view('orders', compact('orders', 'items'));
}
return view('login');
}
return view('login');
return redirect()->back();
}