diff options
Diffstat (limited to 'src/Wallabag/UserBundle/Entity')
-rw-r--r-- | src/Wallabag/UserBundle/Entity/User.php | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 3a167de7..aba76ca7 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php | |||
@@ -4,11 +4,12 @@ namespace Wallabag\UserBundle\Entity; | |||
4 | 4 | ||
5 | use Doctrine\Common\Collections\ArrayCollection; | 5 | use Doctrine\Common\Collections\ArrayCollection; |
6 | use Doctrine\ORM\Mapping as ORM; | 6 | use Doctrine\ORM\Mapping as ORM; |
7 | use JMS\Serializer\Annotation\Groups; | ||
8 | use JMS\Serializer\Annotation\XmlRoot; | ||
9 | use JMS\Serializer\Annotation\Accessor; | ||
7 | use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; | 10 | use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; |
8 | use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; | 11 | use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; |
9 | use FOS\UserBundle\Model\User as BaseUser; | 12 | use FOS\UserBundle\Model\User as BaseUser; |
10 | use JMS\Serializer\Annotation\ExclusionPolicy; | ||
11 | use JMS\Serializer\Annotation\Expose; | ||
12 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | 13 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
13 | use Symfony\Component\Security\Core\User\UserInterface; | 14 | use Symfony\Component\Security\Core\User\UserInterface; |
14 | use Wallabag\ApiBundle\Entity\Client; | 15 | use Wallabag\ApiBundle\Entity\Client; |
@@ -18,23 +19,25 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
18 | /** | 19 | /** |
19 | * User. | 20 | * User. |
20 | * | 21 | * |
22 | * @XmlRoot("user") | ||
21 | * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository") | 23 | * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository") |
22 | * @ORM\Table(name="`user`") | 24 | * @ORM\Table(name="`user`") |
23 | * @ORM\HasLifecycleCallbacks() | 25 | * @ORM\HasLifecycleCallbacks() |
24 | * @ExclusionPolicy("all") | ||
25 | * | 26 | * |
26 | * @UniqueEntity("email") | 27 | * @UniqueEntity("email") |
27 | * @UniqueEntity("username") | 28 | * @UniqueEntity("username") |
28 | */ | 29 | */ |
29 | class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface | 30 | class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface |
30 | { | 31 | { |
32 | /** @Serializer\XmlAttribute */ | ||
31 | /** | 33 | /** |
32 | * @var int | 34 | * @var int |
33 | * | 35 | * |
34 | * @Expose | ||
35 | * @ORM\Column(name="id", type="integer") | 36 | * @ORM\Column(name="id", type="integer") |
36 | * @ORM\Id | 37 | * @ORM\Id |
37 | * @ORM\GeneratedValue(strategy="AUTO") | 38 | * @ORM\GeneratedValue(strategy="AUTO") |
39 | * | ||
40 | * @Groups({"user_api", "user_api_with_client"}) | ||
38 | */ | 41 | */ |
39 | protected $id; | 42 | protected $id; |
40 | 43 | ||
@@ -42,20 +45,40 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
42 | * @var string | 45 | * @var string |
43 | * | 46 | * |
44 | * @ORM\Column(name="name", type="text", nullable=true) | 47 | * @ORM\Column(name="name", type="text", nullable=true) |
48 | * | ||
49 | * @Groups({"user_api", "user_api_with_client"}) | ||
45 | */ | 50 | */ |
46 | protected $name; | 51 | protected $name; |
47 | 52 | ||
48 | /** | 53 | /** |
49 | * @var date | 54 | * @var string |
55 | * | ||
56 | * @Groups({"user_api", "user_api_with_client"}) | ||
57 | */ | ||
58 | protected $username; | ||
59 | |||
60 | /** | ||
61 | * @var string | ||
62 | * | ||
63 | * @Groups({"user_api", "user_api_with_client"}) | ||
64 | */ | ||
65 | protected $email; | ||
66 | |||
67 | /** | ||
68 | * @var \DateTime | ||
50 | * | 69 | * |
51 | * @ORM\Column(name="created_at", type="datetime") | 70 | * @ORM\Column(name="created_at", type="datetime") |
71 | * | ||
72 | * @Groups({"user_api", "user_api_with_client"}) | ||
52 | */ | 73 | */ |
53 | protected $createdAt; | 74 | protected $createdAt; |
54 | 75 | ||
55 | /** | 76 | /** |
56 | * @var date | 77 | * @var \DateTime |
57 | * | 78 | * |
58 | * @ORM\Column(name="updated_at", type="datetime") | 79 | * @ORM\Column(name="updated_at", type="datetime") |
80 | * | ||
81 | * @Groups({"user_api", "user_api_with_client"}) | ||
59 | */ | 82 | */ |
60 | protected $updatedAt; | 83 | protected $updatedAt; |
61 | 84 | ||
@@ -75,7 +98,8 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
75 | private $authCode; | 98 | private $authCode; |
76 | 99 | ||
77 | /** | 100 | /** |
78 | * @var bool Enabled yes/no | 101 | * @var bool |
102 | * | ||
79 | * @ORM\Column(type="boolean") | 103 | * @ORM\Column(type="boolean") |
80 | */ | 104 | */ |
81 | private $twoFactorAuthentication = false; | 105 | private $twoFactorAuthentication = false; |
@@ -86,10 +110,20 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
86 | private $trusted; | 110 | private $trusted; |
87 | 111 | ||
88 | /** | 112 | /** |
113 | * @var ArrayCollection | ||
114 | * | ||
89 | * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) | 115 | * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) |
90 | */ | 116 | */ |
91 | protected $clients; | 117 | protected $clients; |
92 | 118 | ||
119 | /** | ||
120 | * @see getFirstClient() below | ||
121 | * | ||
122 | * @Groups({"user_api_with_client"}) | ||
123 | * @Accessor(getter="getFirstClient") | ||
124 | */ | ||
125 | protected $default_client; | ||
126 | |||
93 | public function __construct() | 127 | public function __construct() |
94 | { | 128 | { |
95 | parent::__construct(); | 129 | parent::__construct(); |
@@ -135,7 +169,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
135 | } | 169 | } |
136 | 170 | ||
137 | /** | 171 | /** |
138 | * @return string | 172 | * @return \DateTime |
139 | */ | 173 | */ |
140 | public function getCreatedAt() | 174 | public function getCreatedAt() |
141 | { | 175 | { |
@@ -143,7 +177,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
143 | } | 177 | } |
144 | 178 | ||
145 | /** | 179 | /** |
146 | * @return string | 180 | * @return \DateTime |
147 | */ | 181 | */ |
148 | public function getUpdatedAt() | 182 | public function getUpdatedAt() |
149 | { | 183 | { |
@@ -266,4 +300,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
266 | { | 300 | { |
267 | return $this->clients; | 301 | return $this->clients; |
268 | } | 302 | } |
303 | |||
304 | /** | ||
305 | * Only used by the API when creating a new user it'll also return the first client (which was also created at the same time). | ||
306 | * | ||
307 | * @return Client | ||
308 | */ | ||
309 | public function getFirstClient() | ||
310 | { | ||
311 | if (!empty($this->clients)) { | ||
312 | return $this->clients->first(); | ||
313 | } | ||
314 | } | ||
269 | } | 315 | } |