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