diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-10-23 11:09:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 11:09:17 +0200 |
commit | 1953a872932a63792293b4aec087880265ba89f7 (patch) | |
tree | fd16599e737fcdaf193c933ef3ec4a4ee248b117 /src/Wallabag/UserBundle/Entity | |
parent | d83d25dadec2c38460a32d96f5d2903426fec9d3 (diff) | |
parent | 702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff) | |
download | wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst wallabag-1953a872932a63792293b4aec087880265ba89f7.zip |
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'src/Wallabag/UserBundle/Entity')
-rw-r--r-- | src/Wallabag/UserBundle/Entity/User.php | 99 |
1 files changed, 71 insertions, 28 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 3a167de7..48446e3c 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php | |||
@@ -4,37 +4,43 @@ 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 FOS\UserBundle\Model\User as BaseUser; | ||
8 | use JMS\Serializer\Annotation\Accessor; | ||
9 | use JMS\Serializer\Annotation\Groups; | ||
10 | use JMS\Serializer\Annotation\XmlRoot; | ||
7 | use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; | 11 | use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; |
8 | use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; | 12 | use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; |
9 | 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; |
15 | use Wallabag\CoreBundle\Entity\Config; | 16 | use Wallabag\CoreBundle\Entity\Config; |
16 | use Wallabag\CoreBundle\Entity\Entry; | 17 | use Wallabag\CoreBundle\Entity\Entry; |
18 | use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; | ||
17 | 19 | ||
18 | /** | 20 | /** |
19 | * User. | 21 | * User. |
20 | * | 22 | * |
23 | * @XmlRoot("user") | ||
21 | * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository") | 24 | * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository") |
22 | * @ORM\Table(name="`user`") | 25 | * @ORM\Table(name="`user`") |
23 | * @ORM\HasLifecycleCallbacks() | 26 | * @ORM\HasLifecycleCallbacks() |
24 | * @ExclusionPolicy("all") | ||
25 | * | 27 | * |
26 | * @UniqueEntity("email") | 28 | * @UniqueEntity("email") |
27 | * @UniqueEntity("username") | 29 | * @UniqueEntity("username") |
28 | */ | 30 | */ |
29 | class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface | 31 | class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface |
30 | { | 32 | { |
33 | use EntityTimestampsTrait; | ||
34 | |||
35 | /** @Serializer\XmlAttribute */ | ||
31 | /** | 36 | /** |
32 | * @var int | 37 | * @var int |
33 | * | 38 | * |
34 | * @Expose | ||
35 | * @ORM\Column(name="id", type="integer") | 39 | * @ORM\Column(name="id", type="integer") |
36 | * @ORM\Id | 40 | * @ORM\Id |
37 | * @ORM\GeneratedValue(strategy="AUTO") | 41 | * @ORM\GeneratedValue(strategy="AUTO") |
42 | * | ||
43 | * @Groups({"user_api", "user_api_with_client"}) | ||
38 | */ | 44 | */ |
39 | protected $id; | 45 | protected $id; |
40 | 46 | ||
@@ -42,20 +48,40 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
42 | * @var string | 48 | * @var string |
43 | * | 49 | * |
44 | * @ORM\Column(name="name", type="text", nullable=true) | 50 | * @ORM\Column(name="name", type="text", nullable=true) |
51 | * | ||
52 | * @Groups({"user_api", "user_api_with_client"}) | ||
45 | */ | 53 | */ |
46 | protected $name; | 54 | protected $name; |
47 | 55 | ||
48 | /** | 56 | /** |
49 | * @var date | 57 | * @var string |
58 | * | ||
59 | * @Groups({"user_api", "user_api_with_client"}) | ||
60 | */ | ||
61 | protected $username; | ||
62 | |||
63 | /** | ||
64 | * @var string | ||
65 | * | ||
66 | * @Groups({"user_api", "user_api_with_client"}) | ||
67 | */ | ||
68 | protected $email; | ||
69 | |||
70 | /** | ||
71 | * @var \DateTime | ||
50 | * | 72 | * |
51 | * @ORM\Column(name="created_at", type="datetime") | 73 | * @ORM\Column(name="created_at", type="datetime") |
74 | * | ||
75 | * @Groups({"user_api", "user_api_with_client"}) | ||
52 | */ | 76 | */ |
53 | protected $createdAt; | 77 | protected $createdAt; |
54 | 78 | ||
55 | /** | 79 | /** |
56 | * @var date | 80 | * @var \DateTime |
57 | * | 81 | * |
58 | * @ORM\Column(name="updated_at", type="datetime") | 82 | * @ORM\Column(name="updated_at", type="datetime") |
83 | * | ||
84 | * @Groups({"user_api", "user_api_with_client"}) | ||
59 | */ | 85 | */ |
60 | protected $updatedAt; | 86 | protected $updatedAt; |
61 | 87 | ||
@@ -70,12 +96,35 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
70 | protected $config; | 96 | protected $config; |
71 | 97 | ||
72 | /** | 98 | /** |
99 | * @var ArrayCollection | ||
100 | * | ||
101 | * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\SiteCredential", mappedBy="user", cascade={"remove"}) | ||
102 | */ | ||
103 | protected $siteCredentials; | ||
104 | |||
105 | /** | ||
106 | * @var ArrayCollection | ||
107 | * | ||
108 | * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) | ||
109 | */ | ||
110 | protected $clients; | ||
111 | |||
112 | /** | ||
113 | * @see getFirstClient() below | ||
114 | * | ||
115 | * @Groups({"user_api_with_client"}) | ||
116 | * @Accessor(getter="getFirstClient") | ||
117 | */ | ||
118 | protected $default_client; | ||
119 | |||
120 | /** | ||
73 | * @ORM\Column(type="integer", nullable=true) | 121 | * @ORM\Column(type="integer", nullable=true) |
74 | */ | 122 | */ |
75 | private $authCode; | 123 | private $authCode; |
76 | 124 | ||
77 | /** | 125 | /** |
78 | * @var bool Enabled yes/no | 126 | * @var bool |
127 | * | ||
79 | * @ORM\Column(type="boolean") | 128 | * @ORM\Column(type="boolean") |
80 | */ | 129 | */ |
81 | private $twoFactorAuthentication = false; | 130 | private $twoFactorAuthentication = false; |
@@ -85,11 +134,6 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
85 | */ | 134 | */ |
86 | private $trusted; | 135 | private $trusted; |
87 | 136 | ||
88 | /** | ||
89 | * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"}) | ||
90 | */ | ||
91 | protected $clients; | ||
92 | |||
93 | public function __construct() | 137 | public function __construct() |
94 | { | 138 | { |
95 | parent::__construct(); | 139 | parent::__construct(); |
@@ -98,19 +142,6 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
98 | } | 142 | } |
99 | 143 | ||
100 | /** | 144 | /** |
101 | * @ORM\PrePersist | ||
102 | * @ORM\PreUpdate | ||
103 | */ | ||
104 | public function timestamps() | ||
105 | { | ||
106 | if (is_null($this->createdAt)) { | ||
107 | $this->createdAt = new \DateTime(); | ||
108 | } | ||
109 | |||
110 | $this->updatedAt = new \DateTime(); | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * Set name. | 145 | * Set name. |
115 | * | 146 | * |
116 | * @param string $name | 147 | * @param string $name |
@@ -135,7 +166,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
135 | } | 166 | } |
136 | 167 | ||
137 | /** | 168 | /** |
138 | * @return string | 169 | * @return \DateTime |
139 | */ | 170 | */ |
140 | public function getCreatedAt() | 171 | public function getCreatedAt() |
141 | { | 172 | { |
@@ -143,7 +174,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
143 | } | 174 | } |
144 | 175 | ||
145 | /** | 176 | /** |
146 | * @return string | 177 | * @return \DateTime |
147 | */ | 178 | */ |
148 | public function getUpdatedAt() | 179 | public function getUpdatedAt() |
149 | { | 180 | { |
@@ -266,4 +297,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
266 | { | 297 | { |
267 | return $this->clients; | 298 | return $this->clients; |
268 | } | 299 | } |
300 | |||
301 | /** | ||
302 | * 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). | ||
303 | * | ||
304 | * @return Client | ||
305 | */ | ||
306 | public function getFirstClient() | ||
307 | { | ||
308 | if (!empty($this->clients)) { | ||
309 | return $this->clients->first(); | ||
310 | } | ||
311 | } | ||
269 | } | 312 | } |