Skip to content

Commit

Permalink
Added logout login file
Browse files Browse the repository at this point in the history
  • Loading branch information
mangrose committed Oct 18, 2024
1 parent aca1cdd commit 2fe0fbf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
7 changes: 5 additions & 2 deletions includes/class-tulo-payway-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ public static function get_tulo_myaccount_url() {
return $url;
}

public function get_authentication_url() {
public function get_authentication_url($currentUrl="") {
global $wp;
$currentUrl = home_url( $wp->request );
$permalinkStructure = get_option( 'permalink_structure' );
if ($currentUrl == "") {
$currentUrl = home_url( $wp->request );
}
if ($permalinkStructure == "plain") {
$queryVars = $wp->query_vars;
$queryVars['tpw_session_refresh'] = time();
$currentUrl = add_query_arg( $queryVars, home_url( $wp->request ) );
} else {
$currentUrl .= "?tpw_session_refresh=".time();
}

$currentOrg = get_option('tulo_organisation_id');
$authUrl = get_option('tulo_authentication_url');
return str_replace("{currentOrganisation}", $currentOrg, str_replace("{currentUrl}", urlencode($currentUrl), $authUrl));
Expand Down
2 changes: 1 addition & 1 deletion includes/class-tulo-payway-sso2-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ protected function logout_user($locallyInitiated=true) {
$this->common->write_log("[logout_user]");
$this->common->write_log("locallyInitiated: ".$locallyInitiated);

if ($locallyInitiated) {
if ($locallyInitiated && $this->sso_session_id() != "") {
// Terminate session in Payway
$this->sso_logout();
}
Expand Down
53 changes: 53 additions & 0 deletions logout_login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/*
* This file serves to logout an already loggedin user and redirect to the login page with a specific continue url that
* the user should land on after login.
*
* If no redirect_url is specified, the user will be redirected to the start page of the site after login.
*
* Params:
* r - the url to redirect to after login
*/

function write_log($log) {
$debug_active = get_option('tulo_debug_log_active');
if (true === WP_DEBUG && $debug_active == "on") {
if (is_array($log) || is_object($log)) {
error_log(print_r($log, true));
} else {
error_log("[SSO2][LOGOUTCONTINUE] ".$log);
}
}
}

$baseurl = explode( "wp-content" , $_SERVER['SCRIPT_FILENAME'] );
$baseurl = $baseurl[0];
require_once( $baseurl . "wp-load.php" );

if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}

if ($_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443) {
$port = "";
} else {
$port = ":".$_SERVER['SERVER_PORT'];
}
$redirect_url = isset($_GET["r"]) ? $_GET["r"] : $protocol . $_SERVER['SERVER_NAME'].$port."/";

$tulo = new Tulo_Payway_Server_Common();
$login_url = $tulo->get_authentication_url($redirect_url);

$session = new Tulo_Payway_Session();
$session->logout(true);

write_log("Redirecting to: ".$login_url);
header("Location: ".$login_url);
die();
?>

0 comments on commit 2fe0fbf

Please sign in to comment.