aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Entity/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/UserBundle/Entity/User.php')
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index ed6ce331..5c75846f 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
6use Doctrine\ORM\Mapping as ORM; 6use Doctrine\ORM\Mapping as ORM;
7use JMS\Serializer\Annotation\Groups; 7use JMS\Serializer\Annotation\Groups;
8use JMS\Serializer\Annotation\XmlRoot; 8use JMS\Serializer\Annotation\XmlRoot;
9use JMS\Serializer\Annotation\Accessor;
9use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; 10use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
10use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; 11use Scheb\TwoFactorBundle\Model\TrustedComputerInterface;
11use FOS\UserBundle\Model\User as BaseUser; 12use FOS\UserBundle\Model\User as BaseUser;
@@ -36,7 +37,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
36 * @ORM\Id 37 * @ORM\Id
37 * @ORM\GeneratedValue(strategy="AUTO") 38 * @ORM\GeneratedValue(strategy="AUTO")
38 * 39 *
39 * @Groups({"user_api"}) 40 * @Groups({"user_api", "user_api_with_client"})
40 */ 41 */
41 protected $id; 42 protected $id;
42 43
@@ -45,21 +46,21 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
45 * 46 *
46 * @ORM\Column(name="name", type="text", nullable=true) 47 * @ORM\Column(name="name", type="text", nullable=true)
47 * 48 *
48 * @Groups({"user_api"}) 49 * @Groups({"user_api", "user_api_with_client"})
49 */ 50 */
50 protected $name; 51 protected $name;
51 52
52 /** 53 /**
53 * @var string 54 * @var string
54 * 55 *
55 * @Groups({"user_api"}) 56 * @Groups({"user_api", "user_api_with_client"})
56 */ 57 */
57 protected $username; 58 protected $username;
58 59
59 /** 60 /**
60 * @var string 61 * @var string
61 * 62 *
62 * @Groups({"user_api"}) 63 * @Groups({"user_api", "user_api_with_client"})
63 */ 64 */
64 protected $email; 65 protected $email;
65 66
@@ -68,7 +69,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
68 * 69 *
69 * @ORM\Column(name="created_at", type="datetime") 70 * @ORM\Column(name="created_at", type="datetime")
70 * 71 *
71 * @Groups({"user_api"}) 72 * @Groups({"user_api", "user_api_with_client"})
72 */ 73 */
73 protected $createdAt; 74 protected $createdAt;
74 75
@@ -77,7 +78,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
77 * 78 *
78 * @ORM\Column(name="updated_at", type="datetime") 79 * @ORM\Column(name="updated_at", type="datetime")
79 * 80 *
80 * @Groups({"user_api"}) 81 * @Groups({"user_api", "user_api_with_client"})
81 */ 82 */
82 protected $updatedAt; 83 protected $updatedAt;
83 84
@@ -97,7 +98,8 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
97 private $authCode; 98 private $authCode;
98 99
99 /** 100 /**
100 * @var bool Enabled yes/no 101 * @var bool
102 *
101 * @ORM\Column(type="boolean") 103 * @ORM\Column(type="boolean")
102 */ 104 */
103 private $twoFactorAuthentication = false; 105 private $twoFactorAuthentication = false;
@@ -112,6 +114,14 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
112 */ 114 */
113 protected $clients; 115 protected $clients;
114 116
117 /**
118 * @see getFirstClient() below
119 *
120 * @Groups({"user_api_with_client"})
121 * @Accessor(getter="getFirstClient")
122 */
123 protected $default_client;
124
115 public function __construct() 125 public function __construct()
116 { 126 {
117 parent::__construct(); 127 parent::__construct();
@@ -288,4 +298,18 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
288 { 298 {
289 return $this->clients; 299 return $this->clients;
290 } 300 }
301
302 /**
303 * 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).
304 *
305 * @return Client
306 */
307 public function getFirstClient()
308 {
309 if (empty($this->clients)) {
310 return $this->clients;
311 }
312
313 return $this->clients->first();
314 }
291} 315}