From 2b4a2676e78178aa6226419baf5be70d05d2cfc7 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Mon, 28 Nov 2022 14:20:34 -0500 Subject: [PATCH 01/17] Update general-view.php Remove beta tag. --- simple-jwt-login/views/general-view.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/simple-jwt-login/views/general-view.php b/simple-jwt-login/views/general-view.php index ec4553c..7cd0bf2 100644 --- a/simple-jwt-login/views/general-view.php +++ b/simple-jwt-login/views/general-view.php @@ -444,7 +444,6 @@ class="form-control" : "" ?> /> - beta

@@ -457,4 +456,4 @@ class="form-control" ?>

- \ No newline at end of file + From 7c71a47f3624894f3e77e6788d270415baf9d216 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Mon, 28 Nov 2022 15:10:39 -0500 Subject: [PATCH 02/17] Update dashboard Add Protect endpoints status --- simple-jwt-login/views/dashboard-view.php | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/simple-jwt-login/views/dashboard-view.php b/simple-jwt-login/views/dashboard-view.php index 423105e..18d29df 100644 --- a/simple-jwt-login/views/dashboard-view.php +++ b/simple-jwt-login/views/dashboard-view.php @@ -199,3 +199,42 @@ class="box-status box-status- +
+
+
+
+
+ +
+
" + > +
+
+ getProtectEndpointsSettings()->isEnabled() + ? __('On', 'simple-jwt-login') + : __('Off', 'simple-jwt-login'); + ?> +
+
+
+
+ +
+ +
+ +
+ +
+
+ +
+ +
From 69b060f40792fe9af1fce9d447ce699c61a85fe7 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Wed, 30 Nov 2022 11:02:09 -0500 Subject: [PATCH 03/17] Allow username/email for /auth username Allow user to use either username or email in username field for /auth endpoint. This is inline with how a user normally logs in to WordPress --- .../src/Services/AuthenticateService.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index b059485..fd0198c 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -99,12 +99,24 @@ public function authenticateUser() ); } - $user = isset($this->request['username']) - ? $this->wordPressData->getUserByUserLogin( - $this->wordPressData->sanitizeTextField($this->request['username']) + $auth_method = 'email'; + + if (isset($this->request['username'])) { + $user_by = $this->request['username']; + $auth_method = (str_contains($this->request['username'], '@')) + ? 'email' + : 'username'; + } + else { + $user_by = $this->request['email']; + } + + $user = ($auth_method == 'email') + ? $this->wordPressData->getUserDetailsByEmail( + $this->wordPressData->sanitizeTextField($user_by) ) - : $this->wordPressData->getUserDetailsByEmail( - $this->wordPressData->sanitizeTextField($this->request['email']) + : $this->wordPressData->getUserByUserLogin( + $this->wordPressData->sanitizeTextField($user_by) ); if (empty($user)) { From 4dfda36fd670200c28d747a97323a8c92206940c Mon Sep 17 00:00:00 2001 From: true2thepen Date: Wed, 30 Nov 2022 11:13:18 -0500 Subject: [PATCH 04/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index fd0198c..6c2102d 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -106,8 +106,7 @@ public function authenticateUser() $auth_method = (str_contains($this->request['username'], '@')) ? 'email' : 'username'; - } - else { + } else { $user_by = $this->request['email']; } From ee88d725b4fab1d55ec005b29867818886973937 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Wed, 30 Nov 2022 11:15:55 -0500 Subject: [PATCH 05/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 6c2102d..30cb341 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -100,14 +100,13 @@ public function authenticateUser() } $auth_method = 'email'; + $user_by = $this->request['email']; if (isset($this->request['username'])) { $user_by = $this->request['username']; $auth_method = (str_contains($this->request['username'], '@')) ? 'email' : 'username'; - } else { - $user_by = $this->request['email']; } $user = ($auth_method == 'email') From a6cc452477f62e0cf19624d36144e62d78b0b869 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Wed, 30 Nov 2022 11:18:46 -0500 Subject: [PATCH 06/17] Update AuthenticateService.php --- .../src/Services/AuthenticateService.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 30cb341..7fd63ce 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -99,22 +99,22 @@ public function authenticateUser() ); } - $auth_method = 'email'; - $user_by = $this->request['email']; + $authMethod = 'email'; + $userBy = $this->request['email']; if (isset($this->request['username'])) { - $user_by = $this->request['username']; - $auth_method = (str_contains($this->request['username'], '@')) + $userBy = $this->request['username']; + $authMethod = (str_contains($this->request['username'], '@')) ? 'email' : 'username'; } - $user = ($auth_method == 'email') + $user = ($authMethod == 'email') ? $this->wordPressData->getUserDetailsByEmail( - $this->wordPressData->sanitizeTextField($user_by) + $this->wordPressData->sanitizeTextField($userBy) ) : $this->wordPressData->getUserByUserLogin( - $this->wordPressData->sanitizeTextField($user_by) + $this->wordPressData->sanitizeTextField($userBy) ); if (empty($user)) { From e4c94fce2c3a6b3dc968d1bbe769fe5fff27a004 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Wed, 30 Nov 2022 11:37:29 -0500 Subject: [PATCH 07/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 7fd63ce..0c1093d 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -99,15 +99,13 @@ public function authenticateUser() ); } - $authMethod = 'email'; - $userBy = $this->request['email']; + $userBy = isset($this->request['email']) + ? $this->request['email'] + : $this->request['username']; - if (isset($this->request['username'])) { - $userBy = $this->request['username']; - $authMethod = (str_contains($this->request['username'], '@')) + $authMethod = (str_contains($userBy, '@')) ? 'email' : 'username'; - } $user = ($authMethod == 'email') ? $this->wordPressData->getUserDetailsByEmail( From 4b18f6147c8830b4274d1639ebb6d2ff46c1799e Mon Sep 17 00:00:00 2001 From: true2thepen Date: Wed, 30 Nov 2022 11:56:03 -0500 Subject: [PATCH 08/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 0c1093d..81fb0aa 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -99,7 +99,7 @@ public function authenticateUser() ); } - $userBy = isset($this->request['email']) + $userBy = isset($this->request['email'] && str_contains($this->request['email'], '@') ? $this->request['email'] : $this->request['username']; From d1b3d8388ee25a8e6ee49cefb94f76851ef24ba1 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Wed, 30 Nov 2022 12:00:26 -0500 Subject: [PATCH 09/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 81fb0aa..ad3008c 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -99,7 +99,7 @@ public function authenticateUser() ); } - $userBy = isset($this->request['email'] && str_contains($this->request['email'], '@') + $userBy = (isset($this->request['email']) && str_contains($this->request['email'], '@')) ? $this->request['email'] : $this->request['username']; From 4287a90e427927f95634d00811fba786bcf86f73 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Fri, 2 Dec 2022 12:07:05 -0500 Subject: [PATCH 10/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index ad3008c..62d6d61 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -98,7 +98,7 @@ public function authenticateUser() ErrorCodes::AUTHENTICATION_MISSING_PASSWORD ); } - + /* $userBy = (isset($this->request['email']) && str_contains($this->request['email'], '@')) ? $this->request['email'] : $this->request['username']; @@ -114,6 +114,15 @@ public function authenticateUser() : $this->wordPressData->getUserByUserLogin( $this->wordPressData->sanitizeTextField($userBy) ); + */ + + $user = isset($this->request['username']) + ? $this->wordPressData->getUserByUserLogin( + $this->wordPressData->sanitizeTextField($this->request['username']) + ) + : $this->wordPressData->getUserDetailsByEmail( + $this->wordPressData->sanitizeTextField($this->request['email']) + ); if (empty($user)) { throw new Exception( From 6b7e499d31fa9579e89ecd7119a6ac6d6069ca54 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Fri, 2 Dec 2022 12:27:06 -0500 Subject: [PATCH 11/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 62d6d61..57ddd9e 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -116,6 +116,12 @@ public function authenticateUser() ); */ + if (isset($this->request['username'] && str_contains($this->request['username'], '@')) + { + $this>request['email'] = $this->request['username']; + unset($this->request['username']; + } + $user = isset($this->request['username']) ? $this->wordPressData->getUserByUserLogin( $this->wordPressData->sanitizeTextField($this->request['username']) From 0d1b0026717ee901a4cbae4ba6b37b1b8d92846e Mon Sep 17 00:00:00 2001 From: true2thepen Date: Fri, 2 Dec 2022 12:29:40 -0500 Subject: [PATCH 12/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 57ddd9e..d5df5c3 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -116,11 +116,10 @@ public function authenticateUser() ); */ - if (isset($this->request['username'] && str_contains($this->request['username'], '@')) - { - $this>request['email'] = $this->request['username']; - unset($this->request['username']; - } + if (isset($this->request['username'] && str_contains($this->request['username'], '@')) { + $this>request['email'] = $this->request['username']; + unset($this->request['username']; + } $user = isset($this->request['username']) ? $this->wordPressData->getUserByUserLogin( From 7ca53f98eb64bcabeca067aac9bd26b4d3361828 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Fri, 2 Dec 2022 12:32:15 -0500 Subject: [PATCH 13/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index d5df5c3..a6bb235 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -117,7 +117,7 @@ public function authenticateUser() */ if (isset($this->request['username'] && str_contains($this->request['username'], '@')) { - $this>request['email'] = $this->request['username']; + $this->request['email'] = $this->request['username']; unset($this->request['username']; } From 97c0632c64e3379fecc8897ddeece0de47f3ee4c Mon Sep 17 00:00:00 2001 From: true2thepen Date: Fri, 2 Dec 2022 12:34:08 -0500 Subject: [PATCH 14/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index a6bb235..2749923 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -116,7 +116,7 @@ public function authenticateUser() ); */ - if (isset($this->request['username'] && str_contains($this->request['username'], '@')) { + if (isset($this->request['username']) && str_contains($this->request['username'], '@')) { $this->request['email'] = $this->request['username']; unset($this->request['username']; } From 940096bf38565355bac4f8fefcc343486cc4138f Mon Sep 17 00:00:00 2001 From: true2thepen Date: Fri, 2 Dec 2022 12:35:40 -0500 Subject: [PATCH 15/17] Update AuthenticateService.php --- simple-jwt-login/src/Services/AuthenticateService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 2749923..8f6a548 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -118,7 +118,7 @@ public function authenticateUser() if (isset($this->request['username']) && str_contains($this->request['username'], '@')) { $this->request['email'] = $this->request['username']; - unset($this->request['username']; + unset($this->request['username']); } $user = isset($this->request['username']) From 14e7d5d9106d34ab24805c506cbe5324dd6e8d44 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Fri, 2 Dec 2022 12:57:15 -0500 Subject: [PATCH 16/17] Update AuthenticateServiceTest.php --- tests/Services/AuthenticateServiceTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Services/AuthenticateServiceTest.php b/tests/Services/AuthenticateServiceTest.php index 105a593..2b5fccc 100644 --- a/tests/Services/AuthenticateServiceTest.php +++ b/tests/Services/AuthenticateServiceTest.php @@ -270,6 +270,9 @@ public function testSuccessFlowWithFullPayload() $this->wordPressDataMock ->method('getUserByUserLogin') ->willReturn('user'); + $this->wordPressDataMock + ->method('getUserDetailsByEmail') + ->willReturn('user'); $this->wordPressDataMock ->method('getUserPassword') ->willReturn('1234'); @@ -323,6 +326,9 @@ public function testSuccessFlowWithFullPayloadAndPasshash() $this->wordPressDataMock ->method('getUserByUserLogin') ->willReturn('user'); + $this->wordPressDataMock + ->method('getUserDetailsByEmail') + ->willReturn('user'); $this->wordPressDataMock ->method('getUserPassword') ->willReturn('1234'); From 2851aa216a81e07c31bfeebadecf473f802e2ad2 Mon Sep 17 00:00:00 2001 From: true2thepen Date: Fri, 2 Dec 2022 13:15:31 -0500 Subject: [PATCH 17/17] Update AuthenticateService.php --- .../src/Services/AuthenticateService.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index 8f6a548..4fdac8b 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -98,23 +98,6 @@ public function authenticateUser() ErrorCodes::AUTHENTICATION_MISSING_PASSWORD ); } - /* - $userBy = (isset($this->request['email']) && str_contains($this->request['email'], '@')) - ? $this->request['email'] - : $this->request['username']; - - $authMethod = (str_contains($userBy, '@')) - ? 'email' - : 'username'; - - $user = ($authMethod == 'email') - ? $this->wordPressData->getUserDetailsByEmail( - $this->wordPressData->sanitizeTextField($userBy) - ) - : $this->wordPressData->getUserByUserLogin( - $this->wordPressData->sanitizeTextField($userBy) - ); - */ if (isset($this->request['username']) && str_contains($this->request['username'], '@')) { $this->request['email'] = $this->request['username'];