if ($bookingStep == 'GetCabins') { setcookie('category-code', $data['category-code']); } if ($bookingStep == 'HoldCabin') { setcookie('cabin-code', $data['cabin_number']); setcookie('dining-preference', $data['dining_preference']); } /* |-------------------------------------------------------------------------- | Response |-------------------------------------------------------------------------- | | We get the API response trough the Unirest library. | | Available properties are: | | $response->code -- HTTP Status code | $response->headers -- Headers | $response->body -- Parsed body | $response->raw_body -- Unparsed body | | For the purpose of demonstration, we will use $response->body in this example, | although you could preferably use 'raw_body' and deal with the plain JSON instead | trough javascript/AJAX, for a better UX. | */ $response = $dispatcher->{$bookingStep}($_POST); $dump = is_object($response->body) ? $response->body : $response->body[0]; $output = ['result' => loadView("{$serviceName}/{$_POST['webservice']}/{$bookingStep}.php", $response->body, $containerName), 'dump' => varDumpToString($dump)]; exit(json_encode($output)); }
public function actionauthenticatewith($provider = "") { $hybridauth_config = Yiiauth::hybridAuthConfig(); $error = false; $user_profile = false; try { // create an instance for Hybridauth with the configuration file path as parameter $hybridauth = new Hybrid_Auth($hybridauth_config); // try to authenticate the selected $provider if (isset($_GET['openid'])) { $provider = "openid"; $adapter = $hybridauth->authenticate($provider, array("openid_identifier" => $_GET['openid'])); } else { $adapter = $hybridauth->authenticate($provider); } // grab the user profile $user_profile = $adapter->getUserProfile(); } catch (Exception $e) { // Display the recived error switch ($e->getCode()) { case 0: $error = "Unspecified error."; break; case 1: $error = "Hybridauth configuration error."; break; case 2: $error = "Provider not properly configured."; break; case 3: $error = "Unknown or disabled provider."; break; case 4: $error = "Missing provider application credentials."; break; case 5: $error = "Authentification failed. The user has canceled the authentication or the provider refused the connection."; break; case 6: $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again."; $adapter->logout(); break; case 7: $error = "User not connected to the provider."; $adapter->logout(); break; } // well, basically your should not display this to the end user, just give him a hint and move on.. $error .= "<br /><br /><b>Original error message:</b> " . $e->getMessage(); $error .= "<hr /><pre>Trace:<br />" . $e->getTraceAsString() . "</pre>"; } /**$user_profile->identifier; //unique id $provider; // the provider name $_GET['openid'];//the extra_info **/ // workOnUser returns an user object if (is_object($user_profile)) { $user = $this->workOnUser($provider, $user_profile->identifier, $user_profile); if ($user === false or is_null($user)) { lg('Alert: Facebook error:'); lg(varDumpToString($user_profile)); Yii::app()->user->setFlash('fb_problem', 'Sorry, we are having trouble identifying you with Facebook. Please sign up normally.'); $this->redirect('/user/registration'); } if ($this->autoLogin($user)) { //successful login $this->redirect('/userlocation/locate'); /* $this->render('profile', array( 'error'=>$error, //string 'provideruser'=>$user_profile,//object 'yiiuser'=>$user, //object 'provider'=>$provider, //string ) ); */ } else { // this is where u go otherwise $this->render('authenticatewith', array('error' => $error, 'user_profile' => $user_profile)); } } else { echo "Something wrong with " . $provider; } }
public function registerViaHybridAuth($ext_profile) { // create new user // create new user profile from profile details // Profile::$regMode = true; lg('registerviaHybridAuth entry:' . $ext_profile->email); $user = new User(); $profile = new Profile(); //$user = new SocialRegistration; $user->email = $ext_profile->email; $user->username = $ext_profile->identifier; $user->status = 1; // activate account // $user->eid = uniqid(); // provide unique id $profile->first_name = $ext_profile->firstName; $profile->last_name = $ext_profile->lastName; $profile->facebook = str_ireplace('http://www.facebook.com/', '', $ext_profile->profileURL); // trim profile to 250 chars $profile->bio = substr($ext_profile->description, 0, 250); $profile->website = $ext_profile->webSiteURL; $profile->profile_image_url = $ext_profile->photoURL; // return user_id if ($user->validate()) { if ($profile->validate()) { if ($user->save()) { $profile->user_id = $user->id; $profile->save(); } return $user->id; } else { lg('Alert: Facebook profile model failed'); lg(varDumpToString($profile)); lg('error summary'); lg(varDumpToString($profile->getErrors())); } } else { lg('Alert: Facebook user model validation failed'); } lg(varDumpToString($user->getErrors())); return false; }