本文整理匯總了PHP中context::setCustomer方法的典型用法代碼示例。如果您正苦於以下問題:PHP context::setCustomer方法的具體用法?PHP context::setCustomer怎麽用?PHP context::setCustomer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類context
的用法示例。
在下文中一共展示了context::setCustomer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: login
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));
}