Skip to content

Commit

Permalink
fix: fix bug with session
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrdrvn committed Oct 1, 2019
1 parent ebfde78 commit 83f787e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 9 deletions.
14 changes: 14 additions & 0 deletions model/common/token.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,21 @@ public function getToken( $args ) {
}

public function validateToken( $output ) {
if (!function_exists('getallheaders')) {
function getallheaders() {
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}

$headers = getallheaders();


$auth = isset( $headers['Authorization'] ) ? $headers['Authorization'] : false;
if ( ! $auth ) {
return false;
Expand Down
78 changes: 78 additions & 0 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,81 @@ function VFA_RestApi( WP_REST_Request $request ) {
'callback' => 'VFA_RestApi',
) );
} );

add_action('wp', function() {
$headers = headers_list();
$cookies = array();



foreach($headers as $header) {
if (strpos($header, 'Set-Cookie: ') === 0) {
if (preg_match('/path=(.*);/i', $header)) {
$cookies[] = preg_replace('/path=(.*);/i', 'path=/;', $header);
} else if (preg_match('/path=(.*)/i', $header)) {
$cookies[] = preg_replace('/path=(.*)/i', 'path=/', $header);
}

}
}

for ($i=0; $i < count($cookies); $i++) {
if($i == 0) {
header($cookies[$i]);
} else {
header($cookies[$i], false);
}
}
},99);
add_action('woocommerce_add_to_cart', function() {
$headers = headers_list();
$cookies = array();



foreach($headers as $header) {
if (strpos($header, 'Set-Cookie: ') === 0) {
if (preg_match('/path=(.*);/i', $header)) {
$cookies[] = preg_replace('/path=(.*);/i', 'path=/;', $header);
} else if (preg_match('/path=(.*)/i', $header)) {
$cookies[] = preg_replace('/path=(.*)/i', 'path=/', $header);
}

}
}


for ($i=0; $i < count($cookies); $i++) {
if($i == 0) {
header($cookies[$i]);
} else {
header($cookies[$i], false);
}
}
},99);

add_action('shutdown', function() {
$headers = headers_list();
$cookies = array();



foreach($headers as $header) {
if (strpos($header, 'Set-Cookie: ') === 0) {
if (preg_match('/path=(.*);/i', $header)) {
$cookies[] = preg_replace('/path=(.*);/i', 'path=/;', $header);
} else if (preg_match('/path=(.*)/i', $header)) {
$cookies[] = preg_replace('/path=(.*)/i', 'path=/', $header);
}

}
}

for ($i=0; $i < count($cookies); $i++) {
if($i == 0) {
header($cookies[$i]);
} else {
header($cookies[$i], false);
}
}
}, 1);
9 changes: 0 additions & 9 deletions resolver/startup/startup.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ public function index()
];
}

$cookie_path = COOKIEPATH ? COOKIEPATH : '/';

if ($cookie_path != '/') {
foreach ($_COOKIE as $key => $value) {
if (strpos($key, 'woocommerce') >= 0) {
setcookie($key, $value, 0, "/");
}
}
}

return $result;
}
Expand Down

0 comments on commit 83f787e

Please sign in to comment.