本文整理汇总了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));
}