first commit symfony 6
This commit is contained in:
12
src/Validator/Grouplabel.php
Normal file
12
src/Validator/Grouplabel.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace App\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class Grouplabel extends Constraint
|
||||
{
|
||||
public $message = "Caractères interdit dans ce label";
|
||||
}
|
29
src/Validator/GrouplabelValidator.php
Normal file
29
src/Validator/GrouplabelValidator.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace App\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class GrouplabelValidator extends ConstraintValidator
|
||||
{
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
/*
|
||||
$tmp=$this->getEntityBy("App:Group","label",$value);
|
||||
if($tmp) $form->addError(new FormError('Un groupe utilise déjà ce label'));
|
||||
|
||||
$tmp=$this->getEntityBy("App:Niveau02","label",$data->getLabel());
|
||||
if($tmp) $form->addError(new FormError('Un niveau de rang 02 utilise déjà ce label'));
|
||||
*/
|
||||
|
||||
// On s'assure que le label ne contient pas des caractères speciaux
|
||||
$string = preg_replace('~[^ éèêôöàïî\'@a-zA-Z0-9._-]~', '', $value);
|
||||
if($string!=$value)
|
||||
{
|
||||
$this->context->addViolation($constraint->message);
|
||||
}
|
||||
}
|
||||
}
|
13
src/Validator/Niveau01unique.php
Normal file
13
src/Validator/Niveau01unique.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace App\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class Niveau01unique extends Constraint
|
||||
{
|
||||
public $messagegroup = "Un groupe utilise déjà ce label";
|
||||
public $messageniveau02 = "Un niveau de rang 02 utilise déjà ce label";
|
||||
}
|
32
src/Validator/Niveau01uniqueValidator.php
Normal file
32
src/Validator/Niveau01uniqueValidator.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace App\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class Niveau01uniqueValidator extends ConstraintValidator
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
$group = $this->em->getRepository("App\Entity\Group")->findOneBy(["label"=>$value]);
|
||||
if($group) {
|
||||
$this->context->addViolation($constraint->messagegroup);
|
||||
}
|
||||
|
||||
$niveau02 = $this->em->getRepository("App\Entity\Niveau02")->findOneBy(["label"=>$value]);
|
||||
if($niveau02) {
|
||||
$this->context->addViolation($constraint->messageniveau02);
|
||||
}
|
||||
}
|
||||
}
|
13
src/Validator/Niveau02unique.php
Normal file
13
src/Validator/Niveau02unique.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace App\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class Niveau02unique extends Constraint
|
||||
{
|
||||
public $messagegroup = "Un groupe utilise déjà ce label";
|
||||
public $messageniveau01 = "Un niveau de rang 01 utilise déjà ce label";
|
||||
}
|
32
src/Validator/Niveau02uniqueValidator.php
Normal file
32
src/Validator/Niveau02uniqueValidator.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace App\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class Niveau02uniqueValidator extends ConstraintValidator
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
$group = $this->em->getRepository("App\Entity\Group")->findOneBy(["label"=>$value]);
|
||||
if($group) {
|
||||
$this->context->addViolation($constraint->messagegroup);
|
||||
}
|
||||
|
||||
$niveau02 = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(["label"=>$value]);
|
||||
if($niveau02) {
|
||||
$this->context->addViolation($constraint->messageniveau01);
|
||||
}
|
||||
}
|
||||
}
|
12
src/Validator/Password.php
Normal file
12
src/Validator/Password.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?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";
|
||||
}
|
29
src/Validator/PasswordValidator.php
Normal file
29
src/Validator/PasswordValidator.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
src/Validator/Userusername.php
Normal file
13
src/Validator/Userusername.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?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à";
|
||||
}
|
41
src/Validator/UserusernameValidator.php
Normal file
41
src/Validator/UserusernameValidator.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace App\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user