Exemplo n.º 1
0
 public function postLogin(Request $request)
 {
     $email = $request->input('email');
     $password = $request->input('password');
     $user = User::where('email', $email)->first();
     if ($user == NULL) {
         return view('auth.login')->withErrors('Email has not been found');
     }
     $cart = new Cart();
     $dictionary = $user->dictionary;
     //        var_dump($dictionary);
     //        die();
     if (strlen($dictionary != 0)) {
         for ($i = 0; $i < strlen($dictionary) - 1; $i += 2) {
             //                var_dump($i);
             $key = $dictionary[$i];
             $i += 2;
             $value = $dictionary[$i];
             $cart->addNewProduct($key);
             $cart->setQuantity($key, $value);
         }
     }
     $cart->setOwnerId($user->id);
     Session::put('cart', $cart);
     if (Hash::check($password, $user->password)) {
         Auth::login($user);
         return redirect('/')->withMessage('Logged in successfully');
     } else {
         return view('auth.login')->withErrors('wrong password');
     }
 }