From 828f360889c0375ea8b9832b6b21ab7781ee09b7 Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Thu, 18 May 2023 15:41:42 +0100 Subject: [PATCH 1/9] add support for all request types when building a user from request. --- src/Authentication/Passwords/ValidationRules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Authentication/Passwords/ValidationRules.php b/src/Authentication/Passwords/ValidationRules.php index 53f078b8e..50815af76 100644 --- a/src/Authentication/Passwords/ValidationRules.php +++ b/src/Authentication/Passwords/ValidationRules.php @@ -73,7 +73,7 @@ protected function buildUserFromRequest(): User /** @var IncomingRequest $request */ $request = service('request'); - $data = $request->getPost($fields); + $data = $request->getVar($fields); return new User($data); } From d1f52d7c9e5b607541c7251130f74c5fd375a8e1 Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Sat, 20 May 2023 11:48:03 +0100 Subject: [PATCH 2/9] revert back to getPost(), deprecate buildUserFromRequest() --- src/Authentication/Passwords/ValidationRules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Authentication/Passwords/ValidationRules.php b/src/Authentication/Passwords/ValidationRules.php index 50815af76..53f078b8e 100644 --- a/src/Authentication/Passwords/ValidationRules.php +++ b/src/Authentication/Passwords/ValidationRules.php @@ -73,7 +73,7 @@ protected function buildUserFromRequest(): User /** @var IncomingRequest $request */ $request = service('request'); - $data = $request->getVar($fields); + $data = $request->getPost($fields); return new User($data); } From 632bcde62bf69c9d1bcad149a10f23d2e0cdd356 Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Sat, 20 May 2023 11:48:44 +0100 Subject: [PATCH 3/9] revert back to getPost(), deprecate buildUserFromRequest() --- src/Authentication/Passwords/ValidationRules.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Authentication/Passwords/ValidationRules.php b/src/Authentication/Passwords/ValidationRules.php index 53f078b8e..ffd8a6417 100644 --- a/src/Authentication/Passwords/ValidationRules.php +++ b/src/Authentication/Passwords/ValidationRules.php @@ -65,6 +65,8 @@ public function max_byte(?string $str, string $val): bool /** * Builds a new user instance from the global request. + * + * @deprecated This will be removed soon. */ protected function buildUserFromRequest(): User { From f673d4237170c05051a7a990e6e9c42e7968c493 Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Sat, 20 May 2023 12:02:18 +0100 Subject: [PATCH 4/9] added a reference link to the deprecation. --- src/Authentication/Passwords/ValidationRules.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Authentication/Passwords/ValidationRules.php b/src/Authentication/Passwords/ValidationRules.php index ffd8a6417..263954557 100644 --- a/src/Authentication/Passwords/ValidationRules.php +++ b/src/Authentication/Passwords/ValidationRules.php @@ -67,6 +67,7 @@ public function max_byte(?string $str, string $val): bool * Builds a new user instance from the global request. * * @deprecated This will be removed soon. + * @see https://github.com/codeigniter4/shield/pull/747#discussion_r1198778666 */ protected function buildUserFromRequest(): User { From dfc3181ead356bae89cb90d08f6ddae9ab9580c5 Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Sat, 20 May 2023 12:03:13 +0100 Subject: [PATCH 5/9] update rule usage in RegisterController --- src/Controllers/RegisterController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controllers/RegisterController.php b/src/Controllers/RegisterController.php index 500b1ea36..9dc5070db 100644 --- a/src/Controllers/RegisterController.php +++ b/src/Controllers/RegisterController.php @@ -197,7 +197,7 @@ protected function getValidationRules(): array ], 'password' => [ 'label' => 'Auth.password', - 'rules' => 'required|' . Passwords::getMaxLengthRule() . '|strong_password', + 'rules' => 'required|' . Passwords::getMaxLengthRule() . '|strong_password[]', 'errors' => [ 'max_byte' => 'Auth.errorPasswordTooLongBytes', ], From 4f907c36449eda1e170183bdd78cf9b5490def5c Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Sat, 20 May 2023 12:03:36 +0100 Subject: [PATCH 6/9] updated docs --- docs/guides/strengthen_password.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/strengthen_password.md b/docs/guides/strengthen_password.md index 5d9345022..102dc9b1d 100644 --- a/docs/guides/strengthen_password.md +++ b/docs/guides/strengthen_password.md @@ -17,7 +17,7 @@ The longer the password, the stronger it is. Consider increasing the value. > **Note** > -> This checking works when you validate passwords with the `strong_password` +> This checking works when you validate passwords with the `strong_password[]` > validation rule. > > If you disable `CompositionValidator` (enabled by default) in `$passwordValidators`, From 70a2138e4e5aed8e155f18c3ae6d2d3a0c11c6e4 Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Sat, 20 May 2023 12:38:40 +0100 Subject: [PATCH 7/9] cs-fix --- src/Authentication/Passwords/ValidationRules.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Authentication/Passwords/ValidationRules.php b/src/Authentication/Passwords/ValidationRules.php index 263954557..b80ef0468 100644 --- a/src/Authentication/Passwords/ValidationRules.php +++ b/src/Authentication/Passwords/ValidationRules.php @@ -65,8 +65,9 @@ public function max_byte(?string $str, string $val): bool /** * Builds a new user instance from the global request. - * + * * @deprecated This will be removed soon. + * * @see https://github.com/codeigniter4/shield/pull/747#discussion_r1198778666 */ protected function buildUserFromRequest(): User From ad2e232a32773f49aed8b706678b43ee328e8e23 Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Tue, 23 May 2023 14:26:21 +0100 Subject: [PATCH 8/9] suppress phpstan deprecation error warning --- src/Authentication/Passwords/ValidationRules.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Authentication/Passwords/ValidationRules.php b/src/Authentication/Passwords/ValidationRules.php index 480920d28..29885e217 100644 --- a/src/Authentication/Passwords/ValidationRules.php +++ b/src/Authentication/Passwords/ValidationRules.php @@ -67,6 +67,8 @@ public function max_byte(?string $str, string $val): bool /** * Builds a new user instance from the global request. * + * @phpstan-ignore-next-line + * * @deprecated This will be removed soon. * * @see https://github.com/codeigniter4/shield/pull/747#discussion_r1198778666 From eedc9452ebc408f0a844dfa67f57a3dc2c60aca0 Mon Sep 17 00:00:00 2001 From: Samuel Asor Date: Tue, 23 May 2023 14:44:46 +0100 Subject: [PATCH 9/9] suppress phpstan deprecation warning --- src/Authentication/Passwords/ValidationRules.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Authentication/Passwords/ValidationRules.php b/src/Authentication/Passwords/ValidationRules.php index 29885e217..c240ec016 100644 --- a/src/Authentication/Passwords/ValidationRules.php +++ b/src/Authentication/Passwords/ValidationRules.php @@ -40,6 +40,7 @@ public function strong_password(string $value, ?string &$error1 = null, array $d if (function_exists('auth') && auth()->user()) { $user = auth()->user(); } else { + /** @phpstan-ignore-next-line */ $user = empty($data) ? $this->buildUserFromRequest() : $this->buildUserFromData($data); } @@ -67,8 +68,6 @@ public function max_byte(?string $str, string $val): bool /** * Builds a new user instance from the global request. * - * @phpstan-ignore-next-line - * * @deprecated This will be removed soon. * * @see https://github.com/codeigniter4/shield/pull/747#discussion_r1198778666