當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。