Skip to content

Commit ce606c3

Browse files
committed
Fix bug
1 parent 363f670 commit ce606c3

File tree

1 file changed

+53
-50
lines changed

1 file changed

+53
-50
lines changed

resolver/startup/startup.php

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,68 @@
33
use GraphQL\GraphQL;
44
use GraphQL\Utils\BuildSchema;
55

6-
class VFA_ResolverStartupStartup extends VFA_Resolver {
7-
public function index() {
6+
class VFA_ResolverStartupStartup extends VFA_Resolver
7+
{
8+
public function index()
9+
{
10+
if ($this->request->get_param('cors')) {
11+
if (! empty($_SERVER['HTTP_ORIGIN'])) {
12+
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
13+
} else {
14+
header('Access-Control-Allow-Origin: *');
15+
}
16+
header('Access-Control-Allow-Methods: POST, OPTIONS');
17+
header('Access-Control-Allow-Credentials: true');
18+
header('Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Token,token,Cookie,cookie,content-type');
19+
}
820

9-
// if ( is_plugin_active( 'd_vuefront/plugin.php' ) ) {
10-
if ( $this->request->get_param( 'cors' ) ) {
11-
if ( ! empty( $_SERVER['HTTP_ORIGIN'] ) ) {
12-
header( 'Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN'] );
13-
} else {
14-
header( 'Access-Control-Allow-Origin: *' );
15-
}
16-
header( 'Access-Control-Allow-Methods: POST, OPTIONS' );
17-
header( 'Access-Control-Allow-Credentials: true' );
18-
header( 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Token,token,Cookie,cookie,content-type' );
19-
}
21+
$this->load->model('startup/startup');
2022

21-
$this->load->model( 'startup/startup' );
23+
try {
24+
$resolvers = $this->model_startup_startup->getResolvers();
25+
$schema = BuildSchema::build(file_get_contents(VFA_DIR_PLUGIN . 'schema.graphql'));
26+
$rawInput = file_get_contents('php://input');
27+
$input = json_decode($rawInput, true);
28+
$query = $input['query'];
2229

23-
try {
24-
$resolvers = $this->model_startup_startup->getResolvers();
25-
$schema = BuildSchema::build( file_get_contents( VFA_DIR_PLUGIN . 'schema.graphql' ) );
26-
$rawInput = file_get_contents( 'php://input' );
27-
$input = json_decode( $rawInput, true );
28-
$query = $input['query'];
30+
$variableValues = isset($input['variables']) ? $input['variables'] : null;
31+
$result = GraphQL::executeQuery($schema, $query, $resolvers, null, $variableValues);
32+
} catch (\Exception $e) {
33+
$result = [
34+
'error' => [
35+
'message' => $e->getMessage()
36+
]
37+
];
38+
}
2939

30-
$variableValues = isset( $input['variables'] ) ? $input['variables'] : null;
31-
$result = GraphQL::executeQuery( $schema, $query, $resolvers, null, $variableValues );
32-
} catch ( \Exception $e ) {
33-
$result = [
34-
'error' => [
35-
'message' => $e->getMessage()
36-
]
37-
];
38-
}
40+
$cookie_path = COOKIEPATH ? COOKIEPATH : '/';
3941

42+
if ($cookie_path != '/') {
43+
foreach ($_COOKIE as $key => $value) {
44+
if (strpos($key, 'woocommerce') >= 0) {
45+
setcookie($key, $value, 0, "/");
46+
}
47+
}
48+
}
4049

41-
foreach ( $_COOKIE as $key => $value ) {
42-
if ( strpos( $key, 'woocommerce' ) >= 0 ) {
43-
setcookie( $key, $value, 0, "/" );
44-
}
45-
}
50+
return $result;
51+
}
4652

47-
return $result;
48-
}
53+
public function determine_current_user($user)
54+
{
55+
$this->load->model('common/token');
4956

50-
public function determine_current_user( $user ) {
51-
$this->load->model( 'common/token' );
57+
$validate_uri = strpos($_SERVER['REQUEST_URI'], 'token/validate');
58+
if ($validate_uri > 0) {
59+
return $user;
60+
}
5261

53-
$validate_uri = strpos( $_SERVER['REQUEST_URI'], 'token/validate' );
54-
if ( $validate_uri > 0 ) {
55-
return $user;
56-
}
62+
$token = $this->model_common_token->validateToken(false);
5763

58-
$token = $this->model_common_token->validateToken( false );
64+
if (! $token) {
65+
return $user;
66+
}
5967

60-
if ( ! $token ) {
61-
return $user;
62-
}
63-
64-
return $token->data->user->id;
65-
}
66-
// }
68+
return $token->data->user->id;
69+
}
6770
}

0 commit comments

Comments
 (0)