1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Zemit Framework. |
4
|
|
|
* |
5
|
|
|
* (c) Zemit Team <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Zemit\Models; |
12
|
|
|
|
13
|
|
|
use Zemit\Models\Abstracts\AbstractUser; |
14
|
|
|
use Zemit\Models\Interfaces\UserInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @property File[] $Files |
18
|
|
|
* @method File[] getFiles(?array $params = null) |
19
|
|
|
* |
20
|
|
|
* @property UserGroup[] $GroupNode |
21
|
|
|
* @method UserGroup[] getGroupNode(?array $params = null) |
22
|
|
|
* |
23
|
|
|
* @property Group[] $Groups |
24
|
|
|
* @method Group[] getGroups(?array $params = null) |
25
|
|
|
* |
26
|
|
|
* @property UserRole[] $RoleNode |
27
|
|
|
* @method UserRole[] getRoleNode(?array $params = null) |
28
|
|
|
* |
29
|
|
|
* @property Role[] $Roles |
30
|
|
|
* @method Role[] getRoles(?array $params = null) |
31
|
|
|
* |
32
|
|
|
* @property UserType[] $TypeNode |
33
|
|
|
* @method UserType[] getTypeNode(?array $params = null) |
34
|
|
|
* |
35
|
|
|
* @property Type[] $Types |
36
|
|
|
* @method Type[] getTypes(?array $params = null) |
37
|
|
|
* |
38
|
|
|
* @property UserFeature[] $FeatureNode |
39
|
|
|
* @method UserFeature[] getFeatureNode(?array $params = null) |
40
|
|
|
* |
41
|
|
|
* @property Feature[] $Features |
42
|
|
|
* @method Feature[] getFeatures(?array $params = null) |
43
|
|
|
*/ |
44
|
|
|
class User extends AbstractUser implements UserInterface |
45
|
|
|
{ |
46
|
|
|
protected $deleted = self::NO; |
47
|
|
|
|
48
|
2 |
|
public function initialize(): void |
49
|
|
|
{ |
50
|
2 |
|
parent::initialize(); |
51
|
|
|
|
52
|
2 |
|
$this->hasMany('id', File::Class, 'userId', ['alias' => 'Files']); |
|
|
|
|
53
|
|
|
|
54
|
2 |
|
$this->hasMany('id', UserGroup::class, 'userId', ['alias' => 'GroupNodes']); |
55
|
2 |
|
$this->hasManyToMany( |
56
|
2 |
|
'id', |
57
|
2 |
|
UserGroup::Class, |
|
|
|
|
58
|
2 |
|
'userId', |
59
|
2 |
|
'groupId', |
60
|
2 |
|
Group::class, |
61
|
2 |
|
'id', |
62
|
2 |
|
['alias' => 'Groups'] |
63
|
2 |
|
); |
64
|
|
|
|
65
|
2 |
|
$this->hasMany('id', UserRole::class, 'userId', ['alias' => 'RoleNodes']); |
66
|
2 |
|
$this->hasManyToMany( |
67
|
2 |
|
'id', |
68
|
2 |
|
UserRole::Class, |
|
|
|
|
69
|
2 |
|
'userId', |
70
|
2 |
|
'roleId', |
71
|
2 |
|
Role::class, |
72
|
2 |
|
'id', |
73
|
2 |
|
['alias' => 'Roles'] |
74
|
2 |
|
); |
75
|
|
|
|
76
|
2 |
|
$this->hasMany('id', UserType::class, 'userId', ['alias' => 'TypeNodes']); |
77
|
2 |
|
$this->hasManyToMany( |
78
|
2 |
|
'id', |
79
|
2 |
|
UserType::Class, |
|
|
|
|
80
|
2 |
|
'userId', |
81
|
2 |
|
'typeId', |
82
|
2 |
|
Type::class, |
83
|
2 |
|
'id', |
84
|
2 |
|
['alias' => 'Types'] |
85
|
2 |
|
); |
86
|
|
|
|
87
|
2 |
|
$this->hasMany('id', UserFeature::class, 'userId', ['alias' => 'FeatureNodes']); |
88
|
2 |
|
$this->hasManyToMany( |
89
|
2 |
|
'id', |
90
|
2 |
|
UserFeature::Class, |
|
|
|
|
91
|
2 |
|
'userId', |
92
|
2 |
|
'featureId', |
93
|
2 |
|
Feature::class, |
94
|
2 |
|
'id', |
95
|
2 |
|
['alias' => 'Features'] |
96
|
2 |
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
2 |
|
public function validation(): bool |
100
|
|
|
{ |
101
|
2 |
|
$validator = $this->genericValidation(); |
102
|
|
|
|
103
|
2 |
|
$this->addEmailValidation($validator, 'email', false); |
104
|
|
|
|
105
|
2 |
|
return $this->validate($validator); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param string|null $password |
110
|
|
|
* |
111
|
|
|
* @return bool If the hash is valid or not |
112
|
|
|
*/ |
113
|
|
|
public function checkPassword(string $password = null): bool |
114
|
|
|
{ |
115
|
|
|
return $password && $this->checkHash($this->getPassword(), $password); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|