Skip to content

Commit

Permalink
fix for #982
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Aug 3, 2023
1 parent ad4b9a5 commit 5be7db5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
12 changes: 9 additions & 3 deletions api.include.php
Expand Up @@ -3306,7 +3306,7 @@ public function fromGlobals(): ServerRequestInterface
/**
* {@inheritdoc}
*/
public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], /*?array*/ $post = null, array $files = [], $body = null): ServerRequestInterface
public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], ?array $post = null, array $files = [], $body = null): ServerRequestInterface
{
$method = $this->getMethodFromEnv($server);
$uri = $this->getUriFromEnvWithHTTP($server);
Expand Down Expand Up @@ -3575,7 +3575,8 @@ public function fromArrays(
array $server,
array $headers = [],
array $cookie = [],
array $get = [], /*?array*/ $post = null,
array $get = [],
?array $post = null,
array $files = [],
$body = null
): ServerRequestInterface;
Expand Down Expand Up @@ -9987,20 +9988,25 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
'remember' => false,
]);
if ($user->ID) {
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
}
if ($method == 'POST' && $path == 'logout') {
if (is_user_logged_in()) {
wp_logout();
$user = wp_get_current_user();
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
}
if ($method == 'GET' && $path == 'me') {
if (is_user_logged_in()) {
return $this->responder->success(wp_get_current_user());
$user = wp_get_current_user();
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
}
Expand Down
12 changes: 9 additions & 3 deletions api.php
Expand Up @@ -3306,7 +3306,7 @@ public function fromGlobals(): ServerRequestInterface
/**
* {@inheritdoc}
*/
public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], /*?array*/ $post = null, array $files = [], $body = null): ServerRequestInterface
public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], ?array $post = null, array $files = [], $body = null): ServerRequestInterface
{
$method = $this->getMethodFromEnv($server);
$uri = $this->getUriFromEnvWithHTTP($server);
Expand Down Expand Up @@ -3575,7 +3575,8 @@ public function fromArrays(
array $server,
array $headers = [],
array $cookie = [],
array $get = [], /*?array*/ $post = null,
array $get = [],
?array $post = null,
array $files = [],
$body = null
): ServerRequestInterface;
Expand Down Expand Up @@ -9987,20 +9988,25 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
'remember' => false,
]);
if ($user->ID) {
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
}
if ($method == 'POST' && $path == 'logout') {
if (is_user_logged_in()) {
wp_logout();
$user = wp_get_current_user();
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
}
if ($method == 'GET' && $path == 'me') {
if (is_user_logged_in()) {
return $this->responder->success(wp_get_current_user());
$user = wp_get_current_user();
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
}
Expand Down
7 changes: 6 additions & 1 deletion src/Tqdev/PhpCrudApi/Middleware/WpAuthMiddleware.php
Expand Up @@ -38,20 +38,25 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
'remember' => false,
]);
if ($user->ID) {
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
}
if ($method == 'POST' && $path == 'logout') {
if (is_user_logged_in()) {
wp_logout();
$user = wp_get_current_user();
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
}
if ($method == 'GET' && $path == 'me') {
if (is_user_logged_in()) {
return $this->responder->success(wp_get_current_user());
$user = wp_get_current_user();
unset($user['user_pass']);
return $this->responder->success($user);
}
return $this->responder->error(ErrorCode::AUTHENTICATION_REQUIRED, '');
}
Expand Down

0 comments on commit 5be7db5

Please sign in to comment.