From fa5830f37b5edbc5168bd14a509dd52597c5cb9c Mon Sep 17 00:00:00 2001 From: = Date: Sun, 28 Feb 2021 15:32:08 +1100 Subject: [PATCH 1/2] Test for date ranges --- tests/Unit/RangeDetectionTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Unit/RangeDetectionTest.php b/tests/Unit/RangeDetectionTest.php index d00d7b2036..1d8540502f 100644 --- a/tests/Unit/RangeDetectionTest.php +++ b/tests/Unit/RangeDetectionTest.php @@ -35,19 +35,19 @@ class RangeDetectionTest extends TestCase foreach($ranges as $range) { - $expanded_ranges[] = $this->makeRanges($range); + $expanded_ranges = array_merge(array_values($expanded_ranges),array_values($this->makeRanges($range))); } - foreach($ranges as $range) - { - - } + $value_count_array = array_count_values($expanded_ranges); + $value_count_array = array_diff($value_count_array, [1]); + + $this->assertEquals(count($value_count_array), 1); } + private function makeRanges(array $range) { - return range($range[0], $range[1]); } From 92f729c10d904ff2b97959f3ae972e6533bfbf9e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 28 Feb 2021 19:54:14 +1100 Subject: [PATCH 2/2] Catch if an OAuth user doesn't exist and attempts to login --- app/Http/Controllers/Auth/LoginController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index fe3b7144a1..8cb1362841 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -286,11 +286,25 @@ class LoginController extends BaseController } if ($user) { + $client = new Google_Client(); $client->setClientId(config('ninja.auth.google.client_id')); $client->setClientSecret(config('ninja.auth.google.client_secret')); $client->setRedirectUri(config('ninja.app_url')); - $token = $client->authenticate(request()->input('server_auth_code')); + + $token = false; + + try{ + $token = $client->authenticate(request()->input('server_auth_code')); + } + catch(\Exception $e) { + + return response() + ->json(['message' => ctrans('texts.invalid_credentials')], 401) + ->header('X-App-Version', config('ninja.app_version')) + ->header('X-Api-Version', config('ninja.minimum_client_version')); + + } $refresh_token = '';