コード例 #1
0
ファイル: AuthController.php プロジェクト: Yatko/Gifteng
 /**
  * Authenticate the user
  * 
  * @return Response
  */
 public function store()
 {
     try {
         $userAgent = array("platform" => Useragent::platform(), "browser" => Useragent::browser(), "version" => Useragent::version(), "mobile" => Useragent::mobile(), "robot" => Useragent::robot(), "agent" => Useragent::agent_string(), "accept_lang" => Useragent::accept_lang(), "accept_charset" => Useragent::accept_charset(), "ip_address" => $_SERVER['REMOTE_ADDR']);
         if (Input::get('password')) {
             $authService = new SoapClient(Config::get('wsdl.auth'));
             $token = $authService->authenticateEmail(array("email" => Input::get('email'), "password" => Input::get('password'), "userAgent" => print_r($userAgent, true)));
             ini_set('soap.wsdl_cache_enabled', '0');
             ini_set('user_agent', "PHP-SOAP/" . PHP_VERSION . "\r\n" . "AuthToken: " . $token->AuthToken);
             Session::put('user.token', $token);
             try {
                 $userService = new SoapClient(Config::get('wsdl.user'));
                 $result = $userService->getUserByEmail(array("email" => Input::get('email')));
                 $user = $result->user;
                 if ($user->businessAccount == true) {
                     if (isset($user->addresses) && is_object($user->addresses)) {
                         $user->addresses = array($user->addresses);
                     }
                 }
                 Session::put('user.data', $user);
                 return array('success' => 'true');
             } catch (InnerException $ex) {
                 throw new Exception($ex->faultstring);
             }
         }
     } catch (Exception $ex) {
         return array('error' => $ex->getMessage());
     }
 }
コード例 #2
0
ファイル: InviteController.php プロジェクト: Yatko/Gifteng
 /**
  * Invokes the user registration on WS.
  *
  * @return response
  * @throws Exception in case of WS error
  */
 public function registerUser()
 {
     try {
         $userService = new SoapClient(Config::get('wsdl.user'));
         $user = new UserModel(Input::all());
         $array = array("user" => $user, "password" => Input::get('password'), "invitationCode" => Input::get('code'));
         if (Input::get('ref')) {
             $array['referrerId'] = Input::get('ref');
         }
         $result = $userService->registerUser($array);
         $authService = new SoapClient(Config::get('wsdl.auth'));
         $token = $authService->authenticateEmail(array("email" => Input::get('email'), "password" => Input::get('password'), "userAgent" => NULL));
         ini_set('soap.wsdl_cache_enabled', '0');
         ini_set('user_agent', "PHP-SOAP/" . PHP_VERSION . "\r\n" . "AuthToken: " . $token->AuthToken);
         Session::put('user.token', $token);
         try {
             $userService = new SoapClient(Config::get('wsdl.user'));
             $result = $userService->getUserByEmail(array("email" => Input::get('email')));
             $user = $result->user;
             /*	if ($user -> businessAccount == true) {
             				if (isset($user -> addresses) && is_object($user -> addresses)) {
             					$user -> addresses = array($user -> addresses);
             				}
             			}  */
             Session::put('user.data', $user);
             return array('success' => true);
         } catch (InnerException $ex) {
             //throw new Exception($ex -> faultstring);
             return array('success' => false, 'faultstring' => $ex->faultstring);
         }
     } catch (Exception $ex) {
         return array('success' => false, 'faultstring' => $ex->faultstring);
     }
 }
コード例 #3
0
ファイル: BizController.php プロジェクト: Yatko/Gifteng
 /**
  * Update profile
  * 
  * @return Response
  */
 public function updateProfile()
 {
     $session = Session::get('user');
     $userService = new SoapClient(Config::get('wsdl.user'), array());
     $geoService = new SoapClient(Config::get('wsdl.utility'), array());
     $currentUser = $userService->getUserByEmail(array('email' => $session['data']->email))->user;
     $currentUser->businessName = Input::get('businessName');
     $currentUser->about = Input::get('about');
     $currentUser->address = $geoService->getAddressByZipcode(array("zipcode" => Input::get('zipCode')))->address;
     $currentUser->website = Input::get('website');
     $currentUser->contactName = Input::get('contactName');
     $currentUser->contactNumber = Input::get('contactNumber');
     $currentUser->email = Input::get('email');
     try {
         $userService->updateUser(array('user' => $currentUser));
     } catch (Exception $ex) {
     }
 }
コード例 #4
0
ファイル: UserController.php プロジェクト: Yatko/Gifteng
 /**
  * Update profile
  * 
  * @return Response
  */
 public function updateProfile()
 {
     $session = Session::get('user');
     $userService = new SoapClient(Config::get('wsdl.user'), array());
     $geoService = new SoapClient(Config::get('wsdl.utility'), array());
     $currentUser = $userService->getUserByEmail(array('email' => $session['data']->email))->user;
     if (!$currentUser->address) {
         $address = new Address();
     } else {
         $address = new Address($currentUser->address);
     }
     $currentUser->firstName = Input::get('first_name');
     $currentUser->lastName = Input::get('last_name');
     $currentUser->about = Input::get('about');
     if (Input::get('zipCode')) {
         $address = $geoService->getAddressByZipcode(array("zipcode" => Input::get('zipCode')));
         $currentUser->address = $address->address;
     } else {
         if (Input::get('zipCode') == "") {
             $currentUser->address = new Address();
         }
     }
     try {
         $userService->updateUser(array('user' => $currentUser));
     } catch (Exception $ex) {
     }
 }
コード例 #5
0
ファイル: StoreController.php プロジェクト: Yatko/Gifteng
 /**
  * Delete store
  * 
  * @return Response
  */
 public function destroy($id)
 {
     $session = Session::get('user');
     $userService = new SoapClient(Config::get('wsdl.user'), array());
     $currentUser = $userService->getUserByEmail(array('email' => $session['data']->email))->user;
     if (is_object($currentUser->addresses)) {
         $currentUser->addresses = array($currentUser->addresses);
     }
     $addresses = $currentUser->addresses;
     foreach ($addresses as $k => $val) {
         if ($val->id == $id) {
             $val->deleted = true;
             $addresses[$k] = $val;
         }
     }
     $currentUser->addresses = $addresses;
     try {
         $userService->updateUser(array('user' => $currentUser));
     } catch (Exception $ex) {
     }
 }
コード例 #6
0
ファイル: AdController.php プロジェクト: Yatko/Gifteng
 /**
  * Ad listing.
  *
  * @return Response
  */
 public function index()
 {
     try {
         $session = Session::get('user');
         $userService = new SoapClient(Config::get('wsdl.user'), array());
         $currentUser = $userService->getUserByEmail(array('email' => $session['data']->email))->user;
         $filter = new Filter();
         $filter->includeOwned = 1;
         $filter->includeCannotRequest = 1;
         $filter->includeInactive = 0;
         $filter->includePickUp = null;
         $filter->includeShipping = null;
         $type = Input::get('order');
         $adtype = Input::get('types');
         $filter->searchString = Input::get('keywords');
         if (Input::get('category')) {
             $category = array(Input::get('category'));
         } else {
             $category = null;
         }
         if ($delivery = Input::get('delivery')) {
             if ($delivery == "pickup") {
                 $filter->includePickUp = 1;
                 $filter->includeShipping = null;
             } else {
                 if ($delivery == "shipping") {
                     $filter->includePickUp = null;
                     $filter->includeShipping = 1;
                 }
             }
         }
         $filter->categories = $category;
         if (!$type) {
             $type = AdController::TYPE_NEWEST;
         }
         if ($type == AdController::TYPE_NEWEST) {
             $filter->orderAsc = false;
             $filter->orderClosest = false;
             $filter->filterType = Filter::FILTER_TYPE_ACTIVE;
         } else {
             if ($type == AdController::TYPE_OLDEST) {
                 $filter->orderAsc = true;
                 $filter->orderClosest = false;
                 $filter->filterType = Filter::FILTER_TYPE_ACTIVE;
             } else {
                 if ($type == AdController::TYPE_CLOSEST) {
                     $filter->orderAsc = true;
                     $filter->orderClosest = true;
                     $filter->filterType = Filter::FILTER_TYPE_ACTIVE;
                     $filter->latitude = $currentUser != null && $currentUser->address != null && isset($currentUser->address->latitude) ? $currentUser->address->latitude : null;
                     $filter->longitude = $currentUser != null && $currentUser->address != null && isset($currentUser->address->longitude) ? $currentUser->address->longitude : null;
                 } else {
                     if ($type == AdController::TYPE_GIFTED) {
                         $filter->orderAsc = false;
                         $filter->orderClosest = false;
                         $filter->filterType = Filter::FILTER_TYPE_GIFTED;
                     }
                 }
             }
         }
         if ($adtype) {
             $filter->types = $adtype;
         }
         $adService = new SoapClient(Config::get('wsdl.ad'), array());
         $result = $adService->getAdsExDetail(array("lastIndex" => -1, "numberAds" => 15, "filter" => $filter, "includeImages" => true, "includeCreator" => true, "includeCommentsNumber" => 2, "includeCreatorStatistics" => true));
         $creators = array();
         if (isset($result->ad->type)) {
             $ads = $result;
         } elseif (isset($result->ad)) {
             $ads = $result->ad;
         } else {
             $ads = array();
         }
         $results = array();
         foreach ($ads as $k => $ad) {
             $ad = new Ad($ad);
             $creators[$ad->creator->id] = $ad->creator;
             if (isset($currentUser->address) && isset($currentUser->address->latitude) && isset($currentUser->address->longitude) && isset($ad->address) && isset($ad->address->latitude) && isset($ad->address->longitude)) {
                 $ad->distance = $this->distance_haversine($currentUser->address->latitude, $currentUser->address->longitude, $ad->address->latitude, $ad->address->longitude);
             }
             if (isset($ad->requests)) {
                 if (is_array($ad->requests->item)) {
                     foreach ($ad->requests->item as $k => $v) {
                         $v = new Requested($v);
                         if ($v->user->id == $user_id) {
                             $ad->request = $v;
                         }
                     }
                 } else {
                     $v = new Requested($ad->requests->item);
                     if ($v->user->id == $user_id) {
                         $ad->request = $v;
                     }
                 }
             }
             if (isset($ad->comments) && isset($ad->comments->item)) {
                 if (!is_array($ad->comments->item)) {
                     $ad->comments->item = array($ad->comments->item);
                 }
             }
             if (!$ad->online) {
                 if ($ad->approved) {
                     $ad->status = "APPROVED";
                 } else {
                     if ($ad->approval == null) {
                         $ad->status = "PENDING";
                     } else {
                         $ad->status = "DECLINED";
                     }
                 }
             } elseif ($ad->sold && $ad->getAcceptedRequest()) {
                 $requestor = $ad->getAcceptedRequest()->user;
                 $request = $ad->getAcceptedRequest();
                 if (isset($requestor->avatar)) {
                     $ad->requestor = $requestor->avatar->id;
                 } else {
                     $ad->requestor = null;
                 }
                 if (isset($request)) {
                     $ad->request = $request;
                 } else {
                     $ad->request = null;
                 }
                 $ad->status = "SOLD";
             } elseif ($ad->expired) {
                 $ad->status = "EXPIRED";
             } elseif (!$ad->hasActiveRequest()) {
                 $ad->status = "NO_REQUESTS";
             } elseif ($ad->hasSentRequest()) {
                 $requestor = $ad->getAcceptedRequest()->user;
                 if (isset($requestor->avatar)) {
                     $ad->requestor = $requestor->avatar->id;
                 } else {
                     $ad->requestor = null;
                 }
                 if (isset($request)) {
                     $ad->request = $request;
                 } else {
                     $ad->request = null;
                 }
                 $ad->status = "SENT";
             } elseif ($ad->hasAcceptedRequest()) {
                 $requestor = $ad->getAcceptedRequest()->user;
                 if (isset($requestor->avatar)) {
                     $ad->requestor = $requestor->avatar->id;
                 } else {
                     $ad->requestor = null;
                 }
                 if (isset($request)) {
                     $ad->request = $request;
                 } else {
                     $ad->request = null;
                 }
                 $ad->status = "SELECTED";
             } else {
                 $ad->status = "ACTIVE";
             }
             if (isset($ad->request)) {
                 $request = $ad->request;
                 if ($ad->expired || $request->isExpired) {
                     if ($ad->request->adStatus == "EXPIRED") {
                         $ad->reqStat = "EXPIRED";
                     } else {
                         if ($ad->request->isCanceled) {
                             $ad->reqStat = "CANCELED";
                         } else {
                             $ad->reqStat = "DECLINED";
                         }
                     }
                 } else {
                     if ($ad->sold) {
                         $ad->reqStat = "RECEIVED";
                     } else {
                         if ($request->isPending) {
                             $ad->reqStat = "PENDING";
                         } else {
                             if ($request->accepted) {
                                 $ad->reqStat = "ACCEPTED";
                             }
                         }
                     }
                 }
             }
             if ($filter->filterType == Filter::FILTER_TYPE_GIFTED) {
                 $ad->sold = true;
             }
             $results[] = $ad;
         }
         return array('ads' => $results, 'creators' => $creators);
     } catch (Exception $ex) {
         throw new Exception($ex->getMessage());
     }
 }