|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CakeCMS Community |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the of the simple cms based on CakePHP 3. |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Community |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
|
12
|
|
|
* @link https://github.com/CakeCMS/Community". |
|
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Community\Model\Entity; |
|
17
|
|
|
|
|
18
|
|
|
use Cake\I18n\FrozenTime; |
|
19
|
|
|
use Core\ORM\Entity\Entity; |
|
20
|
|
|
use Cake\Auth\DefaultPasswordHasher; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class User |
|
24
|
|
|
* |
|
25
|
|
|
* @package Community\Model\Entity |
|
26
|
|
|
* |
|
27
|
|
|
* @property int $id |
|
28
|
|
|
* @property int $group_id |
|
29
|
|
|
* @property Group $group |
|
30
|
|
|
* @property string $login |
|
31
|
|
|
* @property string $name |
|
32
|
|
|
* @property string $slug |
|
33
|
|
|
* @property string $email |
|
34
|
|
|
* @property string $password |
|
35
|
|
|
* @property string $token |
|
36
|
|
|
* @property bool $status |
|
37
|
|
|
* @property FrozenTime $last_login |
|
38
|
|
|
* @property FrozenTime $last_action |
|
39
|
|
|
* @property FrozenTime $modified |
|
40
|
|
|
* @property FrozenTime $created |
|
41
|
|
|
* @property string activation_url Virtual field. |
|
42
|
|
|
*/ |
|
43
|
|
|
class User extends Entity |
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* List of computed or virtual fields that **should** be included in JSON or array |
|
48
|
|
|
* representations of this Entity. If a field is present in both _hidden and _virtual |
|
49
|
|
|
* the field will **not** be in the array/json versions of the entity. |
|
50
|
|
|
* |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $_virtual = [ |
|
54
|
|
|
'activation_url' |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Set virtual field activation_url. |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function _getActivationUrl() |
|
63
|
|
|
{ |
|
64
|
|
|
return '/activation/user/1'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Setup password. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $password |
|
71
|
|
|
* @return null|string |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function _setPassword($password) |
|
74
|
|
|
{ |
|
75
|
|
|
if ($password !== null) { |
|
76
|
|
|
return (new DefaultPasswordHasher())->hash($password); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return null; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|