first commit

This commit is contained in:
2023-07-20 11:56:10 +02:00
parent 08c221d3d5
commit f624b15207
341 changed files with 64075 additions and 103 deletions

13
src/Validator/Password.php Executable file
View File

@ -0,0 +1,13 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Password extends Constraint
{
public $message = 'Votre mot de passe doit contenir au minimum 8 caractères, constitué de chiffres, de lettres et caractères spéciaux';
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* @Annotation
*/
class PasswordValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
if (!empty($value)) {
if (strlen($value) < '8') {
$this->context->addViolation($constraint->message);
} elseif (!preg_match('#[0-9]+#', $value)) {
$this->context->addViolation($constraint->message);
} elseif (!preg_match('#[a-zA-Z]+#', $value)) {
$this->context->addViolation($constraint->message);
} elseif (!preg_match("/[|!@#$%&*\/=?,;.:\-_+~^\\\]/", $value)) {
$this->context->addViolation($constraint->message);
}
}
}
}

14
src/Validator/Userusername.php Executable file
View File

@ -0,0 +1,14 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Userusername extends Constraint
{
public $messageinvalid = "Le login n'est pas valide";
public $messagenotunique = 'Le login exisite déjà';
}

View File

@ -0,0 +1,42 @@
<?php
namespace App\Validator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* @Annotation
*/
class UserusernameValidator extends ConstraintValidator
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function validate($value, Constraint $constraint)
{
if (!empty($value)) {
// On s'assure que le login soit de 5 caractères minimum
if (strlen($value) < '5') {
$this->context->addViolation($constraint->messageinvalid);
}
// On s'assure que le username ne contient pas des caractères speciaux
$string = preg_replace('~[^@a-zA-Z0-9._-]~', '', $value);
if ($string != $value) {
$this->context->addViolation($constraint->messageinvalid);
}
// On s'assure que le username n'existe pas dans la table des registration
$registration = $this->em->getRepository("App\Entity\Registration")->findOneBy(['username' => $value]);
if ($registration) {
$this->context->addViolation($constraint->messagenotunique);
}
}
}
}