This repository has been archived by the owner on Apr 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
User.php
346 lines (310 loc) · 5.88 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
class Default_Model_User extends Issues_Model_Abstract implements Zend_Acl_Resource_Interface
{
/**
* User ID
*
* @var int
*/
protected $_userId;
/**
* Username
*
* @var string
*/
protected $_username;
/**
* Password
*
* @var string
*/
protected $_password;
/**
* Salt
*
* @var string
*/
protected $_salt;
/**
* Role
*
* @var Default_Model_Role
*/
protected $_roles;
/**
* Last login date/time
*
* @var DateTime
*/
protected $_lastLogin;
/**
* Last IP they logged in with
*
* @var string
*/
protected $_lastIp;
/**
* Registration date/time
*
* @var DateTime
*/
protected $_registerTime;
/**
* IP address they registered with
*
* @var string
*/
protected $_registerIp;
/**
* Array of settings (key => value)
*
* @array
*/
protected $_settings;
/**
* Get userId.
*
* @return userId
*/
public function getUserId()
{
return $this->_userId;
}
/**
* Set userId.
*
* @param $userId the value to be set
*/
public function setUserId($userId)
{
$this->_userId = (int) $userId;
return $this;
}
/**
* Get username.
*
* @return username
*/
public function getUsername()
{
return $this->_username;
}
/**
* Set username.
*
* @param $username the value to be set
*/
public function setUsername($username)
{
$this->_username = $username;
return $this;
}
/**
* Get password.
*
* @return password
*/
public function getPassword()
{
return $this->_password;
}
/**
* Set password.
*
* @param $password the value to be set
*/
public function setPassword($password)
{
$this->_password = $password;
return $this;
}
/**
* Get salt.
*
* @return salt
*/
public function getSalt()
{
return $this->_salt;
}
/**
* Set salt.
*
* @param $salt the value to be set
*/
public function setSalt($salt)
{
$this->_salt = $salt;
return $this;
}
/**
* Add a role to this user
*
* @param int|Default_Model_Role $role
*/
public function addRole($role)
{
$role = Zend_Registry::get('Default_DiContainer')->getRoleService()->getRoleDetect($role);
$this->_roles[$role->getRoleId()] = $role;
return $this;
}
/**
* hasRole
*
* @param Default_Model_Role|int|string $role
* @return void
*/
public function hasRole($role)
{
$role = Zend_Registry::get('Default_DiContainer')->getRoleService()->getRoleDetect($role);
foreach ($this->_roles as $r) {
if ($role->getName() === $r->getName()) {
return true;
}
}
return false;
}
/**
* Get all roles.
*
* @return array
*/
public function getRoles()
{
return $this->_roles;
}
/**
* Set role.
*
* @param array $roles
*/
public function setRoles(array $roles)
{
$this->_roles = Zend_Registry::get('Default_DiContainer')->getRoleService()->getRoleDetect($roles);
return $this;
}
/**
* Get lastLogin.
*
* @return lastLogin
*/
public function getLastLogin()
{
return $this->_adjustedDateTime($this->_lastLogin);
}
/**
* Set lastLogin.
*
* @param $lastLogin the value to be set
*/
public function setLastLogin($lastLogin)
{
$this->_lastLogin = new DateTime($lastLogin);
}
/**
* Get lastIp.
*
* @return lastIp
*/
public function getLastIp()
{
return $this->_lastIp;
}
/**
* Set lastIp.
*
* @param $lastIp the value to be set
*/
public function setLastIp($lastIp)
{
$this->_lastIp = $lastIp;
}
/**
* Get registerTime.
*
* @return registerTime
*/
public function getRegisterTime()
{
return $this->_adjustedDateTime($this->_registerTime);
}
/**
* Set registerTime.
*
* @param $registerTime the value to be set
*/
public function setRegisterTime($registerTime)
{
$this->_registerTime = new DateTime($registerTime);
}
/**
* Get registerIp.
*
* @return registerIp
*/
public function getRegisterIp()
{
return $this->_registerIp;
}
/**
* Set registerIp.
*
* @param $registerIp the value to be set
*/
public function setRegisterIp($registerIp)
{
$this->_registerIp = $registerIp;
}
/**
* Get settings.
*
* @return settings
*/
public function getSetting($key)
{
if (isset($this->_settings[$key])) {
return $this->_settings[$key];
} else {
return false;
}
}
/**
* Set settings.
*
* @param $key the setting to set
* @param $value the value to set
*/
public function setSetting($key, $value)
{
$this->_settings[$key] = $value;
return $this;
}
/**
* Get settings.
*
* @return settings
*/
public function getSettings()
{
return $this->_settings;
}
/**
* Set settings.
*
* @param $settings the value to be set
*/
public function setSettings($settings)
{
$this->_settings = $settings;
return $this;
}
/**
* getResourceId
*
* @return string
*/
public function getResourceId()
{
return 'user-' . $this->getUserId();
}
}