1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_auth_sources\Sources\Mapper\Database; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_accounts\AccountsException; |
7
|
|
|
use kalanis\kw_accounts\Interfaces\IUserCert; |
8
|
|
|
use kalanis\kw_accounts\Interfaces\IProcessClasses; |
9
|
|
|
use kalanis\kw_mapper\Interfaces\IEntryType; |
10
|
|
|
use kalanis\kw_mapper\MapperException; |
11
|
|
|
use kalanis\kw_mapper\Records\ASimpleRecord; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class UsersRecord |
16
|
|
|
* @package kalanis\kw_auth_sources\Sources\Mapper\Database |
17
|
|
|
* @property string $id |
18
|
|
|
* @property string $login |
19
|
|
|
* @property string $pass |
20
|
|
|
* @property string $groupId |
21
|
|
|
* @property string $display |
22
|
|
|
* @property string $cert |
23
|
|
|
* @property string $salt |
24
|
|
|
* @property array<string|int, string|int|float|bool> $extra |
25
|
|
|
* @property GroupsRecord[] $groups |
26
|
|
|
* @codeCoverageIgnore remote source |
27
|
|
|
* Mainly seen as example, not working thing due necessity of knowing database structure |
28
|
|
|
*/ |
29
|
|
|
class UsersRecord extends ASimpleRecord implements IUserCert |
30
|
|
|
{ |
31
|
1 |
|
public function addEntries(): void |
32
|
|
|
{ |
33
|
1 |
|
$this->addEntry('id', IEntryType::TYPE_STRING, 2048); |
34
|
1 |
|
$this->addEntry('login', IEntryType::TYPE_STRING, 512); |
35
|
1 |
|
$this->addEntry('pass', IEntryType::TYPE_STRING, 512); |
36
|
1 |
|
$this->addEntry('groupId', IEntryType::TYPE_STRING, 512); |
37
|
1 |
|
$this->addEntry('display', IEntryType::TYPE_STRING, 512); |
38
|
1 |
|
$this->addEntry('cert', IEntryType::TYPE_STRING, 8192); |
39
|
1 |
|
$this->addEntry('salt', IEntryType::TYPE_STRING, 1024); |
40
|
1 |
|
$this->addEntry('extra', IEntryType::TYPE_ARRAY, []); |
41
|
1 |
|
$this->addEntry('groups', IEntryType::TYPE_ARRAY, []); |
42
|
1 |
|
$this->setMapper(UsersMapper::class); |
43
|
1 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string|null $authId |
47
|
|
|
* @param string|null $authName |
48
|
|
|
* @param string|null $authGroup |
49
|
|
|
* @param int|null $authClass |
50
|
|
|
* @param int|null $authStatus |
51
|
|
|
* @param string|null $displayName |
52
|
|
|
* @param string|null $dir |
53
|
|
|
* @param array<string|int, string|int|float|bool>|null $extra |
54
|
|
|
* @throws AccountsException |
55
|
|
|
* @throws MapperException |
56
|
|
|
*/ |
57
|
|
|
public function setUserData(?string $authId, ?string $authName, ?string $authGroup, ?int $authClass, ?int $authStatus, ?string $displayName, ?string $dir, ?array $extra = []): void |
58
|
|
|
{ |
59
|
|
|
if (empty($authId)) { |
60
|
|
|
throw new AccountsException('No user ID'); |
61
|
|
|
} |
62
|
|
|
$this->id = $authId; |
63
|
|
|
$this->load(); |
64
|
|
|
$this->login = $authName ?? $this->login; |
65
|
|
|
$this->groupId = $authGroup ?? $this->groupId; |
66
|
|
|
$this->display = $displayName ?? $this->display; |
67
|
|
|
$this->extra = !is_null($extra) ? array_merge($this->extra, $extra) : $this->extra; |
|
|
|
|
68
|
|
|
$this->save(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string|null $key |
73
|
|
|
* @param string|null $salt |
74
|
|
|
* @throws MapperException |
75
|
|
|
*/ |
76
|
|
|
public function updateCertInfo(?string $key, ?string $salt): void |
77
|
|
|
{ |
78
|
|
|
$this->load(); |
79
|
|
|
$this->cert = $key ?? $this->cert; |
80
|
|
|
$this->salt = $salt ?? $this->salt; |
81
|
|
|
$this->save(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getAuthId(): string |
85
|
|
|
{ |
86
|
|
|
return strval($this->id); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getAuthName(): string |
90
|
|
|
{ |
91
|
|
|
return strval($this->login); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getGroup(): string |
95
|
|
|
{ |
96
|
|
|
return strval($this->groupId); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getClass(): int |
100
|
|
|
{ |
101
|
|
|
return IProcessClasses::CLASS_USER; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getStatus(): int |
105
|
|
|
{ |
106
|
|
|
return static::USER_STATUS_ENABLED; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getDisplayName(): string |
110
|
|
|
{ |
111
|
|
|
return strval($this->display); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getDir(): string |
115
|
|
|
{ |
116
|
|
|
return '/'; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getExtra(): array |
120
|
|
|
{ |
121
|
|
|
return (array) $this->extra; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getSalt(): string |
125
|
|
|
{ |
126
|
|
|
return strval($this->salt); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function getPubKey(): string |
130
|
|
|
{ |
131
|
|
|
return strval($this->cert); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|