|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Majora\Component\OAuth\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Majora\Component\OAuth\Model\AccountInterface; |
|
6
|
|
|
use Majora\Framework\Model\CollectionableInterface; |
|
7
|
|
|
use Majora\Framework\Model\CollectionableTrait; |
|
8
|
|
|
use Majora\Framework\Normalizer\Model\NormalizableTrait; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Basic implementation on AccountInterface. |
|
12
|
|
|
*/ |
|
13
|
|
|
class Account implements AccountInterface, CollectionableInterface |
|
14
|
|
|
{ |
|
15
|
|
|
use CollectionableTrait, NormalizableTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var int |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $id; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $ownerId; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $username; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $password; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $salt; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $roles; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $applications; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @see NormalizableInterface::getScope() |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function getScopes() |
|
56
|
|
|
{ |
|
57
|
|
|
return array( |
|
58
|
|
|
'id' => 'id', |
|
59
|
|
|
'default' => array('id', 'owner_id', 'username'), |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Construct. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $rand |
|
67
|
|
|
*/ |
|
68
|
4 |
|
public function __construct($rand = 'm@J0raOaUth') |
|
69
|
|
|
{ |
|
70
|
4 |
|
$this->salt = base_convert(sha1(uniqid(mt_rand(), true).$rand), 16, 36); |
|
71
|
4 |
|
$this->roles = array(); |
|
72
|
4 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return int |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getId() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->id; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @see AccountInterface::getOwnerId() |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getOwnerId() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->ownerId; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Define Account ownerId. |
|
92
|
|
|
* |
|
93
|
|
|
* @param int $ownerId |
|
94
|
|
|
* |
|
95
|
|
|
* @return self |
|
96
|
|
|
*/ |
|
97
|
|
|
public function setOwnerId($ownerId) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->ownerId = $ownerId; |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @see UserInterface::getUsername() |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getUsername() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->username; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* define Account username. |
|
114
|
|
|
* |
|
115
|
|
|
* @param string $username |
|
116
|
|
|
* |
|
117
|
|
|
* @return self |
|
118
|
|
|
*/ |
|
119
|
|
|
public function setUsername($username) |
|
120
|
|
|
{ |
|
121
|
|
|
$this->username = $username; |
|
122
|
|
|
|
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @see UserInterface::getPassword() |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getPassword() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->password; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Define Account password. |
|
136
|
|
|
* |
|
137
|
|
|
* @param string $password |
|
138
|
|
|
* |
|
139
|
|
|
* @return self |
|
140
|
|
|
*/ |
|
141
|
|
|
public function setPassword($password) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->password = $password; |
|
144
|
|
|
|
|
145
|
|
|
return $this; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @see UserInterface::getSalt() |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getSalt() |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->salt; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @see UserInterface::getRoles() |
|
158
|
|
|
* |
|
159
|
|
|
* @codeCoverageIgnore |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getRoles() |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->roles; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @see UserInterface::eraseCredentials() |
|
168
|
|
|
* |
|
169
|
|
|
* @codeCoverageIgnore |
|
170
|
|
|
*/ |
|
171
|
|
|
public function eraseCredentials() |
|
172
|
|
|
{ |
|
173
|
|
|
return; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return array |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getApplications() |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->applications; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param array $applications |
|
186
|
|
|
* |
|
187
|
|
|
* @return self |
|
188
|
|
|
*/ |
|
189
|
|
|
public function setApplications($applications) |
|
190
|
|
|
{ |
|
191
|
|
|
$this->applications = $applications; |
|
192
|
|
|
|
|
193
|
|
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|