From 6ee3b8bc18b22be9e71851a9c14508dd57b61697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Sirin?= Date: Thu, 8 Oct 2020 17:37:56 +0200 Subject: [PATCH 1/5] #48 validation error since flow 6 --- .../Domain/Validator/RegistrationFlowValidator.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Classes/Domain/Validator/RegistrationFlowValidator.php b/Classes/Domain/Validator/RegistrationFlowValidator.php index c2d7854..cf2b294 100644 --- a/Classes/Domain/Validator/RegistrationFlowValidator.php +++ b/Classes/Domain/Validator/RegistrationFlowValidator.php @@ -49,7 +49,7 @@ protected function isValid($value) if ($existingAccount) { $message = $this->translator->translateById('validations.registrationflow.email', [$value->getEmail()], null, null, 'Main', 'Sandstorm.UserManagement'); - $this->result->forProperty('email')->addError(new Error($message, 1336499566)); + $this->getResult()->forProperty('email')->addError(new Error($message, 1336499566)); } // If a custom validation service is registered, call its validate method to allow custom validations during registration @@ -59,13 +59,4 @@ protected function isValid($value) } } - /** - * The custom validation service might need to access the result directly, so it is exposed here - * - * @return Result - */ - public function getResult() - { - return $this->result; - } } From c0c972225883cdd115075dd57b5ecdad234bcd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Sirin?= Date: Thu, 8 Oct 2020 17:48:25 +0200 Subject: [PATCH 2/5] validation service for flow6 --- ...trationFlow6ValidationServiceInterface.php | 22 +++++++++++++++++++ .../Validator/RegistrationFlowValidator.php | 6 +++++ README.md | 18 ++++++++++----- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 Classes/Domain/Service/RegistrationFlow6ValidationServiceInterface.php diff --git a/Classes/Domain/Service/RegistrationFlow6ValidationServiceInterface.php b/Classes/Domain/Service/RegistrationFlow6ValidationServiceInterface.php new file mode 100644 index 0000000..190c44b --- /dev/null +++ b/Classes/Domain/Service/RegistrationFlow6ValidationServiceInterface.php @@ -0,0 +1,22 @@ +objectManager->get(RegistrationFlowValidationServiceInterface::class); $instance->validateRegistrationFlow($value, $this); } + + // for >= flow 6 + if ($this->objectManager->isRegistered(RegistrationFlow6ValidationServiceInterface::class)) { + $instance = $this->objectManager->get(RegistrationFlow6ValidationServiceInterface::class); + $instance->validateRegistrationFlow6($value, $this->getResult()); + } } } diff --git a/README.md b/README.md index ae74c77..cf367de 100644 --- a/README.md +++ b/README.md @@ -338,19 +338,27 @@ This will add the field, but of course you might also want to validate it. ### Extending the Registration Flow validation logic The UserManagement package has a hook for you to implement your custom registration flow validation logic. It is called directly from the domain model validator of the package. All you need to to is create an implementation of -`Sandstorm\UserManagement\Domain\Service\RegistrationFlowValidationServiceInterface` in your own package. It could +`Sandstorm\UserManagement\Domain\Service\RegistrationFlow6ValidationServiceInterface` in your own package. It could look like this: ```PHP -class RegistrationFlowValidationService implements RegistrationFlowValidationServiceInterface { + +namespace Your\Project\Domain\Service; + +use Sandstorm\UserManagement\Domain\Service\RegistrationFlow6ValidationServiceInterface; +use Sandstorm\UserManagement\Domain\Model\RegistrationFlow; +use Neos\Error\Messages\Result as ErrorResult; +use Neos\Flow\Annotations as Flow; + +class RegistrationFlow6ValidationService implements RegistrationFlow6ValidationServiceInterface { /** * @param RegistrationFlow $registrationFlow - * @param RegistrationFlowValidator $validator + * @param ErrorResult $validatorResult * @return void */ - public function validateRegistrationFlow(RegistrationFlow $registrationFlow, RegistrationFlowValidator $validator) { + public function validateRegistrationFlow6(RegistrationFlow $registrationFlow, ErrorResult $validatorResult) { // This is an example of your own custom validation logic. if ($registrationFlow->getAttributes()['agb'] !== '1') { - $validator->getResult()->forProperty('attributes.terms')->addError(new \Neos\Flow\Validation\Error('You need to accept the terms and conditions.')); + $validatorResult->forProperty('attributes.terms')->addError(new \Neos\Flow\Validation\Error('You need to accept the terms and conditions.')); } } } From 197f5ed4a85b4f35528f667cb72bde1f2fcd287c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Sirin?= Date: Tue, 20 Oct 2020 15:27:35 +0200 Subject: [PATCH 3/5] removed deprecated call --- Classes/Controller/ProfileController.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Classes/Controller/ProfileController.php b/Classes/Controller/ProfileController.php index a382902..762f602 100644 --- a/Classes/Controller/ProfileController.php +++ b/Classes/Controller/ProfileController.php @@ -5,7 +5,7 @@ use Neos\Flow\Mvc\Controller\ActionController; use Neos\Flow\Security\Account; use Neos\Flow\Security\AccountRepository; -use Neos\Flow\Security\Authentication\AuthenticationManagerInterface; +use Neos\Flow\Security\Authentication\TokenAndProviderFactoryInterface; use Neos\Flow\Security\Authentication\Token\UsernamePassword; use Neos\Flow\Security\Authentication\TokenInterface; use Neos\Flow\Security\Context; @@ -31,11 +31,11 @@ class ProfileController extends ActionController */ protected $userRepository; - /** - * @Flow\Inject - * @var AuthenticationManagerInterface - */ - protected $authenticationManager; + /** + * @Flow\Inject + * @var TokenAndProviderFactoryInterface + */ + protected $tokenAndProviderFactoryInterface; /** * @Flow\Inject @@ -104,7 +104,7 @@ protected function getErrorFlashMessage() */ protected function setPassword(Account $account, $password) { - $tokens = $this->authenticationManager->getTokens(); + $tokens = $this->tokenAndProviderFactoryInterface->getTokens(); $indexedTokens = array(); foreach ($tokens as $token) { /** @var TokenInterface $token */ From 46db5b3b8123e7ec8dcbbf7114f8c59f33850dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Sirin?= Date: Fri, 23 Oct 2020 21:57:23 +0200 Subject: [PATCH 4/5] changes for pull request --- Classes/Controller/ProfileController.php | 4 ++-- .../Validator/RegistrationFlowValidator.php | 17 +++++++++++------ README.md | 18 +++++------------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Classes/Controller/ProfileController.php b/Classes/Controller/ProfileController.php index 762f602..ad48d9f 100644 --- a/Classes/Controller/ProfileController.php +++ b/Classes/Controller/ProfileController.php @@ -35,7 +35,7 @@ class ProfileController extends ActionController * @Flow\Inject * @var TokenAndProviderFactoryInterface */ - protected $tokenAndProviderFactoryInterface; + protected $tokenAndProviderFactory; /** * @Flow\Inject @@ -104,7 +104,7 @@ protected function getErrorFlashMessage() */ protected function setPassword(Account $account, $password) { - $tokens = $this->tokenAndProviderFactoryInterface->getTokens(); + $tokens = $this->tokenAndProviderFactory->getTokens(); $indexedTokens = array(); foreach ($tokens as $token) { /** @var TokenInterface $token */ diff --git a/Classes/Domain/Validator/RegistrationFlowValidator.php b/Classes/Domain/Validator/RegistrationFlowValidator.php index 3a86bff..84cf1e3 100644 --- a/Classes/Domain/Validator/RegistrationFlowValidator.php +++ b/Classes/Domain/Validator/RegistrationFlowValidator.php @@ -43,7 +43,7 @@ class RegistrationFlowValidator extends AbstractValidator */ protected function isValid($value) { - + /** @noinspection PhpUndefinedMethodInspection */ $existingAccount = $this->accountRepository->findOneByAccountIdentifier($value->getEmail()); @@ -58,11 +58,16 @@ protected function isValid($value) $instance->validateRegistrationFlow($value, $this); } - // for >= flow 6 - if ($this->objectManager->isRegistered(RegistrationFlow6ValidationServiceInterface::class)) { - $instance = $this->objectManager->get(RegistrationFlow6ValidationServiceInterface::class); - $instance->validateRegistrationFlow6($value, $this->getResult()); - } } + + /** + * The custom validation service might need to access the result directly, so it is exposed here + * + * @return Result + */ + public function getResult() + { + return parent::getResult(); + } } diff --git a/README.md b/README.md index cf367de..ae74c77 100644 --- a/README.md +++ b/README.md @@ -338,27 +338,19 @@ This will add the field, but of course you might also want to validate it. ### Extending the Registration Flow validation logic The UserManagement package has a hook for you to implement your custom registration flow validation logic. It is called directly from the domain model validator of the package. All you need to to is create an implementation of -`Sandstorm\UserManagement\Domain\Service\RegistrationFlow6ValidationServiceInterface` in your own package. It could +`Sandstorm\UserManagement\Domain\Service\RegistrationFlowValidationServiceInterface` in your own package. It could look like this: ```PHP - -namespace Your\Project\Domain\Service; - -use Sandstorm\UserManagement\Domain\Service\RegistrationFlow6ValidationServiceInterface; -use Sandstorm\UserManagement\Domain\Model\RegistrationFlow; -use Neos\Error\Messages\Result as ErrorResult; -use Neos\Flow\Annotations as Flow; - -class RegistrationFlow6ValidationService implements RegistrationFlow6ValidationServiceInterface { +class RegistrationFlowValidationService implements RegistrationFlowValidationServiceInterface { /** * @param RegistrationFlow $registrationFlow - * @param ErrorResult $validatorResult + * @param RegistrationFlowValidator $validator * @return void */ - public function validateRegistrationFlow6(RegistrationFlow $registrationFlow, ErrorResult $validatorResult) { + public function validateRegistrationFlow(RegistrationFlow $registrationFlow, RegistrationFlowValidator $validator) { // This is an example of your own custom validation logic. if ($registrationFlow->getAttributes()['agb'] !== '1') { - $validatorResult->forProperty('attributes.terms')->addError(new \Neos\Flow\Validation\Error('You need to accept the terms and conditions.')); + $validator->getResult()->forProperty('attributes.terms')->addError(new \Neos\Flow\Validation\Error('You need to accept the terms and conditions.')); } } } From 23d358a252b4c38f266e5c6ad87c4a65dbe07ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Sirin?= Date: Fri, 23 Oct 2020 22:03:53 +0200 Subject: [PATCH 5/5] removed RegistrationFlow6ValidationServiceInterface --- ...trationFlow6ValidationServiceInterface.php | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 Classes/Domain/Service/RegistrationFlow6ValidationServiceInterface.php diff --git a/Classes/Domain/Service/RegistrationFlow6ValidationServiceInterface.php b/Classes/Domain/Service/RegistrationFlow6ValidationServiceInterface.php deleted file mode 100644 index 190c44b..0000000 --- a/Classes/Domain/Service/RegistrationFlow6ValidationServiceInterface.php +++ /dev/null @@ -1,22 +0,0 @@ -