forked from ezsystems/repository-forms
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-29122: As a developer, I want to configure password policies in e…
…zuser (ezsystems#262) * EZP-29122: As a developer, I want to configure password policies in ezuser Field Definitions * fixup! EZP-29122: As a developer, I want to configure password policies in ezuser Field Definitions * fixup! EZP-29122: As a developer, I want to configure password policies in ezuser Field Definitions * fixup! EZP-29122: As a developer, I want to configure password policies in ezuser Field Definitions * fixup! EZP-29122: As a developer, I want to configure password policies in ezuser Field Definitions * EZP-29122: As a developer, I want to configure password policies in ezuser Field Definitions (QA)
- Loading branch information
Showing
21 changed files
with
698 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
lib/Form/Type/FieldDefinition/User/PasswordConstraintCheckboxType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EzSystems\RepositoryForms\Form\Type\FieldDefinition\User; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\CallbackTransformer; | ||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class PasswordConstraintCheckboxType extends AbstractType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder->addModelTransformer(new CallbackTransformer('boolval', 'boolval')); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildView(FormView $view, FormInterface $form, array $options): void | ||
{ | ||
$view->vars['label'] = 'field_definition.ezuser.' . $this->toSnakeCase($view->vars['name']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'required' => false, | ||
'translation_domain' => 'ezrepoforms_content_type', | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getParent(): string | ||
{ | ||
return CheckboxType::class; | ||
} | ||
|
||
/** | ||
* Converts given $string to the snake case. | ||
* | ||
* @param string $string | ||
* | ||
* @return string | ||
*/ | ||
private function toSnakeCase(string $string): string | ||
{ | ||
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($string))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EzSystems\RepositoryForms\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
class Password extends Constraint | ||
{ | ||
/** @var string */ | ||
public $message = 'ez.user.password.invalid'; | ||
|
||
/** @var \eZ\Publish\API\Repository\Values\ContentType\ContentType|null */ | ||
public $contentType; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTargets(): string | ||
{ | ||
return self::CLASS_CONSTRAINT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EzSystems\RepositoryForms\Validator\Constraints; | ||
|
||
use eZ\Publish\API\Repository\UserService; | ||
use eZ\Publish\API\Repository\Values\User\PasswordValidationContext; | ||
use EzSystems\RepositoryForms\Validator\ValidationErrorsProcessor; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
|
||
class PasswordValidator extends ConstraintValidator | ||
{ | ||
/** @var \eZ\Publish\API\Repository\UserService */ | ||
private $userService; | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\UserService $userService | ||
*/ | ||
public function __construct(UserService $userService) | ||
{ | ||
$this->userService = $userService; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validate($value, Constraint $constraint): void | ||
{ | ||
if (!\is_string($value) || empty($value)) { | ||
return; | ||
} | ||
|
||
$passwordValidationContext = new PasswordValidationContext([ | ||
'contentType' => $constraint->contentType, | ||
]); | ||
|
||
$validationErrors = $this->userService->validatePassword($value, $passwordValidationContext); | ||
if (!empty($validationErrors)) { | ||
$validationErrorsProcessor = $this->createValidationErrorsProcessor(); | ||
$validationErrorsProcessor->processValidationErrors($validationErrors); | ||
} | ||
} | ||
|
||
/** | ||
* @return \EzSystems\RepositoryForms\Validator\ValidationErrorsProcessor | ||
*/ | ||
protected function createValidationErrorsProcessor(): ValidationErrorsProcessor | ||
{ | ||
return new ValidationErrorsProcessor($this->context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EzSystems\RepositoryForms\Validator\Constraints; | ||
|
||
class UserAccountPassword extends Password | ||
{ | ||
} |
Oops, something went wrong.