Passed
Push — master ( 9eff33...c2decf )
by Anthony
03:23
created

Account::setTokens()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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