add logout to example wordpress self-service, RT#75279
authorIvan Kohler <ivan@freeside.biz>
Wed, 19 Apr 2017 19:57:57 +0000 (12:57 -0700)
committerIvan Kohler <ivan@freeside.biz>
Wed, 19 Apr 2017 19:57:57 +0000 (12:57 -0700)
fs_selfservice/wordpress/README.txt
fs_selfservice/wordpress/example_selfservice.php
fs_selfservice/wordpress/freeside_selfservice.php
fs_selfservice/wordpress/process_logout.php [new file with mode: 0644]

index 759f839..f068e82 100644 (file)
@@ -38,10 +38,11 @@ VPN or tunnel.
 
 Usage:
 
-See the included example_login.php, process_login.php, example_selfservice.php
-and view_invoice.php files.  These files perform a self-service login
-and display a basic landing page.  To use, copy them to the wordpress content
-directory (or a subdirectory), and point your browser to example_login.php
+See the included example_login.php, process_login.php, process_login.php,
+example_selfservice.php and view_invoice.php files.  These files perform a
+self-service login and display a basic landing page.  To use, copy them and
+the elements/ subdirectory to the wordpress content directory (or a
+subdirectory) and point your browser to example_login.php
 
 For full API documentation including all available functions, their arguments
 and return data, see
index 2bfb5b3..6e5049c 100644 (file)
@@ -60,6 +60,7 @@ get_header();
 <p><a href="view_invoice.php?invnum=<?php echo $max_invnum ?>">View my Bill</a></p>
 <p><a href="change_bill.php">Change Bill Deliver Options</a></p>
 
+<p><a href="process_logout.php">Logout</a></p>
 
 
 <h3>Services</h3>
index d26c56f..852c22e 100644 (file)
@@ -46,6 +46,22 @@ function freeside_server_input() {
 //TODO: remove freeside_server on uninstall
 
 function freeside_init() {
+
+  if ( $GLOBALS['FREESIDE_PROCESS_LOGOUT'] ) {
+    $GLOBALS['FREESIDE_PROCESS_LOGOUT'] = false;
+
+    $freeside = new FreesideSelfService();
+    $response = $freeside->logout( array(
+      'session_id' => $_COOKIE['freeside_session_id'],
+    ) );
+    setcookie('freeside_session_id', '', time() - 3600);
+    $error = $response['error'];
+    if ( $error ) {
+      error_log("Logout error: $error");
+    }
+    return;
+  }
+
   if ( ! $GLOBALS['FREESIDE_PROCESS_LOGIN'] ) {
     return;
   } else {
@@ -129,7 +145,7 @@ class FreesideSelfService {
         )));
         $file = file_get_contents($URL, false, $context);
         $response = xmlrpc_decode($file);
-        if (xmlrpc_is_fault($response)) {
+        if (isset($response) && xmlrpc_is_fault($response)) {
             trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
         } else {
             //error_log("[FreesideSelfService] $response");
diff --git a/fs_selfservice/wordpress/process_logout.php b/fs_selfservice/wordpress/process_logout.php
new file mode 100644 (file)
index 0000000..398fb22
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+$GLOBALS['FREESIDE_PROCESS_LOGOUT'] = true;
+
+require( dirname( __FILE__ ) . '/wp-blog-header.php' );
+
+get_header();
+
+?>
+
+You have been logged out.
+
+<?php get_footer(); ?>