Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/bundle/Controller/UserRegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function registerConfirmAction(): ConfirmView

public function registerFromInvitationAction(Request $request): Response|FormView
{
$invitation = $this->invitationService->getInvitation($request->get('inviteHash'));
$invitation = $this->invitationService->getInvitation($request->attributes->get('inviteHash'));

if (!$this->invitationService->isValid($invitation)) {
throw new UnauthorizedHttpException('You are not allowed to register a new account');
Expand Down
8 changes: 4 additions & 4 deletions src/lib/Form/Type/UserPasswordChangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'first_options' => ['label' => /** @Desc("New password") */ 'ezplatform.change_user_password.new_password'],
'second_options' => ['label' => /** @Desc("Confirm password") */ 'ezplatform.change_user_password.confirm_new_password'],
'constraints' => [
new Password([
'contentType' => $options['content_type'],
'user' => $options['user'] ?? null,
]),
new Password(
contentType: $options['content_type'],
user: $options['user'] ?? null,
),
],
])
->add(
Expand Down
6 changes: 2 additions & 4 deletions src/lib/Form/Type/UserPasswordResetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'second_options' => ['label' => /** @Desc("Confirm password") */ 'ezplatform.reset_user_password.confirm_new_password'],
'constraints' => [
new Password(
[
'contentType' => $options['content_type'],
'user' => $options['user'] ?? null,
]
contentType: $options['content_type'],
user: $options['user'] ?? null,
),
],
])
Expand Down
15 changes: 15 additions & 0 deletions src/lib/Validator/Constraints/EmailInvitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint;

/**
Expand All @@ -19,6 +20,20 @@ class EmailInvitation extends Constraint implements TranslationContainerInterfac
{
public string $message = 'ibexa.user.invitation.user_with_email_exists';

/**
* @param array<string>|null $groups
*/
#[HasNamedArguments]
public function __construct(
?string $message = null,
?array $groups = null,
mixed $payload = null,
) {
parent::__construct(null, $groups, $payload);

$this->message = $message ?? $this->message;
}

public static function getTranslationMessages(): array
{
return [
Expand Down
19 changes: 19 additions & 0 deletions src/lib/Validator/Constraints/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Contracts\Core\Repository\Values\User\User;
use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint;

/**
Expand All @@ -23,6 +24,24 @@ class Password extends Constraint

public ?User $user = null;

/**
* @param array<string>|null $groups
*/
#[HasNamedArguments]
public function __construct(
?ContentType $contentType = null,
?User $user = null,
?string $message = null,
?array $groups = null,
mixed $payload = null,
) {
parent::__construct(null, $groups, $payload);

$this->contentType = $contentType;
$this->user = $user;
$this->message = $message ?? $this->message;
}

#[\Override]
public function getTargets(): array
{
Expand Down
15 changes: 15 additions & 0 deletions src/lib/Validator/Constraints/UserPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint;

/**
Expand All @@ -19,6 +20,20 @@ class UserPassword extends Constraint implements TranslationContainerInterface
{
public string $message = 'ezplatform.change_user_password.not_match';

/**
* @param array<string>|null $groups
*/
#[HasNamedArguments]
public function __construct(
?string $message = null,
?array $groups = null,
mixed $payload = null,
) {
parent::__construct(null, $groups, $payload);

$this->message = $message ?? $this->message;
}

/**
* @return \JMS\TranslationBundle\Model\Message[]
*/
Expand Down
32 changes: 16 additions & 16 deletions tests/lib/Validator/Constraint/PasswordValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ static function (string $actualPassword, PasswordValidationContext $actualContex

$this->validator->validate(
$password,
new Password([
'contentType' => $contentType,
'user' => $user,
])
new Password(
contentType: $contentType,
user: $user,
)
);
}

Expand Down Expand Up @@ -140,9 +140,9 @@ public function testInvalid(): void
->expects(self::once())
->method('addViolation');

$this->validator->validate('pass', new Password([
'contentType' => $contentType,
]));
$this->validator->validate('pass', new Password(
contentType: $contentType,
));
}

public function testPluralValidationErrorUsesPluralMessageTemplate(): void
Expand Down Expand Up @@ -174,9 +174,9 @@ public function testPluralValidationErrorUsesPluralMessageTemplate(): void
->with('plural error')
->willReturn($constraintViolationBuilder);

$this->validator->validate('pass', new Password([
'contentType' => $contentType,
]));
$this->validator->validate('pass', new Password(
contentType: $contentType,
));
}

/**
Expand Down Expand Up @@ -212,9 +212,9 @@ public function testKnownValidationErrorsGetRequirementCode(
->with($errorMessage)
->willReturn($constraintViolationBuilder);

$this->validator->validate('pass', new Password([
'contentType' => $contentType,
]));
$this->validator->validate('pass', new Password(
contentType: $contentType,
));
}

/**
Expand Down Expand Up @@ -293,9 +293,9 @@ public function testEveryCoreCharacterRuleErrorProducesRequirementCode(): void
->method('buildViolation')
->willReturn($constraintViolationBuilder);

$this->validator->validate('pass', new Password([
'contentType' => $this->createMock(ContentType::class),
]));
$this->validator->validate('pass', new Password(
contentType: $this->createMock(ContentType::class),
));
}

/**
Expand Down
Loading