Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/lookup-server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2022-06-22 15:34:48 +0300
committerGitHub <noreply@github.com>2022-06-22 15:34:48 +0300
commita00fee543b939d77325d82047675afcf7090b195 (patch)
tree51373de74ac0a340c9cbd8811fec57cc361f4975
parentea006ba63d014599fb6f2e5c1aacb39d29149675 (diff)
parent1c765a524a472d19587d0a63c76d398817cd78e3 (diff)
Merge pull request #93 from nextcloud/fix/72/return-static-responsev0.3
returns static new response
-rw-r--r--server/lib/Replication.php6
-rw-r--r--server/lib/UserManager.php39
-rw-r--r--server/lib/Validator/Email.php7
3 files changed, 20 insertions, 32 deletions
diff --git a/server/lib/Replication.php b/server/lib/Replication.php
index 002cd47..931ee87 100644
--- a/server/lib/Replication.php
+++ b/server/lib/Replication.php
@@ -29,15 +29,13 @@ class Replication {
$userInfo = explode(':', $userInfo, 2);
if (count($userInfo) !== 2 || $userInfo[0] !== 'lookup' || $userInfo[1] !== $this->auth) {
- $response = $response->withStatus(401);
- return $response;
+ return $response->withStatus(401);
}
$params = $request->getQueryParams();
if (!isset($params['timestamp'], $params['page']) || !ctype_digit($params['timestamp']) ||
!ctype_digit($params['page'])) {
- $response = $response->withStatus(400);
- return $response;
+ return $response->withStatus(400);
}
$timestamp = (int)$params['timestamp'];
diff --git a/server/lib/UserManager.php b/server/lib/UserManager.php
index 9739ee0..6b127b8 100644
--- a/server/lib/UserManager.php
+++ b/server/lib/UserManager.php
@@ -5,8 +5,8 @@ namespace LookupServer;
use LookupServer\Validator\Email;
use LookupServer\Validator\Twitter;
use LookupServer\Validator\Website;
-use \Psr\Http\Message\ServerRequestInterface as Request;
-use \Psr\Http\Message\ResponseInterface as Response;
+use Psr\Http\Message\ResponseInterface as Response;
+use Psr\Http\Message\ServerRequestInterface as Request;
class UserManager {
@@ -72,8 +72,7 @@ class UserManager {
$params = $request->getQueryParams();
if (!isset($params['search']) || $params['search'] === '') {
- $response->withStatus(404);
- return $response;
+ return $response->withStatus(404);
}
$search = $params['search'];
@@ -363,8 +362,7 @@ LIMIT :limit');
if ($body === null || !isset($body['message']) || !isset($body['message']['data']) ||
!isset($body['message']['data']['federationId']) || !isset($body['signature']) ||
!isset($body['message']['timestamp'])) {
- $response->withStatus(400);
- return $response;
+ return $response->withStatus(400);
}
$cloudId = $body['message']['data']['federationId'];
@@ -372,18 +370,17 @@ LIMIT :limit');
try {
$verified = $this->signatureHandler->verify($cloudId, $body['message'], $body['signature']);
} catch(\Exception $e) {
- $response->withStatus(400);
- return $response;
+ return $response->withStatus(400);
}
if ($verified) {
$result = $this->insertOrUpdate($cloudId, $body['message']['data'], $body['message']['timestamp']);
if ($result === false) {
- $response->withStatus(403);
+ return $response->withStatus(403);
}
} else {
// ERROR OUT
- $response->withStatus(403);
+ return $response->withStatus(403);
}
return $response;
@@ -401,13 +398,11 @@ LIMIT :limit');
$body = json_decode($request->getBody(), true);
if ($body === null || !isset($body['authKey']) || !isset($body['users'])) {
- $response->withStatus(400);
- return $response;
+ return $response->withStatus(400);
}
if ($body['authKey'] !== $this->authKey) {
- $response->withStatus(403);
- return $response;
+ return $response->withStatus(403);
}
foreach ($body['users'] as $cloudId => $data) {
@@ -430,13 +425,11 @@ LIMIT :limit');
$body = json_decode($request->getBody(), true);
if ($body === null || !isset($body['authKey']) || !isset($body['users'])) {
- $response->withStatus(400);
- return $response;
+ return $response->withStatus(400);
}
if ($body['authKey'] !== $this->authKey) {
- $response->withStatus(403);
- return $response;
+ return $response->withStatus(403);
}
foreach ($body['users'] as $cloudId) {
@@ -454,8 +447,7 @@ LIMIT :limit');
if ($body === null || !isset($body['message']) || !isset($body['message']['data']) ||
!isset($body['message']['data']['federationId']) || !isset($body['signature']) ||
!isset($body['message']['timestamp'])) {
- $response->withStatus(400);
- return $response;
+ return $response->withStatus(400);
}
$cloudId = $body['message']['data']['federationId'];
@@ -463,19 +455,18 @@ LIMIT :limit');
try {
$verified = $this->signatureHandler->verify($cloudId, $body['message'], $body['signature']);
} catch(\Exception $e) {
- $response->withStatus(400);
- return $response;
+ return $response->withStatus(400);
}
if ($verified) {
$result = $this->deleteDBRecord($cloudId);
if ($result === false) {
- $response->withStatus(404);
+ return $response->withStatus(404);
}
} else {
// ERROR OUT
- $response->withStatus(403);
+ return $response->withStatus(403);
}
return $response;
diff --git a/server/lib/Validator/Email.php b/server/lib/Validator/Email.php
index 2d82fd0..b0e0c44 100644
--- a/server/lib/Validator/Email.php
+++ b/server/lib/Validator/Email.php
@@ -2,8 +2,8 @@
namespace LookupServer\Validator;
-use \Psr\Http\Message\ServerRequestInterface as Request;
-use \Psr\Http\Message\ResponseInterface as Response;
+use Psr\Http\Message\ResponseInterface as Response;
+use Psr\Http\Message\ServerRequestInterface as Request;
class Email {
@@ -54,8 +54,7 @@ class Email {
$stmt->closeCursor();
if ($validation === false) {
- $response->withStatus(403);
- $response->getBody()->write('Invalid token');
+ return $response->withStatus(403, 'Invalid token');
} else {
$stmt = $this->db->prepare('UPDATE store SET valid = 1 WHERE id = :storeId');
$stmt->bindParam('storeId', $validation['storeId']);