Example #1
0
 /**
  * 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());
     }
 }
Example #2
0
 function deviceInfo()
 {
     $client = Client::get_instance();
     // Referral
     $client->referrer = Useragent::referrer();
     // Heavy detections will be cached in cookie
     $cookieStore = array('device', 'browser', 'browserVersion', 'os', 'country', 'city', 'lat', 'lon', 'timezone');
     $device_info_cookie = Cookie::get('device_info');
     if ($device_info_cookie && ($device_info_cookie = json_decode($device_info_cookie))) {
         foreach ($cookieStore as $key) {
             $client->{$key} = $device_info_cookie->{$key};
         }
     } else {
         // Device and browser
         // Use Mobile_Detect for better device recognition
         $client->device = Useragent::is_mobile() ? 'phone' : 'computer';
         $client->browser = Useragent::browser();
         $client->browserVersion = Useragent::version();
         $client->os = Useragent::platform();
         // Geolocation
         // Defaults to Kyiv
         $gb = new IPGeoBase();
         $geo = $gb->getRecord($client->ip);
         $client->country = empty($geo['cc']) ? 'UA' : $geo['cc'];
         $client->city = empty($geo['city']) ? 'Киев' : $geo['city'];
         $client->lat = empty($geo['lat']) ? 50.4501 : $geo['lat'];
         $client->lon = empty($geo['lon']) ? 30.5234 : $geo['lon'];
         $client->timezone = empty($geo['timezone']) ? Config::get('application.timezone', 'Europe/Kiev') : $geo['timezone'];
         $cookieStoreData = new \stdClass();
         foreach ($cookieStore as $key) {
             $cookieStoreData->{$key} = $client->{$key};
         }
         Cookie::make('device_info', json_encode($cookieStoreData), 60 * 60 * 4);
     }
 }