浏览代码

Contrainte uniqueEntity sur username, mail et token des users

François 6 年之前
父节点
当前提交
6ff6eda117
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      src/AppBundle/Entity/User.php

+ 8 - 0
src/AppBundle/Entity/User.php

@@ -5,12 +5,18 @@ namespace AppBundle\Entity;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Security\Core\User\UserInterface;
+use Symfony\Component\Validator\Constraints as Assert;
+use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 
 /**
  * User
  *
  * @ORM\Table(name="user")
  * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
+ * @UniqueEntity(fields="username", message="Le username est déjà utilisé")
+ * @UniqueEntity(fields="mail", message="L'email est déjà utilisé")
+ * @UniqueEntity(fields="token", message="Erreur, token non unique")
+ *
  */
 class User implements UserInterface
 {
@@ -357,6 +363,8 @@ class User implements UserInterface
     public function __construct()
     {
         $this->films = new \Doctrine\Common\Collections\ArrayCollection();
+        $this->setToken();
+        $this->setLastActivity(new \DateTime('now'));
     }
 
     ///////////////////////////////////////////////////////////////