public function login() { $credentials = Input::only(['email', 'password']); $validator = Validator::make($credentials, array('email' => 'required|email', 'password' => 'required|min:4')); //validation if ($validator->fails()) { return Response::json($validator->messages(), 400); } if (!($token = JWTAuth::attempt($credentials))) { return Response::json(array('error' => array('message' => 'Authentication failed')), 401); } try { $customer = JWTAuth::toUser($token); } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) { // token has expired return Response::json(array('error' => array('message' => 'Token expired')), 401); } if (!$customer) { return Response::json(array('error' => array('message' => 'customer not found')), 404); } context::setCustomer($customer); $cart = NULL; $wishlist = NULL; try { $cart = unserialize($customer->cart); } catch (Exception $e) { } try { $wishlist = unserialize($customer->wishlist); } catch (Exception $e) { } if ($cart == NULL) { $cart = new Cart(Cart::SHOPPING_CART); } if ($wishlist == NULL) { $wishlist = new Cart(Cart::WISHLIST_CART); } //Import from session //$cart->import($this->active_settings->carts[Cart::SHOPPING_CART]); //$wishlist->import($this->active_settings->carts[Cart::WISHLIST_CART]); //$this->active_settings->carts[Cart::SHOPPING_CART] = $cart; //$this->active_settings->carts[Cart::WISHLIST_CART] = $wishlist; //$this->active_settings->save(); return Response::json(array('auth_token' => $token, 'customer' => $customer, 'shoppingCart' => $cart, 'wishList' => $wishlist)); }