Explorar o código

Improve username validation to avoid nonsense accounts

Jordi Boggiano %!s(int64=6) %!d(string=hai) anos
pai
achega
abf8762876
Modificáronse 1 ficheiros con 19 adicións e 0 borrados
  1. 19 0
      src/Packagist/WebBundle/Entity/User.php

+ 19 - 0
src/Packagist/WebBundle/Entity/User.php

@@ -14,6 +14,7 @@ namespace Packagist\WebBundle\Entity;
 
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Validator\Constraints as Assert;
 use FOS\UserBundle\Model\User as BaseUser;
 
 /**
@@ -61,6 +62,24 @@ class User extends BaseUser
      */
     protected $id;
 
+    /**
+     * @Assert\Length(
+     *     min=8,
+     *     max=180,
+     *     groups={"Profile", "Registration"}
+     * )
+     * @Assert\Regex(
+     *     pattern="{^[^/""\r\n><#\[\]]{2,100}$}",
+     *     message="Username invalid, /""\r\n><#[] are not allowed",
+     *     groups={"Profile", "Registration"}
+     * )
+     * @Assert\NotBlank(
+     *     message="fos_user.username.blank",
+     *     groups={"Profile", "Registration"}
+     * )
+     */
+    protected $username;
+
     /**
      * @ORM\ManyToMany(targetEntity="Package", mappedBy="maintainers")
      */