WIP: Implement profile validation
This commit is contained in:
@@ -17,10 +17,12 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
class ProfileController extends AbstractController
|
class ProfileController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
private readonly ValidatorInterface $validator,
|
||||||
private readonly EntityManagerInterface $entityManager,
|
private readonly EntityManagerInterface $entityManager,
|
||||||
private readonly ApiClient $apiClient,
|
private readonly ApiClient $apiClient,
|
||||||
private readonly UploadHandler $uploadHandler,
|
private readonly UploadHandler $uploadHandler,
|
||||||
@@ -48,6 +50,9 @@ class ProfileController extends AbstractController
|
|||||||
$this->updatePhoto($user, $uploadSession);
|
$this->updatePhoto($user, $uploadSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate teamer data to show missing data right away
|
||||||
|
$errors = $this->validator->validate($teamer);
|
||||||
|
|
||||||
$form = $this->createForm(TeamerProfileType::class, $teamer, ['upload_session' => $uploadSession]);
|
$form = $this->createForm(TeamerProfileType::class, $teamer, ['upload_session' => $uploadSession]);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
@@ -72,6 +77,7 @@ class ProfileController extends AbstractController
|
|||||||
return $this->render('teamer/profile.html.twig', [
|
return $this->render('teamer/profile.html.twig', [
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'teamer' => $teamer,
|
'teamer' => $teamer,
|
||||||
|
'errors' => $errors,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
class Address
|
class Address
|
||||||
{
|
{
|
||||||
#[ORM\Column(type: 'string', nullable: true)]
|
#[ORM\Column(type: 'string', nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib deine Straße an')]
|
||||||
protected ?string $street = null;
|
protected ?string $street = null;
|
||||||
|
|
||||||
#[ORM\Column(type: 'string', nullable: true)]
|
#[ORM\Column(type: 'string', nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib deine Postleitzahl an')]
|
||||||
protected ?string $postCode = null;
|
protected ?string $postCode = null;
|
||||||
|
|
||||||
#[ORM\Column(type: 'string', nullable: true)]
|
#[ORM\Column(type: 'string', nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib deinen Ort an')]
|
||||||
protected ?string $city = null;
|
protected ?string $city = null;
|
||||||
|
|
||||||
#[ORM\Column(type: 'string', nullable: true)]
|
#[ORM\Column(type: 'string', nullable: true)]
|
||||||
|
|||||||
@@ -2,27 +2,25 @@
|
|||||||
|
|
||||||
namespace App\Entity\Embeddable;
|
namespace App\Entity\Embeddable;
|
||||||
|
|
||||||
|
use App\Validator\Constraints as AppAssert;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
#[ORM\Embeddable]
|
#[ORM\Embeddable]
|
||||||
|
#[AppAssert\BankAccount]
|
||||||
class BankAccount
|
class BankAccount
|
||||||
{
|
{
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\Iban(message: 'Die IBAN ist ungültig')]
|
||||||
#[Assert\Iban(message: 'Diese IBAN ist ungültig')]
|
|
||||||
private ?string $iban = null;
|
private ?string $iban = null;
|
||||||
|
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
||||||
private ?string $bic = null;
|
private ?string $bic = null;
|
||||||
|
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
||||||
private ?string $bank = null;
|
private ?string $bank = null;
|
||||||
|
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
||||||
private ?string $holder = null;
|
private ?string $holder = null;
|
||||||
|
|
||||||
public function getIban(bool $obfuscated = false): ?string
|
public function getIban(bool $obfuscated = false): ?string
|
||||||
|
|||||||
@@ -32,19 +32,19 @@ class Teamer implements TimestampableEntityInterface
|
|||||||
private string $uuid;
|
private string $uuid;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib deinen Vornamen an')]
|
||||||
private ?string $firstName = null;
|
private ?string $firstName = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib deinen Nachnamen an')]
|
||||||
private ?string $lastName = null;
|
private ?string $lastName = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 1)]
|
#[ORM\Column(length: 1)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib dein Geschlecht an')]
|
||||||
private ?string $gender = null;
|
private ?string $gender = null;
|
||||||
|
|
||||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||||
#[Assert\NotNull(message: 'Bitte angeben')]
|
#[Assert\NotNull(message: 'Bitte gib dein Geburtsdatum an')]
|
||||||
private ?\DateTimeImmutable $dateOfBirth = null;
|
private ?\DateTimeImmutable $dateOfBirth = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
@@ -54,7 +54,7 @@ class Teamer implements TimestampableEntityInterface
|
|||||||
private ?string $salutation = null;
|
private ?string $salutation = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib deine Nationalität an')]
|
||||||
private ?string $nationality = null;
|
private ?string $nationality = null;
|
||||||
|
|
||||||
#[ORM\Embedded(class: Address::class)]
|
#[ORM\Embedded(class: Address::class)]
|
||||||
@@ -70,11 +70,11 @@ class Teamer implements TimestampableEntityInterface
|
|||||||
private ?BankAccount $bankAccount = null;
|
private ?BankAccount $bankAccount = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib deine SteuerID an')]
|
||||||
private ?string $taxId = null;
|
private ?string $taxId = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
#[Assert\NotBlank(message: 'Bitte gib deine Krankenversicherung an')]
|
||||||
private ?string $healthInsuranceCompany = null;
|
private ?string $healthInsuranceCompany = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 32)]
|
#[ORM\Column(length: 32)]
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Validator\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
|
||||||
|
#[\Attribute]
|
||||||
|
class BankAccount extends Constraint
|
||||||
|
{
|
||||||
|
public string $message = 'Die Bankverbindung ist unvollständig';
|
||||||
|
|
||||||
|
public function __construct(string $message = null, array $groups = null, $payload = null)
|
||||||
|
{
|
||||||
|
parent::__construct([], $groups, $payload);
|
||||||
|
|
||||||
|
$this->message = $message ?? $this->message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTargets(): string
|
||||||
|
{
|
||||||
|
return Constraint::CLASS_CONSTRAINT;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Validator\Constraints;
|
||||||
|
|
||||||
|
use App\Entity\Embeddable\BankAccount as BankAccountEntity;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
|
|
||||||
|
class BankAccountValidator extends ConstraintValidator
|
||||||
|
{
|
||||||
|
public function validate(mixed $value, Constraint $constraint): void
|
||||||
|
{
|
||||||
|
if (!$value instanceof BankAccountEntity) {
|
||||||
|
throw new UnexpectedTypeException($value, BankAccountEntity::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$constraint instanceof BankAccount) {
|
||||||
|
throw new UnexpectedTypeException($constraint, BankAccount::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
$isIncomplete = null === $value->getIban()
|
||||||
|
|| null === $value->getBic()
|
||||||
|
|| null === $value->getBank()
|
||||||
|
|| null === $value->getHolder()
|
||||||
|
;
|
||||||
|
|
||||||
|
if ($isIncomplete) {
|
||||||
|
$this->context
|
||||||
|
->buildViolation($constraint->message)
|
||||||
|
->atPath('iban')
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
{% for child in form.children %}
|
{% for child in form.children %}
|
||||||
{% for error in child.vars.errors %}
|
{% for error in child.vars.errors %}
|
||||||
<li>
|
<li>
|
||||||
{{ child.vars.label }}: {{error.message}}
|
{{error.message}}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{%endfor%}
|
{%endfor%}
|
||||||
@@ -42,6 +42,16 @@
|
|||||||
{{ _self.formErrors(form.communication) }}
|
{{ _self.formErrors(form.communication) }}
|
||||||
{{ _self.formErrors(form.bankAccount) }}
|
{{ _self.formErrors(form.bankAccount) }}
|
||||||
</div>
|
</div>
|
||||||
|
{% elseif errors|length > 0 %}
|
||||||
|
<div class="max-w-screen-md mx-auto border border-red-500 rounded-md p-4 text-red-500 mb-8">
|
||||||
|
<ul>
|
||||||
|
{% for error in errors %}
|
||||||
|
<li>
|
||||||
|
{{ error.message }}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="pb-8 max-w-screen-md mx-auto" {{ stimulus_target('tabs', 'tab') }}>
|
<div class="pb-8 max-w-screen-md mx-auto" {{ stimulus_target('tabs', 'tab') }}>
|
||||||
<h3 class="text-xl font-bold pb-2">
|
<h3 class="text-xl font-bold pb-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user