当前位置: 首页>>代码示例>>PHP>>正文


PHP context::setCustomer方法代码示例

本文整理汇总了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));
 }
开发者ID:pda-code,项目名称:eshop-angular-laravel,代码行数:45,代码来源:CustomerController.php


注:本文中的context::setCustomer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。