1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @ORM\Entity |
10
|
|
|
* @ORM\Table(name="users") |
11
|
|
|
*/ |
12
|
|
|
class User implements \Serializable, UserInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var int |
16
|
|
|
* @ORM\Id |
17
|
|
|
* @ORM\GeneratedValue |
18
|
|
|
* @ORM\Column(type="integer") |
19
|
|
|
*/ |
20
|
|
|
protected $id; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var int |
24
|
|
|
* @ORM\Column(type="integer", unique=true) |
25
|
|
|
*/ |
26
|
|
|
protected $remote_id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
* @ORM\Column(type="string") |
31
|
|
|
*/ |
32
|
|
|
protected $username; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
* @ORM\Column(type="text") |
37
|
|
|
*/ |
38
|
|
|
protected $token_data; |
39
|
|
|
|
40
|
|
|
protected $password = ''; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return int The ID |
44
|
|
|
*/ |
45
|
|
|
public function getId(): int |
46
|
|
|
{ |
47
|
|
|
return $this->id; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return int The ID on the OAuth server |
52
|
|
|
*/ |
53
|
|
|
public function getRemoteId(): int |
54
|
|
|
{ |
55
|
|
|
return $this->remote_id; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param int $remote_id The ID on the OAuth server |
60
|
|
|
* |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
|
|
public function setRemoteId(int $remote_id): self |
64
|
|
|
{ |
65
|
|
|
$this->remote_id = $remote_id; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function getUsername(): string |
74
|
|
|
{ |
75
|
|
|
return $this->username; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $username The username |
80
|
|
|
* |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
|
public function setUsername(string $username): self |
84
|
|
|
{ |
85
|
|
|
$this->username = $username; |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string The token |
92
|
|
|
*/ |
93
|
|
|
public function getTokenData(): string |
94
|
|
|
{ |
95
|
|
|
return $this->token_data; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $token_data The token |
100
|
|
|
* |
101
|
|
|
* @return $this |
102
|
|
|
*/ |
103
|
|
|
public function setTokenData(string $token_data): self |
104
|
|
|
{ |
105
|
|
|
$this->token_data = $token_data; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
public function getPassword() |
114
|
|
|
{ |
115
|
|
|
return ''; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function getSalt(): ?string |
122
|
|
|
{ |
123
|
|
|
// you *may* need a real salt depending on your encoder |
124
|
|
|
// see section on salt below |
125
|
|
|
return null; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritdoc} |
130
|
|
|
*/ |
131
|
|
|
public function getRoles(): array |
132
|
|
|
{ |
133
|
|
|
return ['ROLE_USER', 'ROLE_OAUTH_USER']; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
|
|
public function eraseCredentials() |
140
|
|
|
{ |
141
|
|
|
// Do nothing |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* {@inheritdoc} |
146
|
|
|
*/ |
147
|
|
|
public function serialize(): string |
148
|
|
|
{ |
149
|
|
|
return serialize([ |
150
|
|
|
$this->id, |
151
|
|
|
$this->username, |
152
|
|
|
$this->password, |
153
|
|
|
// see section on salt below |
154
|
|
|
// $this->salt, |
155
|
|
|
]); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* {@inheritdoc} |
160
|
|
|
*/ |
161
|
|
|
public function unserialize($serialized): void |
162
|
|
|
{ |
163
|
|
|
list( |
164
|
|
|
$this->id, |
165
|
|
|
$this->username, |
166
|
|
|
$this->password, |
167
|
|
|
// see section on salt below |
168
|
|
|
// $this->salt |
169
|
|
|
) = unserialize($serialized); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|