Forums / Developer / extension using soap transactions

extension using soap transactions

Author Message

sean foley

Wednesday 01 July 2009 1:40:24 am

Hello, I am currently working on an ez publish extension and its all new stuff to me I wanted to get some advise from people in the ez publish communtity. The company I work for have an ez publish Licience and we are currently moving all our web products into an ez publish CMS and hosting them here on our servers. I am working on the manage my account at the moment and I need some advise about it, it uses all soap transactions to communicate with our soap server where all the customers details are stored. I will show the login page below and I was hoping for some direction on how things should be after successfull login and how to redirect a user and also how to process the template I need to use.

require_once('lib\ezutils\classes\ezini.php');
include_once('lib\ezutils\classes\ezhttptool.php');
include_once('classes\lib\nusoap.php');
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : 'ukproxy.travel.oag.com';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '80';

	$Module = $Params('Module');
	
	/**
	  * Return the unique instance of the HTTP tool
	  * @static 
	  * @return eZHTTPTool
	  */ 
	$http = new eZHTTPTool();
	$ini = new eZINI('EclipseNetSettings.ini');
	$user_Login = '';
	$user_Password = '';
	$user_RedirectURI = '';
	
	$login_authenticate_response = new login_authenticate_response;	
	$login_authenticate_response = null;
	
	
	//remove data from previous page
	$previousData = ''; 
	if ( $http->hasSessionVariable( '$_POST_BeforeLogin' ) )
	{
	    $previousData = $http->sessionVariable( '$_POST_BeforeLogin' );
	    $http->removeSessionVariable( '$_POST_BeforeLogin' );
	}
	
	$ThinkSoap = new ThinkWS('../../wsdl/Customized25.wsdl',array());
	
	$user_login_data = new user_login_data();
	$user_login_data->login = $ini->variable(
								'user_login_data','login');
	$user_login_data->password = $ini->variable(
								'user_login_data', 'password');
		
	//Get the parameters for the login
	if ( $http->hasGetVariable( 'user_Login' ))
	{
		$Module->setCurrentAction( 'Login' );
		$customer_identifier = new customer_identifier();
	  	$customer_identifier->customer_id = null;
	  	$customer_identifier->login = $http->getVariable( 'user_Login' );
	  	$customer_identifier->password = $http->getVariable( 'user_Password' );
	}
	//proceed with login
	// try to login user if action is Login
	if ( $Module->isCurrentAction( 'login' ) and
	     $Module->hasActionParameter( 'user_Login' ) and
	     $Module->hasActionParameter( 'user_Password' ) and
	 	 !$http->hasPostVariable('requestPassword'))
 	 

  	$user_Login = $Module->actionParameter('user_Login');
  	$user_Password = $Module->actionParameter('user_Password');
  	$user_RedirectURI = $Module->actionParameter('RedirectURI');
    	 	
  	// Set login and password variables into session for later use in other transactions
  	$http->setSessionVariable($user_Login, $customer_identifier->login);
  	$http->setSessionVariable($user_Password, $customer_identifier->password);
  	
	 	 		 	
  try {	   	
	  //construct soap request proxy class for authentication
	  $login_authenticate_request = new login_authenticate_request;
	  
	  //add the required parameters to the loginAuthenticate class
	  $login_authenticate_request->user_login_data = $user_login_data;
	  	$login_authenticate_request->customer_identifier = $customer_identifier;
	  
  		eZDebug::writeNotice(
  		'Starting the soap call LoginAuthenticateRequest: '.date('Y-m-d h:i:s A').' ');
  
  		$login_authenticate_response = $ThinkSoap->LoginAuthenticate($login_authenticate_request);
  
 	   eZDebug::writeNotice(
  	 'Finishing the soap call LoginAuthenticateRequest: '.date('Y-m-d h:i:s A').' ');
  
    //check for a fault
	if ($ThinkSoap->fault) {
		eZDebug::writeWarning(
		  "Warning Login was unsuccessfull for user:  '$customer_identifier->login' " );  
	  	   }
			$err = $ThinkSoap->getError();
	if ($err) {
			// Display the error
			   eZDebug::writeWarning("Warning: Error from Soap Request:  ' $err ' ");
		      }
				
 	$customer = new customer();
  	$customer = $login_authenticate_response->customer;
   	$customer_identifier = $login_authenticate_response->customer_identifier;
    $eclipseCustomer = new EclipseNetCustomer();	
	$eclipseCustomer->setAuthenticationCode($customer_identifier->authentication_code);
  	$eclipseCustomer->setCustomerId($customer_identifier->customer_id);
	$eclipseCustomer->setCustomerCatagory($customer->customer_category);
	
	//set Authenticatecode, customer_id into session for later use
	$http->setSessionVariable($authenticationCode, $customer_identifier->authentication_code);
	$http->setSessionVariable($customer_id, $customer_identifier->customer_id);		

	if ($customer->lname != null){
		$eclipseCustomer->setLastName($customer->lname);
	}
	if ($customer->fname != null){
		$eclipseCustomer->setFirstName($customer->fname);
	}
	if ($customer->email != null){
		$eclipseCustomer->setEmail($customer->email);
	}
	if($customer->salutation != null){
		$eclipseCustomer->setSalutation($customer->salutation);
	}
	if ($customer->title != null){
		$eclipseCustomer->setJobTitle($customer->title);
	}
	$eclipseCustomer->setBillToAddressSequence($customer->def_bill_to_cust_addr_seq);

	if ($customer->def_bill_to_cust_addr_seq != 1){
			$eclipseCustomer->setBillingAddressSameAsShipping(false); 
			$eclipseCustomer->setOriginalBillingSameAsShippingFlag(false);
		}
	else{
		$eclipseCustomer->setBillingAddressSameAsShipping(true);
		$eclipseCustomer->setOriginalBillingSameAsShippingFlag(true); 
	}
	
	$eclipseCustomer->setCustomerLoginId($customer->customer_login->customer_login_id);
	$eclipseCustomer->setLogin($customer->customer_login->login);
	$eclipseCustomer->setPassword($login_authenticate_request->customer_identifier->password);
	
	if ($customer->customer_login->hint != null){
		$eclipseCustomer->setPasswordHint($customer->customer_login->hint);
	}
			
	if ($customer->customer_login->response != null){
		$eclipseCustomer->setPasswordHintResponse($customer->customer_login->response); 
	}
	
	if ($customer->zzaux_contact_by_email != null && $customer->zzaux_contact_by_email(
						strcasecmp('Y', 'y')== 0))
	{
		$eclipseCustomer->setEmailContactAllowed(true);
	}
	else
	{
		$eclipseCustomer->setEmailContactAllowed(false);
	}
	
	if ($customer->zzaux_contact_by_fax != null && $customer->zzaux_contact_by_fax(
						strcasecmp('Y', 'y')== 0))
	{
		$eclipseCustomer->setFaxContactAllowed(true);
	}
	else
	{
		$eclipseCustomer->setFaxContactAllowed(false);
	}
	
	if ($customer->zzaux_contact_by_mail != null && $customer->zzaux_contact_by_mail(
					strcasecmp('Y', 'y')== 0) )
	{
		$eclipseCustomer->setMailContactAllowed(true);
	}
	else
	{
		$eclipseCustomer->setMailContactAllowed(false);
	}
	
	if ($customer->zzaux_contact_by_phone != null && $customer->zzaux_contact_by_phone(
					strcasecmp('Y', 'y')== 0))
	{
		$eclipseCustomer->setPhoneContactAllowed(true);
	}
	else
	{
		$eclipseCustomer->setPhoneContactAllowed(false);
	}
	//construct instance of address_info_select_request and populate it with request data
	$address_info_select_request = new address_info_select_request();
	$address_info_select_request->user_login_data = $user_login_data;
	$address_info_select_request->customer_identifier = $customer_identifier;
	//construct the responce object
	$address_info_select_response = new address_info_select_response();
	
	eZDebug::writeNotice(
  		'Starting the soap call AddressInfoSelect: '.date('Y-m-d h:i:s A').' ');
	
	$address_info_select_response = $ThinkSoap->AddressInfoSelect($address_info_select_request);
	
	eZDebug::writeNotice(
  	 'Finishing the soap call AddressInfoSelect: '.date('Y-m-d h:i:s A').' ');
	
	$customer_addresses = new customer_address();
	$customer_addresses = $address_info_select_response->customer_address;
	$customer_address = new customer_address();

	for ($i = 0; $i < sizeof($customer_addresses); $i++) {
								
		$eclipseAddress = new EclipseNetAddress();
		$eclipseAddress->setAddressSequence($customer_addresses->customer_address_seq);
		
		if ($customer_addresses->company != null){
			$eclipseAddress->setCompany($customer_addresses->company);
		}
		if ($customer_addresses->address1 != null){
			$eclipseAddress->setAddress1($customer_addresses->address1);
		}
		if ($customer_addresses->address2 != null){
			$eclipseAddress->setAddress2($customer_addresses->address2);
		}
		if ($customer_addresses->address3 != null){
			$eclipseAddress->setAddress3($customer_addresses->address3);
		}
		if ($customer_addresses->city != null){
			$eclipseAddress->setCity($customer_addresses->city);
		}
		if ($customer_addresses->state != null){
			
			$eclipseAddress->setState($customer_addresses->state);
		}
		if ($customer_addresses->zip != null){
			$eclipseAddress->setZip( $customer_addresses->zip);
		}
		if ($customer_addresses->county != null){
			$eclipseAddress->setCountry($customer_addresses->county);			
		}
		if ($customer_addresses->phone != null){
			$eclipseAddress->setTelephoneNumber($customer_addresses->phone);
		}
		if ($customer_addresses->eighthundred != null){
			$eclipseAddress->setMobileNumber($customer_addresses->eighthundred);
		}
		if ($customer_addresses->faxnbr != null){
			$eclipseAddress->setFaxNumber($customer_addresses->faxnbr);
		}
		if ($customer_addresses->email != null){
			$eclipseAddress->setEmail($customer_addresses->email);
		}
	
	}
	
 }catch(Exception $e){
    // in case of an error, process the fault
    if ($e instanceof SoapClient) {
        printf("Soap Fault: %s\n", $e->getCode());
    } else {
        printf("Message = %s\n", $e->getMessage());
    }


} 

Gaetano Giunta

Wednesday 01 July 2009 4:19:22 am

Sorry for not taking the time to read your long code, but the best approach is usually to use the standard login module, and add your won code in a login handler class, whose method loginUser() will be called automatically by eZ when a user tries to login.

You can take a look at the csv and ldap login handlers that come with eZ for inspiration (the ldap one does the create-ez-user-if-it-does-not-exist-locally thing).

Oh, and you can take a look at ggwebservices extension, too. Since version 0.3 it has nice soap support.

Principal Consultant International Business
Member of the Community Project Board

eZ debug

Timing: Jan 31 2025 03:33:41
Script start
Timing: Jan 31 2025 03:33:41
Module start 'content'
Timing: Jan 31 2025 03:33:41
Module end 'content'
Timing: Jan 31 2025 03:33:41
Script end

Main resources:

Total runtime0.2807 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 587.9531370.2891
Module start 'content' 0.00790.0138 958.24221,009.5625
Module end 'content' 0.02180.2589 1,967.80473,908.9609
Script end 0.2807  5,876.7656 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00441.5713200.0002
Check MTime0.00130.4711200.0001
Mysql Total
Database connection0.00070.264010.0007
Mysqli_queries0.174162.00311410.0012
Looping result0.00150.52431390.0000
Template Total0.258592.110.2585
Template load0.00080.286810.0008
Template processing0.257791.804610.2577
Override
Cache load0.00060.207610.0006
Sytem overhead
Fetch class attribute can translate value0.00200.708110.0020
XML
Image XML parsing0.00020.080510.0002
General
dbfile0.01465.2118200.0007
String conversion0.00000.003230.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs