first commit
This commit is contained in:
13
src/Validator/Password.php
Executable file
13
src/Validator/Password.php
Executable 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';
|
||||
}
|
27
src/Validator/PasswordValidator.php
Executable file
27
src/Validator/PasswordValidator.php
Executable 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
14
src/Validator/Userusername.php
Executable 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à';
|
||||
}
|
42
src/Validator/UserusernameValidator.php
Executable file
42
src/Validator/UserusernameValidator.php
Executable 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user