Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation and Custom-Validator throws error since flow 6 #50

Merged
merged 5 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Classes/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,11 +31,11 @@ class ProfileController extends ActionController
*/
protected $userRepository;

/**
* @Flow\Inject
* @var AuthenticationManagerInterface
*/
protected $authenticationManager;
/**
* @Flow\Inject
* @var TokenAndProviderFactoryInterface
*/
protected $tokenAndProviderFactory;

/**
* @Flow\Inject
Expand Down Expand Up @@ -104,7 +104,7 @@ protected function getErrorFlashMessage()
*/
protected function setPassword(Account $account, $password)
{
$tokens = $this->authenticationManager->getTokens();
$tokens = $this->tokenAndProviderFactory->getTokens();
$indexedTokens = array();
foreach ($tokens as $token) {
/** @var TokenInterface $token */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Sandstorm\UserManagement\Domain\Service;

use Sandstorm\UserManagement\Domain\Model\RegistrationFlow;
use Neos\Error\Messages\Result as ErrorResult;
use Neos\Flow\Annotations as Flow;

/**
* @api
*/
interface RegistrationFlow6ValidationServiceInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you still remove the one obsolete interface? :-) :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

{

/**
* You can implement custom validations for your registration flows by implementing this method in your own service.
*
* @param RegistrationFlow $registrationFlow
* @param ErrorResult $validatorResult
* @return void
*/
public function validateRegistrationFlow6(RegistrationFlow $registrationFlow, ErrorResult $validatorResult);
}
18 changes: 10 additions & 8 deletions Classes/Domain/Validator/RegistrationFlowValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,31 @@ class RegistrationFlowValidator extends AbstractValidator
*/
protected function isValid($value)
{

/** @noinspection PhpUndefinedMethodInspection */
$existingAccount = $this->accountRepository->findOneByAccountIdentifier($value->getEmail());

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
if ($this->objectManager->isRegistered(RegistrationFlowValidationServiceInterface::class)) {
$instance = $this->objectManager->get(RegistrationFlowValidationServiceInterface::class);
$instance->validateRegistrationFlow($value, $this);
}

}

/**
* The custom validation service might need to access the result directly, so it is exposed here
*
* @return Result
*/
public function getResult()
{
return $this->result;
}
skurfuerst marked this conversation as resolved.
Show resolved Hide resolved
*/
public function getResult()
{
return parent::getResult();
}

}