-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevcenter.model.php
229 lines (199 loc) · 5.9 KB
/
devcenter.model.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
<?php
use League\OAuth2\Server\Entities\ClientEntityInterface;
use Monoless\Xe\OAuth2\Server\Repositories\AccessTokenRepository;
use Monoless\Xe\OAuth2\Server\Repositories\ClientRepository;
use Monoless\Xe\OAuth2\Server\Repositories\GrantAppRepository;
use Monoless\Xe\OAuth2\Server\Repositories\RefreshTokenRepository;
use Monoless\Xe\OAuth2\Server\Entities\ClientEntity;
use Monoless\Xe\OAuth2\Server\Entities\PageContainerEntity;
class devcenterModel extends devcenter
{
const MODULE_NAME = 'devcenter';
/**
* @var ClientRepository
*/
private $clientRepository;
/**
* @var GrantAppRepository
*/
private $grantAppRepository;
/**
* @var AccessTokenRepository
*/
private $accessTokenRepository;
/**
* @var RefreshTokenRepository
*/
private $refreshTokenRepository;
private static $keys = null;
private static $config = null;
public function __construct($error = 0, $message = 'success')
{
parent::__construct($error, $message);
$this->clientRepository = new ClientRepository();
$this->grantAppRepository = new GrantAppRepository();
$this->accessTokenRepository = new AccessTokenRepository();
$this->refreshTokenRepository = new RefreshTokenRepository();
}
/**
* @return stdClass|null
*/
public function getConfig()
{
if (null == self::$config) {
$oModuleModel = getModel('module');
$config = $oModuleModel->getModuleConfig(self::MODULE_NAME);
if (!$config) {
$config = new stdClass();
}
self::$config = $config;
}
return self::$config;
}
public function saveConfig(\stdClass $config)
{
/**
* @var \moduleController $controller
*/
$controller = getController('module');
$controller->insertModuleConfig(self::MODULE_NAME, $config);
}
/**
* @return array|null
*/
public function getKeys()
{
if (null == self::$keys) {
$path = './files/devcenter/keys.php';
if (\FileHandler::exists($path)) {
$raw = explode("\n", file_get_contents($path));
if (is_array($raw) && 2 <= count($raw)) {
array_shift($raw);
self::$keys = unserialize(implode("\n", $raw));
}
}
}
return self::$keys;
}
public function getSitemap()
{
$path = './files/devcenter/sitemap.json';
if (\FileHandler::exists($path)) {
if (time() > filemtime($path) + 60) {
return null;
}
return file_get_contents($path);
}
return null;
}
public function setSitemap($json)
{
$path = './files/devcenter/sitemap.json';
file_put_contents($path, $json);
}
/**
* @param ClientEntity $clientEntity
* @return boolean
*/
public function createApp(ClientEntity $clientEntity)
{
return $this->clientRepository->persistNewClient($clientEntity);
}
/**
* @param ClientEntity $clientEntity
* @return boolean
*/
public function modifyApp(ClientEntity $clientEntity)
{
return $this->clientRepository->persistClient($clientEntity);
}
/**
* @param ClientEntity $clientEntity
* @return boolean
*/
public function deleteApp(ClientEntity $clientEntity)
{
return $this->clientRepository->removeClient($clientEntity);
}
/**
* @param ClientEntity $clientEntity
* @param integer $memberSrl
* @return boolean
*/
public function revokeApp(ClientEntity $clientEntity, $memberSrl)
{
try {
$this->grantAppRepository->revokeGrantApp($clientEntity->getIdentifier(), $memberSrl);
$this->refreshTokenRepository->revokeRefreshTokenByUniqueAppSrlAndMemberSrl(
$clientEntity->getIdentifier(), $memberSrl);
$this->accessTokenRepository->revokeAccessTokenByUniqueAppSrlAndMemberSrl(
$clientEntity->getIdentifier(), $memberSrl);
} catch (\Exception $e) {
return false;
}
return true;
}
/**
* @param string $name
* @return boolean
*/
public function isAppExistByName($name)
{
return $this->clientRepository->isAppExistByName($name);
}
/**
* @param string $clientIdentifier
* @return ClientEntityInterface|ClientEntity
*/
public function getAppByClientId($clientIdentifier)
{
return $this->clientRepository->getClientEntity(
$clientIdentifier,
null,
null,
false);
}
/**
* @param integer $listCount
* @param integer $pageCount
* @param integer $page
* @return PageContainerEntity
*/
public function getApps($listCount = 20, $pageCount = 10, $page = 1)
{
return $this->clientRepository->getApps(
$listCount,
$pageCount,
$page);
}
/**
* @param integer $memberSrl
* @param integer $listCount
* @param integer $pageCount
* @param integer $page
* @return PageContainerEntity
*/
public function getAppsByMemberSrl($memberSrl, $listCount = 20, $pageCount = 10, $page = 1)
{
return $this->clientRepository->getAppsByMemberSrl(
$memberSrl,
$listCount,
$pageCount,
$page);
}
/**
* @param integer $memberSrl
* @param integer $listCount
* @param integer $pageCount
* @param integer $page
* @return PageContainerEntity
*/
public function getGrantAppsByMemberSrl($memberSrl, $listCount = 20, $pageCount = 10, $page = 1)
{
return $this->grantAppRepository->getGrantAppsByMemberSrl(
$memberSrl,
$listCount,
$pageCount,
$page);
}
}