Passed
Push — master ( 26f0d1...865369 )
by Anthony
03:01
created

Account::setUpdatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Symfony\Component\Security\Core\User\UserInterface;
7
8
/**
9
 * @ORM\Entity(repositoryClass="PiouPiou\RibsAdminBundle\Repository\AccountRepository")
10
 * @ORM\EntityListeners({"PiouPiou\RibsAdminBundle\EventListener\CreateUpdateAwareListener"})
11
 * @ORM\Table(name="account")
12
 */
13
class Account implements UserInterface, \Serializable
14
{
15
    use CreatedUpdatedTrait;
16
17
	/**
18
	 * @ORM\Id
19
	 * @ORM\Column(type="integer")
20
	 * @ORM\GeneratedValue(strategy="AUTO")
21
	 */
22
	protected $id;
23
	
24
	/**
25
	 * @ORM\Column(type="string", length=255, unique=true)
26
	 */
27
	private $username;
28
	
29
	/**
30
	 * @ORM\Column(type="string", length=64)
31
	 */
32
	private $password;
33
	
34
	/**
35
	 * @ORM\Column(type="string", length=64, nullable=true)
36
	 */
37
	private $plainPassword;
38
	
39
	/**
40
	 * @ORM\Column(type="string", length=100, unique=true)
41
	 */
42
	private $email;
43
	
44
	/**
45
	 * @ORM\Column(name="is_active", type="boolean")
46
	 */
47
	private $isActive;
48
49
    /**
50
     * @ORM\Column(type="datetime", nullable=true)
51
     */
52
    protected $last_connection;
53
54
    /**
55
     * @ORM\OneToMany(targetEntity="AccountToken", mappedBy="account")
56
     * @ORM\JoinColumn(name="id", referencedColumnName="account_id", nullable=false)
57
     */
58
    protected $tokens;
59
	
60
	/**
61
	 * @var User
62
	 *
63
	 * @ORM\OneToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User", cascade={"persist"})
64
	 * @ORM\JoinColumns({
65
	 *   @ORM\JoinColumn(name="id_user", referencedColumnName="id", nullable=true)
66
	 * })
67
	 */
68
	private $user;
69
	
70
	public function __construct()
71
	{
72
		$this->isActive = true;
73
		// may not be needed, see section on salt below
74
		// $this->salt = md5(uniqid('', true));
75
	}
76
	
77
	/**
78
	 * @return mixed
79
	 */
80
	public function getId()
81
	{
82
		return $this->id;
83
	}
84
	
85
	/**
86
	 * @param mixed $id
87
	 */
88
	public function setId($id)
89
	{
90
		$this->id = $id;
91
	}
92
	
93
	/**
94
	 * @return mixed
95
	 */
96
	public function getEmail()
97
	{
98
		return $this->email;
99
	}
100
	
101
	/**
102
	 * @param mixed $email
103
	 */
104
	public function setEmail($email)
105
	{
106
		$this->email = $email;
107
	}
108
	
109
	/**
110
	 * @return mixed
111
	 */
112
	public function getPassword()
113
	{
114
		return $this->password;
115
	}
116
	
117
	/**
118
	 * @param mixed $password
119
	 */
120
	public function setPassword($password)
121
	{
122
		$this->password = $password;
123
	}
124
	
125
	/**
126
	 * @return mixed
127
	 */
128
	public function getPlainPassword()
129
	{
130
		return $this->plainPassword;
131
	}
132
	
133
	/**
134
	 * @param mixed $plainPassword
135
	 */
136
	public function setPlainPassword(string $plainPassword)
137
	{
138
		$this->plainPassword = $plainPassword;
139
	}
140
	
141
	/**
142
	 * @return mixed
143
	 */
144
	public function getUsername()
145
	{
146
		return $this->username;
147
	}
148
	
149
	/**
150
	 * @param mixed $username
151
	 */
152
	public function setUsername($username)
153
	{
154
		$this->username = $username;
155
	}
156
	
157
	/**
158
	 * @return mixed
159
	 */
160
	public function getisActive()
161
	{
162
		return $this->isActive;
163
	}
164
	
165
	/**
166
	 * @param mixed $isActive
167
	 */
168
	public function setIsActive($isActive)
169
	{
170
		$this->isActive = $isActive;
171
	}
172
	
173
	/**
174
	 * @return User
175
	 */
176
	public function getUser()
177
	{
178
		return $this->user;
179
	}
180
	
181
	/**
182
	 * @param User $user
183
	 */
184
	public function setUser($user)
185
	{
186
		$this->user = $user;
187
	}
188
189
    /**
190
     * @return mixed
191
     */
192
    public function getLastConnection()
193
    {
194
        return $this->last_connection;
195
    }
196
197
    /**
198
     * @param mixed $last_connection
199
     * @return Account
200
     */
201
    public function setLastConnection($last_connection)
202
    {
203
        $this->last_connection = $last_connection;
204
205
        return $this;
206
    }
207
208
    /**
209
     * @return mixed
210
     */
211
    public function getTokens()
212
    {
213
        return $this->tokens;
214
    }
215
216
    /**
217
     * @param mixed $tokens
218
     * @return Account
219
     */
220
    public function setTokens($tokens)
221
    {
222
        $this->tokens = $tokens;
223
224
        return $this;
225
    }
226
	
227
	/**
228
	 * Returns the roles granted to the user.
229
	 *
230
	 * <code>
231
	 * public function getRoles()
232
	 * {
233
	 *     return array('ROLE_USER');
234
	 * }
235
	 * </code>
236
	 *
237
	 * Alternatively, the roles might be stored on a ``roles`` property,
238
	 * and populated in any number of different ways when the user object
239
	 * is created.
240
	 *
241
	 * @return (Role|string)[] The user roles
242
	 */
243
	public function getRoles()
244
	{
245
		return ['ROLE_ADMIN'];
246
	}
247
	
248
	/**
249
	 * Returns the salt that was originally used to encode the password.
250
	 *
251
	 * This can return null if the password was not encoded using a salt.
252
	 *
253
	 * @return string|null The salt
254
	 */
255
	public function getSalt()
256
	{
257
		// you *may* need a real salt depending on your encoder
258
		// see section on salt below
259
		return null;
260
	}
261
	
262
	/**
263
	 * Removes sensitive data from the user.
264
	 *
265
	 * This is important if, at any given point, sensitive information like
266
	 * the plain-text password is stored on this object.
267
	 */
268
	public function eraseCredentials()
269
	{
270
	}
271
	
272
	/**
273
	 * String representation of object
274
	 * @link http://php.net/manual/en/serializable.serialize.php
275
	 * @return string the string representation of the object or null
276
	 * @since 5.1.0
277
	 */
278
	public function serialize()
279
	{
280
		return serialize([
281
			$this->id,
282
			$this->username,
283
			$this->password,
284
			// see section on salt below
285
			// $this->salt,
286
		]);
287
	}
288
	
289
	/**
290
	 * Constructs the object
291
	 * @link http://php.net/manual/en/serializable.unserialize.php
292
	 * @param string $serialized <p>
293
	 * The string representation of the object.
294
	 * </p>
295
	 * @return void
296
	 * @since 5.1.0
297
	 */
298
	public function unserialize($serialized)
299
	{
300
		list (
301
			$this->id,
302
			$this->username,
303
			$this->password,
304
			// see section on salt below
305
			// $this->salt
306
			) = unserialize($serialized);
307
	}
308
}
309