From 878fb1956fd18c9aad8e1201c1d769f895d9504a Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Thu, 8 Feb 2024 21:59:25 -0500 Subject: [PATCH] Update deprecated code --- .../Controller/Dashboard/DashboardAction.php | 2 +- app/src/Controller/Group/GroupCreateAction.php | 17 ++++++++--------- app/src/Controller/Group/GroupCreateModal.php | 6 +++--- app/src/Controller/Group/GroupEditAction.php | 17 ++++++++--------- app/src/Controller/Group/GroupEditModal.php | 6 +++--- app/src/Controller/Role/RoleCreateAction.php | 17 ++++++++--------- app/src/Controller/Role/RoleCreateModal.php | 6 +++--- app/src/Controller/Role/RoleEditAction.php | 17 ++++++++--------- app/src/Controller/Role/RoleEditModal.php | 6 +++--- .../Controller/Role/RoleUpdateFieldAction.php | 17 ++++++++--------- app/src/Controller/User/UserCreateAction.php | 17 ++++++++--------- app/src/Controller/User/UserCreateModal.php | 8 +++----- app/src/Controller/User/UserEditAction.php | 17 ++++++++--------- app/src/Controller/User/UserEditModal.php | 6 +++--- app/src/Controller/User/UserPasswordModal.php | 8 +++----- .../Controller/User/UserUpdateFieldAction.php | 17 ++++++++--------- app/src/Mail/PasswordEmail.php | 4 ++-- 17 files changed, 88 insertions(+), 100 deletions(-) diff --git a/app/src/Controller/Dashboard/DashboardAction.php b/app/src/Controller/Dashboard/DashboardAction.php index 7e8fca6..3759ab2 100644 --- a/app/src/Controller/Dashboard/DashboardAction.php +++ b/app/src/Controller/Dashboard/DashboardAction.php @@ -139,7 +139,7 @@ protected function getLatestUsers(): array */ protected function getDatabaseInfo(): array { - $database = $this->config->getString('db.default'); + $database = $this->config->getString('db.default', ''); $pdo = $this->dbConnection->getPdo(); $results = [ 'connection' => $database, diff --git a/app/src/Controller/Group/GroupCreateAction.php b/app/src/Controller/Group/GroupCreateAction.php index a8fad8c..09b0ad3 100644 --- a/app/src/Controller/Group/GroupCreateAction.php +++ b/app/src/Controller/Group/GroupCreateAction.php @@ -16,11 +16,10 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use UserFrosting\Alert\AlertStream; -use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; +use UserFrosting\Fortress\Transformer\RequestDataTransformer; +use UserFrosting\Fortress\Validator\ServerSideValidator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\GroupInterface; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; @@ -56,8 +55,9 @@ public function __construct( protected Authenticator $authenticator, protected Connection $db, protected GroupInterface $groupModel, - protected Translator $translator, protected UserActivityLogger $userActivityLogger, + protected RequestDataTransformer $transformer, + protected ServerSideValidator $validator, ) { } @@ -92,8 +92,7 @@ protected function handle(Request $request): void $schema = $this->getSchema(); // Whitelist and set parameter defaults - $transformer = new RequestDataTransformer($schema); - $data = $transformer->transform($params); + $data = $this->transformer->transform($schema, $params); // Validate request data $this->validateData($schema, $data); @@ -153,10 +152,10 @@ protected function getSchema(): RequestSchemaInterface */ protected function validateData(RequestSchemaInterface $schema, array $data): void { - $validator = new ServerSideValidator($schema, $this->translator); - if ($validator->validate($data) === false && is_array($validator->errors())) { + $errors = $this->validator->validate($schema, $data); + if (count($errors) !== 0) { $e = new ValidationException(); - $e->addErrors($validator->errors()); + $e->addErrors($errors); throw $e; } diff --git a/app/src/Controller/Group/GroupCreateModal.php b/app/src/Controller/Group/GroupCreateModal.php index 47a0e48..c88298a 100644 --- a/app/src/Controller/Group/GroupCreateModal.php +++ b/app/src/Controller/Group/GroupCreateModal.php @@ -15,7 +15,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; -use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; +use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; use UserFrosting\I18n\Translator; @@ -50,6 +50,7 @@ public function __construct( protected GroupInterface $groupModel, protected Translator $translator, protected Twig $view, + protected JqueryValidationArrayAdapter $adapter, ) { } @@ -82,7 +83,6 @@ protected function handle(): array // Load the request schema & validator $schema = $this->getSchema(); - $validatorRegister = new JqueryValidationAdapter($schema, $this->translator); // Determine form fields to hide/disable $fields = [ @@ -99,7 +99,7 @@ protected function handle(): array 'submit_text' => $this->translator->translate('CREATE'), ], 'page' => [ - 'validators' => $validatorRegister->rules(), + 'validators' => $this->adapter->rules($schema), ], ]; } diff --git a/app/src/Controller/Group/GroupEditAction.php b/app/src/Controller/Group/GroupEditAction.php index 2f20400..a4b0872 100644 --- a/app/src/Controller/Group/GroupEditAction.php +++ b/app/src/Controller/Group/GroupEditAction.php @@ -17,11 +17,10 @@ use Psr\Http\Message\ServerRequestInterface as Request; use UserFrosting\Alert\AlertStream; use UserFrosting\Config\Config; -use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; +use UserFrosting\Fortress\Transformer\RequestDataTransformer; +use UserFrosting\Fortress\Validator\ServerSideValidator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\GroupInterface; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; @@ -55,9 +54,10 @@ public function __construct( protected Authenticator $authenticator, protected Config $config, protected Connection $db, - protected Translator $translator, protected UserActivityLogger $userActivityLogger, protected GroupInterface $groupModel, + protected RequestDataTransformer $transformer, + protected ServerSideValidator $validator, ) { } @@ -93,8 +93,7 @@ protected function handle(GroupInterface $group, Request $request): void $schema = $this->getSchema(); // Whitelist and set parameter defaults - $transformer = new RequestDataTransformer($schema); - $data = $transformer->transform($params); + $data = $this->transformer->transform($schema, $params); // Validate request data $this->validateData($schema, $data); @@ -164,10 +163,10 @@ protected function getSchema(): RequestSchemaInterface */ protected function validateData(RequestSchemaInterface $schema, array $data): void { - $validator = new ServerSideValidator($schema, $this->translator); - if ($validator->validate($data) === false && is_array($validator->errors())) { + $errors = $this->validator->validate($schema, $data); + if (count($errors) !== 0) { $e = new ValidationException(); - $e->addErrors($validator->errors()); + $e->addErrors($errors); throw $e; } diff --git a/app/src/Controller/Group/GroupEditModal.php b/app/src/Controller/Group/GroupEditModal.php index 1350844..12fde37 100644 --- a/app/src/Controller/Group/GroupEditModal.php +++ b/app/src/Controller/Group/GroupEditModal.php @@ -15,7 +15,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; -use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; +use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; use UserFrosting\I18n\Translator; @@ -49,6 +49,7 @@ public function __construct( protected SiteLocaleInterface $siteLocale, protected Translator $translator, protected Twig $view, + protected JqueryValidationArrayAdapter $adapter, ) { } @@ -93,7 +94,6 @@ protected function handle(GroupInterface $group): array // Load validation rules $schema = $this->getSchema(); - $validator = new JqueryValidationAdapter($schema, $this->translator); return [ 'group' => $group, @@ -104,7 +104,7 @@ protected function handle(GroupInterface $group): array 'submit_text' => $this->translator->translate('UPDATE'), ], 'page' => [ - 'validators' => $validator->rules(), + 'validators' => $this->adapter->rules($schema), ], ]; } diff --git a/app/src/Controller/Role/RoleCreateAction.php b/app/src/Controller/Role/RoleCreateAction.php index b2d4042..9de9307 100644 --- a/app/src/Controller/Role/RoleCreateAction.php +++ b/app/src/Controller/Role/RoleCreateAction.php @@ -16,11 +16,10 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use UserFrosting\Alert\AlertStream; -use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; +use UserFrosting\Fortress\Transformer\RequestDataTransformer; +use UserFrosting\Fortress\Validator\ServerSideValidator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\RoleInterface; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; @@ -56,8 +55,9 @@ public function __construct( protected Authenticator $authenticator, protected Connection $db, protected RoleInterface $roleModel, - protected Translator $translator, protected UserActivityLogger $userActivityLogger, + protected RequestDataTransformer $transformer, + protected ServerSideValidator $validator, ) { } @@ -92,8 +92,7 @@ protected function handle(Request $request): void $schema = $this->getSchema(); // Whitelist and set parameter defaults - $transformer = new RequestDataTransformer($schema); - $data = $transformer->transform($params); + $data = $this->transformer->transform($schema, $params); // Validate request data $this->validateData($schema, $data); @@ -153,10 +152,10 @@ protected function getSchema(): RequestSchemaInterface */ protected function validateData(RequestSchemaInterface $schema, array $data): void { - $validator = new ServerSideValidator($schema, $this->translator); - if ($validator->validate($data) === false && is_array($validator->errors())) { + $errors = $this->validator->validate($schema, $data); + if (count($errors) !== 0) { $e = new ValidationException(); - $e->addErrors($validator->errors()); + $e->addErrors($errors); throw $e; } diff --git a/app/src/Controller/Role/RoleCreateModal.php b/app/src/Controller/Role/RoleCreateModal.php index c27b66f..4c85286 100644 --- a/app/src/Controller/Role/RoleCreateModal.php +++ b/app/src/Controller/Role/RoleCreateModal.php @@ -15,7 +15,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; -use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; +use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; use UserFrosting\I18n\Translator; @@ -47,6 +47,7 @@ public function __construct( protected RoleInterface $roleModel, protected Translator $translator, protected Twig $view, + protected JqueryValidationArrayAdapter $adapter, ) { } @@ -76,7 +77,6 @@ protected function handle(): array // Load the request schema & validator $schema = $this->getSchema(); - $validatorRegister = new JqueryValidationAdapter($schema, $this->translator); // Determine form fields to hide/disable $fields = [ @@ -93,7 +93,7 @@ protected function handle(): array 'submit_text' => $this->translator->translate('CREATE'), ], 'page' => [ - 'validators' => $validatorRegister->rules(), + 'validators' => $this->adapter->rules($schema), ], ]; } diff --git a/app/src/Controller/Role/RoleEditAction.php b/app/src/Controller/Role/RoleEditAction.php index e9de4e2..34af751 100644 --- a/app/src/Controller/Role/RoleEditAction.php +++ b/app/src/Controller/Role/RoleEditAction.php @@ -17,11 +17,10 @@ use Psr\Http\Message\ServerRequestInterface as Request; use UserFrosting\Alert\AlertStream; use UserFrosting\Config\Config; -use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; +use UserFrosting\Fortress\Transformer\RequestDataTransformer; +use UserFrosting\Fortress\Validator\ServerSideValidator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\RoleInterface; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; @@ -55,9 +54,10 @@ public function __construct( protected Authenticator $authenticator, protected Config $config, protected Connection $db, - protected Translator $translator, protected UserActivityLogger $userActivityLogger, protected RoleInterface $roleModel, + protected RequestDataTransformer $transformer, + protected ServerSideValidator $validator, ) { } @@ -93,8 +93,7 @@ protected function handle(RoleInterface $role, Request $request): void $schema = $this->getSchema(); // Whitelist and set parameter defaults - $transformer = new RequestDataTransformer($schema); - $data = $transformer->transform($params); + $data = $this->transformer->transform($schema, $params); // Validate request data $this->validateData($schema, $data); @@ -164,10 +163,10 @@ protected function getSchema(): RequestSchemaInterface */ protected function validateData(RequestSchemaInterface $schema, array $data): void { - $validator = new ServerSideValidator($schema, $this->translator); - if ($validator->validate($data) === false && is_array($validator->errors())) { + $errors = $this->validator->validate($schema, $data); + if (count($errors) !== 0) { $e = new ValidationException(); - $e->addErrors($validator->errors()); + $e->addErrors($errors); throw $e; } diff --git a/app/src/Controller/Role/RoleEditModal.php b/app/src/Controller/Role/RoleEditModal.php index 8bfba06..febb9a4 100644 --- a/app/src/Controller/Role/RoleEditModal.php +++ b/app/src/Controller/Role/RoleEditModal.php @@ -15,7 +15,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; -use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; +use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; use UserFrosting\I18n\Translator; @@ -50,6 +50,7 @@ public function __construct( protected SiteLocaleInterface $siteLocale, protected Translator $translator, protected Twig $view, + protected JqueryValidationArrayAdapter $adapter, ) { } @@ -94,7 +95,6 @@ protected function handle(RoleInterface $role): array // Load validation rules $schema = $this->getSchema(); - $validator = new JqueryValidationAdapter($schema, $this->translator); return [ 'role' => $role, @@ -105,7 +105,7 @@ protected function handle(RoleInterface $role): array 'submit_text' => $this->translator->translate('UPDATE'), ], 'page' => [ - 'validators' => $validator->rules(), + 'validators' => $this->adapter->rules($schema), ], ]; } diff --git a/app/src/Controller/Role/RoleUpdateFieldAction.php b/app/src/Controller/Role/RoleUpdateFieldAction.php index 4342de6..ba2afb3 100644 --- a/app/src/Controller/Role/RoleUpdateFieldAction.php +++ b/app/src/Controller/Role/RoleUpdateFieldAction.php @@ -18,11 +18,10 @@ use Psr\Http\Message\ServerRequestInterface as Request; use UserFrosting\Alert\AlertStream; use UserFrosting\Config\Config; -use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; +use UserFrosting\Fortress\Transformer\RequestDataTransformer; +use UserFrosting\Fortress\Validator\ServerSideValidator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\RoleInterface; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; @@ -54,8 +53,9 @@ public function __construct( protected Authenticator $authenticator, protected Config $config, protected Connection $db, - protected Translator $translator, protected UserActivityLogger $userActivityLogger, + protected RequestDataTransformer $transformer, + protected ServerSideValidator $validator, ) { } @@ -126,8 +126,7 @@ protected function handle( $schema = $this->getSchema(); // Whitelist and set parameter defaults - $transformer = new RequestDataTransformer($schema); - $data = $transformer->transform($params); + $data = $this->transformer->transform($schema, $params); // Validate request data $this->validateData($schema, $data); @@ -185,10 +184,10 @@ protected function getSchema(): RequestSchemaInterface */ protected function validateData(RequestSchemaInterface $schema, array $data): void { - $validator = new ServerSideValidator($schema, $this->translator); - if ($validator->validate($data) === false && is_array($validator->errors())) { + $errors = $this->validator->validate($schema, $data); + if (count($errors) !== 0) { $e = new ValidationException(); - $e->addErrors($validator->errors()); + $e->addErrors($errors); throw $e; } diff --git a/app/src/Controller/User/UserCreateAction.php b/app/src/Controller/User/UserCreateAction.php index 7d1c5c2..5721949 100644 --- a/app/src/Controller/User/UserCreateAction.php +++ b/app/src/Controller/User/UserCreateAction.php @@ -18,11 +18,10 @@ use Psr\Http\Message\ServerRequestInterface as Request; use UserFrosting\Alert\AlertStream; use UserFrosting\Config\Config; -use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; +use UserFrosting\Fortress\Transformer\RequestDataTransformer; +use UserFrosting\Fortress\Validator\ServerSideValidator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\GroupInterface; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; @@ -67,12 +66,13 @@ public function __construct( protected EventDispatcherInterface $eventDispatcher, protected GroupInterface $groupModel, protected SiteLocaleInterface $siteLocale, - protected Translator $translator, protected UserActivityLogger $userActivityLogger, protected PasswordEmail $passwordEmail, protected UserInterface $userModel, protected UserValidation $userValidation, protected DebugLogger $debugLogger, + protected RequestDataTransformer $transformer, + protected ServerSideValidator $validator, ) { } @@ -107,8 +107,7 @@ protected function handle(Request $request): void $schema = $this->getSchema(); // Whitelist and set parameter defaults - $transformer = new RequestDataTransformer($schema); - $data = $transformer->transform($params); + $data = $this->transformer->transform($schema, $params); // If no password is set, set password as empty on initial creation. // We will then send email so new user can set it themselves via a @@ -211,10 +210,10 @@ protected function getSchema(): RequestSchemaInterface */ protected function validateData(RequestSchemaInterface $schema, array $data): void { - $validator = new ServerSideValidator($schema, $this->translator); - if ($validator->validate($data) === false && is_array($validator->errors())) { + $errors = $this->validator->validate($schema, $data); + if (count($errors) !== 0) { $e = new ValidationException(); - $e->addErrors($validator->errors()); + $e->addErrors($errors); throw $e; } diff --git a/app/src/Controller/User/UserCreateModal.php b/app/src/Controller/User/UserCreateModal.php index 9f059bb..8df8955 100644 --- a/app/src/Controller/User/UserCreateModal.php +++ b/app/src/Controller/User/UserCreateModal.php @@ -16,7 +16,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; use UserFrosting\Config\Config; -use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; +use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; use UserFrosting\I18n\Translator; @@ -57,6 +57,7 @@ public function __construct( protected Translator $translator, protected Twig $view, protected UserInterface $userModel, + protected JqueryValidationArrayAdapter $adapter, ) { } @@ -85,9 +86,6 @@ protected function handle(): array // Load the request schema $schema = $this->getSchema(); - // Get validator - $validatorRegister = new JqueryValidationAdapter($schema, $this->translator); - // Determine form fields to hide/disable $fields = [ 'hidden' => [], @@ -130,7 +128,7 @@ protected function handle(): array 'submit_text' => $this->translator->translate('CREATE'), ], 'page' => [ - 'validators' => $validatorRegister->rules(), + 'validators' => $this->adapter->rules($schema), ], ]; } diff --git a/app/src/Controller/User/UserEditAction.php b/app/src/Controller/User/UserEditAction.php index ae4b0fd..3f04d2d 100644 --- a/app/src/Controller/User/UserEditAction.php +++ b/app/src/Controller/User/UserEditAction.php @@ -17,11 +17,10 @@ use Psr\Http\Message\ServerRequestInterface as Request; use UserFrosting\Alert\AlertStream; use UserFrosting\Config\Config; -use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; +use UserFrosting\Fortress\Transformer\RequestDataTransformer; +use UserFrosting\Fortress\Validator\ServerSideValidator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; use UserFrosting\Sprinkle\Account\Exceptions\EmailNotUniqueException; @@ -53,9 +52,10 @@ public function __construct( protected Authenticator $authenticator, protected Config $config, protected Connection $db, - protected Translator $translator, protected UserActivityLogger $userActivityLogger, protected UserInterface $userModel, + protected RequestDataTransformer $transformer, + protected ServerSideValidator $validator, ) { } @@ -91,8 +91,7 @@ protected function handle(UserInterface $user, Request $request): void $schema = $this->getSchema(); // Whitelist and set parameter defaults - $transformer = new RequestDataTransformer($schema); - $data = $transformer->transform($params); + $data = $this->transformer->transform($schema, $params); // Validate request data $this->validateData($schema, $data); @@ -187,10 +186,10 @@ protected function getSchema(): RequestSchemaInterface */ protected function validateData(RequestSchemaInterface $schema, array $data): void { - $validator = new ServerSideValidator($schema, $this->translator); - if ($validator->validate($data) === false && is_array($validator->errors())) { + $errors = $this->validator->validate($schema, $data); + if (count($errors) !== 0) { $e = new ValidationException(); - $e->addErrors($validator->errors()); + $e->addErrors($errors); throw $e; } diff --git a/app/src/Controller/User/UserEditModal.php b/app/src/Controller/User/UserEditModal.php index e1dc955..81ac798 100644 --- a/app/src/Controller/User/UserEditModal.php +++ b/app/src/Controller/User/UserEditModal.php @@ -15,7 +15,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; -use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; +use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; use UserFrosting\I18n\Translator; @@ -54,6 +54,7 @@ public function __construct( protected SiteLocaleInterface $siteLocale, protected Translator $translator, protected Twig $view, + protected JqueryValidationArrayAdapter $adapter, ) { } @@ -117,7 +118,6 @@ protected function handle(UserInterface $user): array // Load validation rules $schema = $this->getSchema(); - $validator = new JqueryValidationAdapter($schema, $this->translator); return [ 'user' => $user, @@ -130,7 +130,7 @@ protected function handle(UserInterface $user): array 'submit_text' => $this->translator->translate('UPDATE'), ], 'page' => [ - 'validators' => $validator->rules(), + 'validators' => $this->adapter->rules($schema), ], ]; } diff --git a/app/src/Controller/User/UserPasswordModal.php b/app/src/Controller/User/UserPasswordModal.php index 01cff7d..b4d92cd 100644 --- a/app/src/Controller/User/UserPasswordModal.php +++ b/app/src/Controller/User/UserPasswordModal.php @@ -16,10 +16,9 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; use UserFrosting\Config\Config; -use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; +use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\I18n\Translator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\GroupInterface; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; @@ -50,9 +49,9 @@ public function __construct( protected Config $config, protected GroupInterface $groupModel, protected SiteLocaleInterface $siteLocale, - protected Translator $translator, protected Twig $view, protected UserInterface $userModel, + protected JqueryValidationArrayAdapter $adapter, ) { } @@ -84,12 +83,11 @@ protected function handle(UserInterface $user): array // Load the request schema $schema = $this->getSchema(); - $validator = new JqueryValidationAdapter($schema, $this->translator); return [ 'user' => $user, 'page' => [ - 'validators' => $validator->rules(), + 'validators' => $this->adapter->rules($schema), ], ]; } diff --git a/app/src/Controller/User/UserUpdateFieldAction.php b/app/src/Controller/User/UserUpdateFieldAction.php index accd6b8..ec36177 100644 --- a/app/src/Controller/User/UserUpdateFieldAction.php +++ b/app/src/Controller/User/UserUpdateFieldAction.php @@ -18,11 +18,10 @@ use Psr\Http\Message\ServerRequestInterface as Request; use UserFrosting\Alert\AlertStream; use UserFrosting\Config\Config; -use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; +use UserFrosting\Fortress\Transformer\RequestDataTransformer; +use UserFrosting\Fortress\Validator\ServerSideValidator; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; use UserFrosting\Sprinkle\Account\Exceptions\AccountException; @@ -56,8 +55,9 @@ public function __construct( protected Authenticator $authenticator, protected Config $config, protected Connection $db, - protected Translator $translator, protected UserActivityLogger $userActivityLogger, + protected RequestDataTransformer $transformer, + protected ServerSideValidator $validator, ) { } @@ -141,8 +141,7 @@ protected function handle( $schema = $this->getSchema(); // Whitelist and set parameter defaults - $transformer = new RequestDataTransformer($schema); - $data = $transformer->transform($params); + $data = $this->transformer->transform($schema, $params); // Validate request data $this->validateData($schema, $data); @@ -234,10 +233,10 @@ protected function getSchema(): RequestSchemaInterface */ protected function validateData(RequestSchemaInterface $schema, array $data): void { - $validator = new ServerSideValidator($schema, $this->translator); - if ($validator->validate($data) === false && is_array($validator->errors())) { + $errors = $this->validator->validate($schema, $data); + if (count($errors) !== 0) { $e = new ValidationException(); - $e->addErrors($validator->errors()); + $e->addErrors($errors); throw $e; } diff --git a/app/src/Mail/PasswordEmail.php b/app/src/Mail/PasswordEmail.php index 51ce749..8d5b378 100644 --- a/app/src/Mail/PasswordEmail.php +++ b/app/src/Mail/PasswordEmail.php @@ -43,7 +43,7 @@ public function __construct( public function send(UserInterface $user, string $template = 'mail/password-create.html.twig'): void { // Try to generate a new verification request - $timeout = $this->config->getInt('password_reset.timeouts.create'); + $timeout = $this->config->getInt('password_reset.timeouts.create', 86400); $verification = $this->repoPasswordReset->create($user, $timeout); // Create and send verification email @@ -54,7 +54,7 @@ public function send(UserInterface $user, string $template = 'mail/password-crea ->addEmailRecipient(new EmailRecipient($user->email, $user->full_name)) ->addParams([ 'user' => $user, - 'create_password_expiration' => $this->config->getInt('password_reset.timeouts.create') / 3600 . ' hours', + 'create_password_expiration' => $timeout / 3600 . ' hours', 'token' => $verification->getToken(), 'request_date' => Carbon::now()->format('Y-m-d H:i:s'), ]);