"Added admin type checks and redirects in AdminController and MainController; updated product views and admin header"
This commit is contained in:
@ -20,13 +20,16 @@ class MainController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$allProducts = Products::all();
|
||||
//dd($allProducts);
|
||||
$newArrival = Products::where('type', 'new-arrival')->get();
|
||||
$hotSale = Products::where('type', 'sale')->get();
|
||||
if (session()->get('type') == 'Customer') {
|
||||
$allProducts = Products::all();
|
||||
//dd($allProducts);
|
||||
$newArrival = Products::where('type', 'new-arrival')->get();
|
||||
$hotSale = Products::where('type', 'sale')->get();
|
||||
|
||||
|
||||
return view('index', compact('allProducts', 'hotSale', 'newArrival'));
|
||||
return view('index', compact('allProducts', 'hotSale', 'newArrival'));
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function about()
|
||||
@ -82,18 +85,37 @@ class MainController extends Controller
|
||||
return view('login');
|
||||
}
|
||||
|
||||
// public function loginUser(Request $data)
|
||||
// {
|
||||
// $user = User::where('email', $data->input('email'))->first();
|
||||
// if ($user && Hash::check($data->input('password'), $user->password)) { // Verifying the hashed password
|
||||
// session()->put('id', $user->id);
|
||||
// session()->put('type', $user->type);
|
||||
// if ($user->type == 'Customer') {
|
||||
// return redirect('/');
|
||||
// }else if($user->type == 'Admin'){
|
||||
// return redirect('/admin)}
|
||||
// } else {
|
||||
// return redirect('login')->with('error', 'Invalid email or password!');
|
||||
// }
|
||||
// }
|
||||
|
||||
public function loginUser(Request $data)
|
||||
{
|
||||
$user = User::where('email', $data->input('email'))->first();
|
||||
if ($user && Hash::check($data->input('password'), $user->password)) { // Verifying the hashed password
|
||||
|
||||
if ($user && Hash::check($data->input('password'), $user->password)) {
|
||||
session()->put('id', $user->id);
|
||||
session()->put('type', $user->type);
|
||||
|
||||
if ($user->type == 'Customer') {
|
||||
return redirect('/');
|
||||
} else if ($user->type == 'Admin') {
|
||||
return redirect('/admin');
|
||||
}
|
||||
} else {
|
||||
return redirect('login')->with('error', 'Invalid email or password!');
|
||||
}
|
||||
|
||||
return redirect('login')->with('error', 'Invalid email or password!');
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user