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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 06:02:36
Script start
Timing: Jan 31 2025 06:02:36
Module start 'layout'
Timing: Jan 31 2025 06:02:36
Module start 'content'
Timing: Jan 31 2025 06:02:37
Module end 'content'
Timing: Jan 31 2025 06:02:37
Script end

Main resources:

Total runtime1.1813 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 588.1406151.2109
Module start 'layout' 0.00560.0025 739.351636.6641
Module start 'content' 0.00811.1723 776.0156947.9063
Module end 'content' 1.18040.0008 1,723.921919.8438
Script end 1.1813  1,743.7656 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.2773160.0002
Check MTime0.00130.1079160.0001
Mysql Total
Database connection0.00090.075310.0009
Mysqli_queries1.135896.1483540.0210
Looping result0.00050.0405520.0000
Template Total1.136596.220.5682
Template load0.00200.172820.0010
Template processing1.134496.030320.5672
Template load and register function0.00120.104810.0012
states
state_id_array0.00180.156410.0018
state_identifier_array0.00150.125720.0007
Override
Cache load0.00160.1354100.0002
Sytem overhead
Fetch class attribute can translate value0.00080.069520.0004
Fetch class attribute name0.00180.155830.0006
XML
Image XML parsing0.00070.056520.0003
class_abstraction
Instantiating content class attribute0.00000.000830.0000
General
dbfile0.00390.3285160.0002
String conversion0.00000.000440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 8
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs