| 1 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
use Laminas\ModuleManager\ModuleEvent;
|
|
|
8 |
use Laminas\ModuleManager\ModuleManager;
|
|
|
9 |
use Laminas\Mvc\MvcEvent;
|
|
|
10 |
use Laminas\Config\Reader\Ini;
|
|
|
11 |
use Laminas\Permissions\Acl\Acl;
|
|
|
12 |
use Laminas\Permissions\Acl\Role\GenericRole;
|
|
|
13 |
use LeadersLinked\Plugin\CurrentUserPlugin;
|
|
|
14 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
15 |
use LeadersLinked\Authentication\AuthTokenAdapter;
|
|
|
16 |
use Laminas\Authentication\AuthenticationService;
|
|
|
17 |
use Laminas\Permissions\Acl\Resource\GenericResource;
|
|
|
18 |
use LeadersLinked\Model\UserType;
|
|
|
19 |
use LeadersLinked\Plugin\CurrentNetworkPlugin;
|
|
|
20 |
use LeadersLinked\Model\Network;
|
|
|
21 |
use LeadersLinked\Model\User;
|
|
|
22 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
23 |
use LeadersLinked\Model\CompanyUser;
|
|
|
24 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
25 |
use LeadersLinked\Mapper\CompanyServiceMapper;
|
|
|
26 |
use LeadersLinked\Model\Service;
|
|
|
27 |
|
|
|
28 |
use LeadersLinked\Library\Functions;
|
|
|
29 |
use LeadersLinked\Mapper\DailyPulseMapper;
|
|
|
30 |
use LeadersLinked\Model\DailyPulse;
|
|
|
31 |
use LeadersLinked\Mapper\OrganizationPositionMapper;
|
|
|
32 |
use LeadersLinked\Mapper\KnowledgeAreaCategoryJobDescriptionMapper;
|
|
|
33 |
use LeadersLinked\Mapper\MyCoachCategoryJobDescriptionMapper;
|
|
|
34 |
use LeadersLinked\Mapper\KnowledgeAreaCategoryUserMapper;
|
|
|
35 |
use LeadersLinked\Mapper\MyCoachCategoryUserMapper;
|
| 23 |
efrain |
36 |
use Firebase\JWT\JWT;
|
|
|
37 |
use Firebase\JWT\Key;
|
|
|
38 |
use LeadersLinked\Mapper\JwtTokenMapper;
|
|
|
39 |
use LeadersLinked\Authentication\AuthUserIdAdapter;
|
| 95 |
efrain |
40 |
use LeadersLinked\Model\JwtToken;
|
| 154 |
efrain |
41 |
use Laminas\Http\Response;
|
| 1 |
efrain |
42 |
|
|
|
43 |
class Module
|
| 302 |
www |
44 |
|
| 1 |
efrain |
45 |
{
|
|
|
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @var Acl
|
|
|
49 |
*/
|
|
|
50 |
private $acl;
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
*
|
|
|
54 |
* @var AdapterInterface
|
|
|
55 |
*/
|
|
|
56 |
private $adapter;
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
*
|
|
|
60 |
* @var CurrentUserPlugin
|
|
|
61 |
*/
|
|
|
62 |
private $currentUserPlugin;
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
*
|
|
|
66 |
* @var CurrentNetworkPlugin
|
|
|
67 |
*/
|
|
|
68 |
private $currentNetworkPlugin;
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
*
|
|
|
72 |
* @var array
|
|
|
73 |
*/
|
|
|
74 |
private $routesAuthorized = [];
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
*
|
|
|
78 |
* @var boolean
|
|
|
79 |
*/
|
| 23 |
efrain |
80 |
private $authByOTP = false;
|
| 1 |
efrain |
81 |
|
| 23 |
efrain |
82 |
/**
|
|
|
83 |
*
|
|
|
84 |
* @var boolean
|
|
|
85 |
*/
|
|
|
86 |
private $authByJWT = false;
|
| 1 |
efrain |
87 |
|
| 102 |
efrain |
88 |
/**
|
|
|
89 |
*
|
|
|
90 |
* @var int
|
|
|
91 |
*/
|
|
|
92 |
private $jwtID = 0;
|
| 23 |
efrain |
93 |
|
| 102 |
efrain |
94 |
|
| 1 |
efrain |
95 |
/**
|
|
|
96 |
*
|
| 95 |
efrain |
97 |
* @var JwtToken
|
|
|
98 |
*/
|
|
|
99 |
private $jwtToken;
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
*
|
| 1 |
efrain |
104 |
* @var array
|
|
|
105 |
*/
|
|
|
106 |
private $config;
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
public function init(ModuleManager $moduleManager)
|
|
|
111 |
{
|
| 195 |
efrain |
112 |
|
|
|
113 |
|
| 1 |
efrain |
114 |
$events = $moduleManager->getEventManager();
|
|
|
115 |
$events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'));
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
public function onMergeConfig(ModuleEvent $event)
|
|
|
119 |
{
|
|
|
120 |
$configListener = $event->getConfigListener();
|
|
|
121 |
$this->config = $configListener->getMergedConfig(false);
|
|
|
122 |
|
|
|
123 |
$reader = new Ini();
|
|
|
124 |
$data = $reader->fromFile('config/leaderslinked.ini');
|
|
|
125 |
|
|
|
126 |
$prefix = 'leaderslinked';
|
|
|
127 |
foreach($data as $section => $pairs)
|
|
|
128 |
{
|
|
|
129 |
foreach($pairs as $key => $value)
|
|
|
130 |
{
|
|
|
131 |
$this->config[$prefix . '.' . $section . '.' . $key] = $value;
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
$configListener->setMergedConfig($this->config);
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
public function getConfig() : array
|
|
|
139 |
{
|
|
|
140 |
return include __DIR__ . '/../config/module.config.php';
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public function onBootstrap(MvcEvent $event)
|
|
|
144 |
{
|
| 195 |
efrain |
145 |
|
| 283 |
www |
146 |
$timezone = $this->config['leaderslinked.runmode.timezone'];
|
|
|
147 |
date_default_timezone_set($timezone);
|
| 195 |
efrain |
148 |
|
|
|
149 |
|
| 164 |
efrain |
150 |
header('Access-Control-Allow-Origin: *');
|
|
|
151 |
header('Access-Control-Allow-Headers: *');
|
|
|
152 |
header('Access-Control-Allow-Method: POST, GET, HEAD, OPTIONS');
|
|
|
153 |
header('Access-Control-Max-Age: 86400');
|
|
|
154 |
|
| 86 |
efrain |
155 |
|
| 96 |
efrain |
156 |
$response = $event->getResponse();
|
|
|
157 |
Functions::addCrossSiteToResponse($response);
|
|
|
158 |
$event->setResponse($response);
|
|
|
159 |
|
| 68 |
efrain |
160 |
$serviceManager = $event->getApplication()->getServiceManager();
|
| 55 |
efrain |
161 |
|
|
|
162 |
|
| 68 |
efrain |
163 |
$eventManager = $event->getApplication()->getEventManager();
|
|
|
164 |
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, [$this,'onDispatchError'], 0);
|
|
|
165 |
$eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, [$this,'onRenderError'], 0);
|
|
|
166 |
|
| 1 |
efrain |
167 |
$adapter = $serviceManager->get('leaders-linked-db');
|
|
|
168 |
|
| 283 |
www |
169 |
/*
|
| 1 |
efrain |
170 |
$session = $serviceManager->get('leaders-linked-session');
|
|
|
171 |
$session->start();
|
| 231 |
efrain |
172 |
$session->regenerateId(true);
|
| 283 |
www |
173 |
*/
|
| 1 |
efrain |
174 |
|
|
|
175 |
$translator = $serviceManager->get('MvcTranslator');
|
|
|
176 |
$translator->addTranslationFile(
|
|
|
177 |
'phpArray',
|
|
|
178 |
__DIR__ . '/i18n/validate.php',
|
|
|
179 |
'default'
|
|
|
180 |
);
|
|
|
181 |
|
|
|
182 |
$translator->addTranslationFile(
|
|
|
183 |
'phpArray',
|
|
|
184 |
__DIR__ . '/i18n/spanish.php',
|
|
|
185 |
'default'
|
|
|
186 |
);
|
|
|
187 |
|
| 97 |
efrain |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
| 1 |
efrain |
192 |
\Laminas\Validator\AbstractValidator::setDefaultTranslator($translator);
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
$headers = $event->getRequest()->getHeaders();
|
|
|
196 |
if($headers->has('token')) {
|
|
|
197 |
$device_uuid = Functions::sanitizeFilterString($headers->get('token')->getFieldValue());
|
|
|
198 |
} else {
|
|
|
199 |
$device_uuid = '';
|
|
|
200 |
}
|
|
|
201 |
if($headers->has('secret')) {
|
|
|
202 |
$password = Functions::sanitizeFilterString($headers->get('secret')->getFieldValue());
|
|
|
203 |
} else {
|
|
|
204 |
$password = '';
|
|
|
205 |
}
|
|
|
206 |
if($headers->has('rand')) {
|
|
|
207 |
$rand = Functions::sanitizeFilterString($headers->get('rand')->getFieldValue());
|
|
|
208 |
} else {
|
|
|
209 |
$rand = 0;
|
|
|
210 |
}
|
|
|
211 |
if($headers->has('created')) {
|
|
|
212 |
$timestamp = Functions::sanitizeFilterString($headers->get('created')->getFieldValue());
|
|
|
213 |
} else {
|
|
|
214 |
$timestamp = 0;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
|
| 4 |
efrain |
218 |
|
| 283 |
www |
219 |
$this->currentNetworkPlugin = CurrentNetworkPlugin::getInstance($adapter);
|
| 1 |
efrain |
220 |
if(!$this->currentNetworkPlugin->hasNetwork()) {
|
| 43 |
efrain |
221 |
|
| 1 |
efrain |
222 |
$response = $event->getResponse();
|
| 45 |
efrain |
223 |
$code = 200;
|
|
|
224 |
$content = json_encode(['success' => false, 'data' => '200 Unauthorized - Private network - not found', 'fatal' => true]);
|
| 43 |
efrain |
225 |
$this->sendResponse($response, $code, $content);
|
|
|
226 |
|
| 1 |
efrain |
227 |
}
|
|
|
228 |
|
|
|
229 |
if($this->currentNetworkPlugin->getNetwork()->status == Network::STATUS_INACTIVE) {
|
| 43 |
efrain |
230 |
|
| 1 |
efrain |
231 |
$response = $event->getResponse();
|
| 45 |
efrain |
232 |
$code = 200;
|
|
|
233 |
$content = json_encode(['success' => false, 'data' => '200 Unauthorized - Private network - inactive', 'fatal' => true]);
|
| 43 |
efrain |
234 |
$this->sendResponse($response, $code, $content);
|
|
|
235 |
|
| 1 |
efrain |
236 |
}
|
|
|
237 |
|
| 192 |
efrain |
238 |
|
| 1 |
efrain |
239 |
|
| 192 |
efrain |
240 |
|
| 23 |
efrain |
241 |
$this->authByOTP = false;
|
| 1 |
efrain |
242 |
if($device_uuid && $password && $rand && $timestamp) {
|
| 23 |
efrain |
243 |
$this->authByOTP = true;
|
| 1 |
efrain |
244 |
|
|
|
245 |
|
|
|
246 |
$tokenAuthAdapter = new AuthTokenAdapter($adapter);
|
|
|
247 |
$tokenAuthAdapter->setData($device_uuid, $password, $timestamp, $rand);
|
|
|
248 |
|
|
|
249 |
$authService = new AuthenticationService();
|
|
|
250 |
$result = $authService->authenticate($tokenAuthAdapter);
|
|
|
251 |
if($result->getCode() != \Laminas\Authentication\Result::SUCCESS) {
|
| 43 |
efrain |
252 |
|
| 1 |
efrain |
253 |
$response = $event->getResponse();
|
| 43 |
efrain |
254 |
$code = 200;
|
|
|
255 |
$content = json_encode(['success' => false, 'data' => $result->getMessages()[0], 'fatal' => true]);
|
|
|
256 |
$this->sendResponse($response, $code, $content);
|
|
|
257 |
|
| 1 |
efrain |
258 |
}
|
|
|
259 |
|
|
|
260 |
}
|
| 23 |
efrain |
261 |
|
| 102 |
efrain |
262 |
$this->jwtID = 0;
|
| 23 |
efrain |
263 |
$this->authByJWT = false;
|
|
|
264 |
$headers = getallheaders();
|
| 34 |
efrain |
265 |
|
|
|
266 |
if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
|
| 23 |
efrain |
267 |
|
| 34 |
efrain |
268 |
$token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
|
|
|
269 |
|
|
|
270 |
|
| 23 |
efrain |
271 |
if (substr($token, 0, 6 ) == 'Bearer') {
|
| 43 |
efrain |
272 |
|
| 23 |
efrain |
273 |
|
|
|
274 |
$token = trim(substr($token, 7));
|
|
|
275 |
|
|
|
276 |
if(!empty($this->config['leaderslinked.jwt.key'])) {
|
|
|
277 |
$key = $this->config['leaderslinked.jwt.key'];
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
try {
|
|
|
281 |
$payload = JWT::decode($token, new Key($key, 'HS256'));
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
|
| 43 |
efrain |
285 |
|
| 23 |
efrain |
286 |
$response = $event->getResponse();
|
| 45 |
efrain |
287 |
$code = 200;
|
| 43 |
efrain |
288 |
$content = json_encode(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server', 'fatal' => true]);
|
|
|
289 |
$this->sendResponse($response, $code, $content);
|
| 23 |
efrain |
290 |
|
| 43 |
efrain |
291 |
|
|
|
292 |
|
| 23 |
efrain |
293 |
}
|
|
|
294 |
|
|
|
295 |
$uuid = empty($payload->uuid) ? '' : $payload->uuid;
|
|
|
296 |
if($uuid) {
|
|
|
297 |
$jwtTokenMapper = JwtTokenMapper::getInstance($adapter);
|
| 100 |
efrain |
298 |
$jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
|
|
|
299 |
if($jwtToken) {
|
| 23 |
efrain |
300 |
|
| 102 |
efrain |
301 |
$this->jwtID = $jwtToken->id;
|
|
|
302 |
|
| 100 |
efrain |
303 |
$_SESSION['aes'] = $jwtToken->aes;
|
| 23 |
efrain |
304 |
|
| 100 |
efrain |
305 |
if($jwtToken->user_id) {
|
| 23 |
efrain |
306 |
$authByUserId = new AuthUserIdAdapter($adapter);
|
| 100 |
efrain |
307 |
$authByUserId->setData($jwtToken->user_id);
|
| 23 |
efrain |
308 |
|
|
|
309 |
$authService = new AuthenticationService();
|
|
|
310 |
$result = $authService->authenticate($authByUserId);
|
|
|
311 |
if($result->getCode() != \Laminas\Authentication\Result::SUCCESS) {
|
| 43 |
efrain |
312 |
|
| 23 |
efrain |
313 |
$response = $event->getResponse();
|
| 45 |
efrain |
314 |
$code = 200;
|
| 43 |
efrain |
315 |
$content = json_encode(['success' => false, 'data' => $result->getMessages()[0], 'fatal' => true]);
|
|
|
316 |
$this->sendResponse($response, $code, $content);
|
| 23 |
efrain |
317 |
|
|
|
318 |
}
|
| 24 |
efrain |
319 |
|
| 102 |
efrain |
320 |
|
| 23 |
efrain |
321 |
}
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
} else {
|
|
|
325 |
$response = $event->getResponse();
|
| 45 |
efrain |
326 |
$code = 200;
|
| 43 |
efrain |
327 |
$content = json_encode(['success' => false, 'data' => 'Unauthorized - JWT - Expired', 'fatal' => true]);
|
|
|
328 |
$this->sendResponse($response, $code, $content);
|
|
|
329 |
|
| 23 |
efrain |
330 |
}
|
|
|
331 |
|
|
|
332 |
}
|
|
|
333 |
} catch(\Exception $e) {
|
| 43 |
efrain |
334 |
|
| 23 |
efrain |
335 |
$response = $event->getResponse();
|
| 45 |
efrain |
336 |
$code = 200;
|
| 43 |
efrain |
337 |
$content = json_encode(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key', 'fatal' => true]);
|
|
|
338 |
$this->sendResponse($response, $code, $content);
|
|
|
339 |
|
| 23 |
efrain |
340 |
}
|
|
|
341 |
}
|
|
|
342 |
}
|
|
|
343 |
}
|
| 1 |
efrain |
344 |
|
|
|
345 |
|
|
|
346 |
|
|
|
347 |
if(empty($_SERVER['REDIRECT_URL'])) {
|
|
|
348 |
if(empty($_SERVER['REQUEST_URI'])) {
|
|
|
349 |
$routeName = '';
|
|
|
350 |
|
|
|
351 |
} else {
|
|
|
352 |
$routeName = $_SERVER['REQUEST_URI'];
|
|
|
353 |
}
|
|
|
354 |
|
|
|
355 |
} else {
|
|
|
356 |
$routeName = $_SERVER['REDIRECT_URL'];
|
|
|
357 |
|
|
|
358 |
}
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
$routeName = strtolower(trim($routeName));
|
|
|
362 |
if(strlen($routeName) > 0 && substr($routeName, 0, 1) == '/') {
|
|
|
363 |
$routeName = substr($routeName, 1);
|
|
|
364 |
}
|
|
|
365 |
|
| 283 |
www |
366 |
$this->currentUserPlugin = CurrentUserPlugin::getInstance($adapter);
|
| 192 |
efrain |
367 |
if($this->currentUserPlugin->hasIdentity()) {
|
|
|
368 |
|
| 195 |
efrain |
369 |
|
|
|
370 |
|
| 192 |
efrain |
371 |
if(User::STATUS_BANNED == $this->currentUserPlugin->getUser()->status) {
|
|
|
372 |
|
|
|
373 |
$code = 200;
|
|
|
374 |
$content = json_encode(['success' => false, 'data' => '403 Forbidden - Banned', 'fatal' => true]);
|
|
|
375 |
$this->sendResponse($response, $code, $content);
|
|
|
376 |
}
|
|
|
377 |
|
|
|
378 |
}
|
| 1 |
efrain |
379 |
|
| 23 |
efrain |
380 |
if($this->authByOTP && substr($routeName, 0, 8) == 'services') {
|
| 1 |
efrain |
381 |
$checkUserForNetwork = false;
|
|
|
382 |
} else {
|
|
|
383 |
if($this->currentUserPlugin->hasIdentity()) {
|
|
|
384 |
|
|
|
385 |
$checkUserForNetwork = true;
|
|
|
386 |
} else {
|
|
|
387 |
$checkUserForNetwork = false;
|
|
|
388 |
}
|
|
|
389 |
}
|
|
|
390 |
|
|
|
391 |
if($checkUserForNetwork) {
|
|
|
392 |
if(!$routeName || in_array($routeName, ['signout', 'signin', 'home'])) {
|
|
|
393 |
$checkUserForNetwork = false;
|
|
|
394 |
}
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
if($checkUserForNetwork) {
|
|
|
398 |
|
| 154 |
efrain |
399 |
|
| 1 |
efrain |
400 |
|
|
|
401 |
if($this->currentUserPlugin->getUser()->network_id != $this->currentNetworkPlugin->getNetworkId()) {
|
| 154 |
efrain |
402 |
|
| 1 |
efrain |
403 |
$response = $event->getResponse();
|
| 154 |
efrain |
404 |
$content = json_encode(['success' => false, 'data' => '200 Unauthorized - The user is not part of this private network', 'fatal' => true]);
|
|
|
405 |
$this->sendResponse($response, 200, $content);
|
| 1 |
efrain |
406 |
exit;
|
|
|
407 |
}
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
$this->initAcl($event);
|
| 68 |
efrain |
413 |
|
| 88 |
efrain |
414 |
|
| 1 |
efrain |
415 |
|
|
|
416 |
$sharedManager = $eventManager->getSharedManager();
|
|
|
417 |
$sharedManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, [$this, 'authPreDispatch'], 100);
|
|
|
418 |
$sharedManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, [$this, 'authPosDispatch'], -100);
|
|
|
419 |
}
|
|
|
420 |
|
|
|
421 |
public function initAcl(MvcEvent $event)
|
|
|
422 |
{
|
|
|
423 |
|
|
|
424 |
$serviceManager = $event->getApplication()->getServiceManager();
|
|
|
425 |
$adapter = $serviceManager->get('leaders-linked-db');
|
|
|
426 |
|
|
|
427 |
|
|
|
428 |
require_once (dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'acl.config.php');
|
|
|
429 |
|
|
|
430 |
|
|
|
431 |
$this->acl = new Acl();
|
|
|
432 |
$resources = getAclResources();
|
|
|
433 |
|
|
|
434 |
foreach($resources as $resourceName)
|
|
|
435 |
{
|
|
|
436 |
$this->acl->addResource(new GenericResource($resourceName));
|
|
|
437 |
}
|
|
|
438 |
|
|
|
439 |
$usertypes = getAclUsertype();
|
|
|
440 |
foreach($usertypes as $usertype => $resources)
|
|
|
441 |
{
|
|
|
442 |
$this->acl->addRole(new GenericRole($usertype));
|
|
|
443 |
foreach ($resources as $resourceName)
|
|
|
444 |
{
|
|
|
445 |
$this->acl->allow($usertype, $resourceName);
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
|
|
|
450 |
|
| 167 |
efrain |
451 |
if($this->currentUserPlugin->hasIdentity()) {
|
|
|
452 |
$user_id = $this->currentUserPlugin->getUserId();
|
|
|
453 |
|
|
|
454 |
if($this->currentUserPlugin->getUser()->is_super_user == User::IS_SUPER_USER_YES) {
|
|
|
455 |
|
|
|
456 |
|
|
|
457 |
$resources = getAclSuperAdmin();
|
|
|
458 |
foreach($resources as $resourceName)
|
|
|
459 |
{
|
|
|
460 |
$this->acl->allow(UserType::ADMIN, $resourceName);
|
|
|
461 |
}
|
| 1 |
efrain |
462 |
}
|
| 167 |
efrain |
463 |
} else {
|
|
|
464 |
$user_id = 0;
|
| 1 |
efrain |
465 |
}
|
|
|
466 |
|
|
|
467 |
$allowMyCoach = false;
|
|
|
468 |
$allowKnowledgeArea = false;
|
|
|
469 |
$allowDailyPulse = false;
|
|
|
470 |
|
|
|
471 |
|
| 167 |
efrain |
472 |
if( $user_id) {
|
|
|
473 |
$allowMicrolearning = $this->isMicroLeargningAccessGranted($adapter, $user_id);
|
| 302 |
www |
474 |
$allowHabit = $this->isHabitsAccessGranted($adapter, $user_id);
|
| 167 |
efrain |
475 |
} else {
|
|
|
476 |
$allowMicrolearning = false;
|
| 302 |
www |
477 |
$allowHabit = false;
|
| 167 |
efrain |
478 |
}
|
| 1 |
efrain |
479 |
|
| 167 |
efrain |
480 |
|
|
|
481 |
|
|
|
482 |
|
|
|
483 |
|
|
|
484 |
|
| 1 |
efrain |
485 |
$companyMapper = CompanyMapper::getInstance($adapter);
|
|
|
486 |
$company = $companyMapper->fetchDefaultForNetworkByNetworkId($this->currentNetworkPlugin->getNetwork()->id);
|
|
|
487 |
|
|
|
488 |
|
|
|
489 |
if($company) {
|
|
|
490 |
|
|
|
491 |
$companyServiceMapper = CompanyServiceMapper::getInstance($adapter);
|
|
|
492 |
$companyService = $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company->id, Service::DAILY_PULSE);
|
|
|
493 |
|
|
|
494 |
|
|
|
495 |
$companyUserMapper = CompanyUserMapper::getInstance($adapter);
|
|
|
496 |
$companyUser = $companyUserMapper->fetchOneAcceptedByCompanyIdAndUserId($company->id, $this->currentUserPlugin->getUserId());
|
|
|
497 |
|
|
|
498 |
|
|
|
499 |
|
|
|
500 |
|
|
|
501 |
if($companyService) {
|
|
|
502 |
|
|
|
503 |
$dailyPulseMapper = DailyPulseMapper::getInstance($adapter);
|
|
|
504 |
$dailyPulse = $dailyPulseMapper->fetchOneByCompanyId($company->id);
|
|
|
505 |
|
|
|
506 |
if($dailyPulse) {
|
|
|
507 |
$privacy = $dailyPulse->privacy;
|
|
|
508 |
|
|
|
509 |
} else {
|
|
|
510 |
$privacy = DailyPulse::PRIVACY_COMPANY;
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
if($privacy == DailyPulse::PRIVACY_PUBLIC) {
|
|
|
514 |
$allowDailyPulse = true;
|
|
|
515 |
} else {
|
|
|
516 |
$allowDailyPulse = !empty($companyUser);
|
|
|
517 |
}
|
|
|
518 |
|
|
|
519 |
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
$job_description_ids = [];
|
|
|
523 |
|
|
|
524 |
$organizationPositionMapper = OrganizationPositionMapper::getInstance($adapter);
|
|
|
525 |
$records = $organizationPositionMapper->fetchAllByCompanyIdAndEmployeeId($company->id, $this->currentUserPlugin->getUserId());
|
|
|
526 |
foreach($records as $record)
|
|
|
527 |
{
|
|
|
528 |
array_push($job_description_ids, $record->job_description_id);
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
|
|
|
532 |
$companyService = $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company->id, Service::KNOWLEDGE_AREA);
|
|
|
533 |
if($companyService) {
|
|
|
534 |
if($job_description_ids) {
|
|
|
535 |
|
|
|
536 |
|
|
|
537 |
$knowledgeAreaCategoryJobDescriptionMapper = KnowledgeAreaCategoryJobDescriptionMapper::getInstance($adapter);
|
|
|
538 |
$records = $knowledgeAreaCategoryJobDescriptionMapper->fetchAllByCompanyIdAndJobDescriptionIds($company->id, $job_description_ids);
|
|
|
539 |
|
|
|
540 |
if(!empty($records)) {
|
|
|
541 |
$allowKnowledgeArea = true;
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
}
|
|
|
545 |
|
|
|
546 |
if($companyUser && !$allowKnowledgeArea) {
|
|
|
547 |
$knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($adapter);
|
|
|
548 |
$records = $knowledgeAreaCategoryUserMapper->fetchAllByUserId($companyUser->user_id);
|
|
|
549 |
if(!empty($records)) {
|
|
|
550 |
$allowKnowledgeArea = true;
|
|
|
551 |
}
|
|
|
552 |
}
|
|
|
553 |
}
|
|
|
554 |
|
|
|
555 |
$companyService = $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company->id, Service::MY_COACH);
|
|
|
556 |
if($companyService) {
|
|
|
557 |
|
|
|
558 |
|
|
|
559 |
if($job_description_ids) {
|
|
|
560 |
|
|
|
561 |
|
|
|
562 |
$myCoachCategoryJobDescriptionMapper = MyCoachCategoryJobDescriptionMapper::getInstance($adapter);
|
|
|
563 |
$records = $myCoachCategoryJobDescriptionMapper->fetchAllByCompanyIdAndJobDescriptionIds($company->id, $job_description_ids);
|
|
|
564 |
|
|
|
565 |
if(!empty($records)) {
|
|
|
566 |
$allowKnowledgeArea = true;
|
|
|
567 |
}
|
|
|
568 |
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
if($companyUser && !$allowMyCoach) {
|
|
|
572 |
$myCoachCategoryUserMapper = MyCoachCategoryUserMapper::getInstance($adapter);
|
|
|
573 |
$records = $myCoachCategoryUserMapper->fetchAllByUserId($companyUser->user_id);
|
|
|
574 |
if(!empty($records)) {
|
|
|
575 |
$allowMyCoach = true;
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
|
|
|
579 |
}
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
} else {
|
|
|
583 |
$companyUser = '';
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
|
|
|
587 |
$usertype = $this->currentUserPlugin->getUserTypeId();
|
|
|
588 |
if($allowDailyPulse) {
|
|
|
589 |
$resources = getAclDailyPulse();
|
|
|
590 |
foreach($resources as $resourceName)
|
|
|
591 |
{
|
|
|
592 |
$this->acl->allow($usertype, $resourceName);
|
|
|
593 |
}
|
|
|
594 |
}
|
|
|
595 |
|
| 167 |
efrain |
596 |
if($allowMicrolearning) {
|
|
|
597 |
$resources = getAclMicrolearning();
|
|
|
598 |
foreach($resources as $resourceName)
|
|
|
599 |
{
|
|
|
600 |
$this->acl->allow($usertype, $resourceName);
|
|
|
601 |
}
|
|
|
602 |
}
|
|
|
603 |
|
| 302 |
www |
604 |
if($allowHabit) {
|
|
|
605 |
$resources = getAclHabits();
|
|
|
606 |
foreach($resources as $resourceName)
|
|
|
607 |
{
|
|
|
608 |
$this->acl->allow($usertype, $resourceName);
|
|
|
609 |
}
|
|
|
610 |
}
|
| 167 |
efrain |
611 |
|
| 302 |
www |
612 |
|
| 1 |
efrain |
613 |
if($allowKnowledgeArea) {
|
|
|
614 |
$resources = getAclKnowledgeArea();
|
|
|
615 |
foreach($resources as $resourceName)
|
|
|
616 |
{
|
|
|
617 |
$this->acl->allow($usertype, $resourceName);
|
|
|
618 |
}
|
|
|
619 |
}
|
|
|
620 |
|
|
|
621 |
if($allowMyCoach) {
|
|
|
622 |
$resources = getAclMyCoach();
|
|
|
623 |
|
|
|
624 |
|
|
|
625 |
|
|
|
626 |
foreach($resources as $resourceName)
|
|
|
627 |
{
|
|
|
628 |
$this->acl->allow($usertype, $resourceName);
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
|
|
|
634 |
|
| 302 |
www |
635 |
|
|
|
636 |
|
| 1 |
efrain |
637 |
if($this->currentNetworkPlugin->getNetwork()->default == Network::DEFAULT_YES) {
|
|
|
638 |
|
|
|
639 |
$usertypes = getAclUsertypeDefaultNetwork();
|
|
|
640 |
foreach($usertypes as $usertype => $resources)
|
|
|
641 |
{
|
|
|
642 |
|
|
|
643 |
|
|
|
644 |
|
|
|
645 |
foreach ($resources as $resourceName)
|
|
|
646 |
{
|
|
|
647 |
$this->acl->allow($usertype, $resourceName);
|
|
|
648 |
}
|
|
|
649 |
}
|
|
|
650 |
|
|
|
651 |
|
|
|
652 |
} else {
|
|
|
653 |
|
|
|
654 |
if($this->currentUserPlugin->hasIdentity()) {
|
|
|
655 |
|
|
|
656 |
|
|
|
657 |
if($company) {
|
|
|
658 |
|
|
|
659 |
|
|
|
660 |
if($companyUser) {
|
|
|
661 |
$usertype = $this->currentUserPlugin->getUserTypeId();
|
|
|
662 |
|
|
|
663 |
if($companyUser->creator == CompanyUser::CREATOR_YES) {
|
|
|
664 |
|
|
|
665 |
$resources = getAclUsertypeOtherNetworkCreator();
|
|
|
666 |
foreach($resources as $resourceName)
|
|
|
667 |
{
|
|
|
668 |
$this->acl->allow($usertype, $resourceName);
|
|
|
669 |
}
|
|
|
670 |
|
|
|
671 |
}
|
|
|
672 |
if($companyUser->creator == CompanyUser::CREATOR_NO) {
|
|
|
673 |
$resources = getAclUsertypeOtherNetworkNonCreator();
|
|
|
674 |
foreach($resources as $resourceName)
|
|
|
675 |
{
|
|
|
676 |
$this->acl->allow($usertype, $resourceName);
|
|
|
677 |
}
|
|
|
678 |
}
|
|
|
679 |
}
|
|
|
680 |
}
|
|
|
681 |
}
|
|
|
682 |
}
|
|
|
683 |
|
|
|
684 |
|
|
|
685 |
$event->getViewModel()->setVariable('acl', $this->acl);
|
| 88 |
efrain |
686 |
|
|
|
687 |
|
| 1 |
efrain |
688 |
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
public function onDispatchError(MvcEvent $event)
|
|
|
692 |
{
|
|
|
693 |
$this->processError($event);
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
public function onRenderError(MvcEvent $event)
|
|
|
697 |
{
|
|
|
698 |
$this->processError($event);
|
|
|
699 |
}
|
|
|
700 |
|
| 43 |
efrain |
701 |
/**
|
|
|
702 |
*
|
|
|
703 |
* @param \Laminas\Http\Response $response
|
|
|
704 |
* @param int $code
|
|
|
705 |
* @param string $content
|
|
|
706 |
*/
|
|
|
707 |
public function sendResponse($response, $code, $content)
|
| 1 |
efrain |
708 |
{
|
| 94 |
efrain |
709 |
|
| 43 |
efrain |
710 |
|
| 44 |
efrain |
711 |
|
| 1 |
efrain |
712 |
$headers = $response->getHeaders();
|
|
|
713 |
$headers->clearHeaders();
|
|
|
714 |
$headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
|
|
|
715 |
|
| 43 |
efrain |
716 |
Functions::addCrossSiteToResponse($response);
|
|
|
717 |
|
|
|
718 |
$response->setStatusCode($code);
|
|
|
719 |
$response->setContent($content); //json_encode($data));
|
| 1 |
efrain |
720 |
$response->send();
|
|
|
721 |
exit;
|
|
|
722 |
}
|
|
|
723 |
|
|
|
724 |
public function processError(MvcEvent $event)
|
|
|
725 |
{
|
|
|
726 |
$error = $event->getError();
|
|
|
727 |
if (!$error) {
|
|
|
728 |
return;
|
|
|
729 |
}
|
|
|
730 |
|
|
|
731 |
$response = $event->getResponse();
|
|
|
732 |
if('error-exception' == $error) {
|
| 195 |
efrain |
733 |
|
|
|
734 |
|
| 1 |
efrain |
735 |
$exception = $event->getParam('exception');
|
|
|
736 |
error_log($exception->getCode() . ' ' . $exception->getMessage());
|
|
|
737 |
error_log($exception->getTraceAsString());
|
| 43 |
efrain |
738 |
|
| 1 |
efrain |
739 |
$response = $event->getResponse();
|
| 45 |
efrain |
740 |
$code = 200;
|
| 43 |
efrain |
741 |
$content = json_encode(['success' => false, 'data' => $exception->getCode() . ' ' . $exception->getMessage(), 'fatal' => true]);
|
|
|
742 |
$this->sendResponse($response, $code, $content);
|
| 1 |
efrain |
743 |
|
|
|
744 |
} else if('error-router-no-match' == $error) {
|
| 43 |
efrain |
745 |
|
| 1 |
efrain |
746 |
$response = $event->getResponse();
|
| 43 |
efrain |
747 |
$code = 404;
|
|
|
748 |
$content = json_encode(['success' => false, 'data' => 'error-router-no-match', 'fatal' => true]);
|
|
|
749 |
$this->sendResponse($response, $code, $content);
|
| 1 |
efrain |
750 |
|
|
|
751 |
|
|
|
752 |
|
|
|
753 |
} else if(' error-controller-not-found' == $error) {
|
| 43 |
efrain |
754 |
|
| 1 |
efrain |
755 |
$response = $event->getResponse();
|
| 43 |
efrain |
756 |
$code = 404;
|
|
|
757 |
$content = json_encode(['success' => false, 'data' => 'error-controller-not-found', 'fatal' => true]);
|
|
|
758 |
$this->sendResponse($response, $code, $content);
|
| 1 |
efrain |
759 |
|
| 43 |
efrain |
760 |
|
| 1 |
efrain |
761 |
} else {
|
|
|
762 |
$response = $event->getResponse();
|
| 45 |
efrain |
763 |
$code = 200;
|
| 43 |
efrain |
764 |
$content = json_encode(['success' => false, 'data' => $error, 'fatal' => true]);
|
|
|
765 |
$this->sendResponse($response, $code, $content);
|
| 1 |
efrain |
766 |
|
| 43 |
efrain |
767 |
|
| 1 |
efrain |
768 |
}
|
|
|
769 |
|
|
|
770 |
exit;
|
|
|
771 |
|
|
|
772 |
}
|
|
|
773 |
|
|
|
774 |
|
|
|
775 |
public function authPreDispatch(MvcEvent $event)
|
|
|
776 |
{
|
|
|
777 |
|
| 195 |
efrain |
778 |
|
| 1 |
efrain |
779 |
|
|
|
780 |
|
|
|
781 |
$serviceManager = $event->getApplication()->getServiceManager();
|
|
|
782 |
$adapter = $serviceManager->get('leaders-linked-db');
|
|
|
783 |
|
|
|
784 |
$routeName = $event->getRouteMatch()->getMatchedRouteName();
|
|
|
785 |
|
|
|
786 |
|
|
|
787 |
$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? trim(strtoupper($_SERVER['REQUEST_METHOD'])) : '';
|
|
|
788 |
|
| 95 |
efrain |
789 |
if($requestMethod == 'POST') {
|
| 1 |
efrain |
790 |
|
|
|
791 |
|
| 23 |
efrain |
792 |
if($this->authByOTP && substr($routeName, 0, 8) == 'services') {
|
| 1 |
efrain |
793 |
$exclude = true;
|
|
|
794 |
} else {
|
|
|
795 |
$exclude = false;
|
|
|
796 |
|
|
|
797 |
$usertypes = getAclUsertype();
|
|
|
798 |
|
|
|
799 |
|
|
|
800 |
foreach($usertypes[UserType::GUEST] as $resourceName)
|
|
|
801 |
{
|
|
|
802 |
if($routeName == $resourceName) {
|
|
|
803 |
$exclude = true;
|
|
|
804 |
break;
|
|
|
805 |
}
|
|
|
806 |
}
|
|
|
807 |
}
|
|
|
808 |
|
| 95 |
efrain |
809 |
|
| 1 |
efrain |
810 |
if(!$exclude) {
|
| 95 |
efrain |
811 |
|
| 1 |
efrain |
812 |
$httpToken = isset($_SERVER['HTTP_X_CSRF_TOKEN']) ? $_SERVER['HTTP_X_CSRF_TOKEN'] : '';
|
|
|
813 |
|
| 100 |
efrain |
814 |
|
|
|
815 |
|
| 102 |
efrain |
816 |
if($this->jwtID) {
|
| 103 |
efrain |
817 |
|
| 95 |
efrain |
818 |
$jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
|
| 102 |
efrain |
819 |
$jwtToken = $jwtTokenMapper->fetchOne($this->jwtID);
|
| 100 |
efrain |
820 |
if($jwtToken) {
|
| 95 |
efrain |
821 |
|
| 100 |
efrain |
822 |
$sessionToken = $jwtToken->csrf;
|
|
|
823 |
//$jwtToken->csrf= '';
|
|
|
824 |
|
|
|
825 |
|
|
|
826 |
// $jwtTokenMapper->update($jwtToken);
|
|
|
827 |
} else {
|
|
|
828 |
$sessionToken = '';
|
|
|
829 |
}
|
|
|
830 |
|
| 95 |
efrain |
831 |
|
|
|
832 |
} else {
|
|
|
833 |
$sessionToken = '';
|
|
|
834 |
}
|
|
|
835 |
|
|
|
836 |
|
| 106 |
efrain |
837 |
//error_log('$this->jwtID = ' . $this->jwtID . ' $httpToken = ' . $httpToken . ' $sessionToken = ' . $sessionToken);
|
| 100 |
efrain |
838 |
|
| 283 |
www |
839 |
// if ( $httpToken != $sessionToken) {
|
|
|
840 |
// $response = $event->getResponse();
|
|
|
841 |
// $this->sendResponse($response, 200, json_encode(['success' => false, 'data' => 'Unauthorized - CSRF fail', 'fatal' => true]));
|
|
|
842 |
// }
|
| 1 |
efrain |
843 |
|
|
|
844 |
}
|
|
|
845 |
}
|
| 95 |
efrain |
846 |
|
| 1 |
efrain |
847 |
|
|
|
848 |
|
|
|
849 |
|
|
|
850 |
if($this->currentUserPlugin->hasIdentity()) {
|
|
|
851 |
$user = $this->currentUserPlugin->getUser();
|
| 167 |
efrain |
852 |
$user_id = $user->id;
|
| 1 |
efrain |
853 |
$userTypeId = $user->usertype_id;
|
|
|
854 |
|
|
|
855 |
|
|
|
856 |
} else {
|
|
|
857 |
|
|
|
858 |
$userTypeId = UserType::GUEST;
|
| 167 |
efrain |
859 |
$user_id = 0;
|
| 1 |
efrain |
860 |
}
|
|
|
861 |
|
| 167 |
efrain |
862 |
|
| 1 |
efrain |
863 |
|
| 167 |
efrain |
864 |
|
|
|
865 |
|
|
|
866 |
|
|
|
867 |
|
| 1 |
efrain |
868 |
if($this->acl->isAllowed($userTypeId, $routeName)) {
|
|
|
869 |
$user = $this->currentUserPlugin->getUser();
|
|
|
870 |
|
|
|
871 |
|
|
|
872 |
if($user) {
|
|
|
873 |
|
|
|
874 |
$updateLastActivity = true;
|
|
|
875 |
if ('chat' == substr($routeName, 0, 4)) {
|
|
|
876 |
$updateLastActivity = false;
|
|
|
877 |
}
|
|
|
878 |
if ('inmail' == substr($routeName, 0, 6)) {
|
|
|
879 |
$updateLastActivity = false;
|
|
|
880 |
}
|
|
|
881 |
if ('check-session' == $routeName) {
|
|
|
882 |
$updateLastActivity = false;
|
|
|
883 |
}
|
|
|
884 |
|
|
|
885 |
|
|
|
886 |
if($updateLastActivity) {
|
|
|
887 |
$userMapper = UserMapper::getInstance($adapter);
|
|
|
888 |
$userMapper->updateLastActivity($user->id);
|
|
|
889 |
}
|
|
|
890 |
}
|
|
|
891 |
|
|
|
892 |
|
|
|
893 |
|
|
|
894 |
} else {
|
|
|
895 |
$response = $event->getResponse();
|
| 54 |
efrain |
896 |
|
| 45 |
efrain |
897 |
$response->setStatusCode(200);
|
| 106 |
efrain |
898 |
$response->setContent(json_encode(['success' => false, 'data' => 'Unauthorized - Does not have permission', 'fatal' => true]));
|
| 1 |
efrain |
899 |
$response->send();
|
|
|
900 |
exit;
|
|
|
901 |
|
|
|
902 |
|
|
|
903 |
|
|
|
904 |
}
|
| 90 |
efrain |
905 |
|
| 91 |
efrain |
906 |
|
| 90 |
efrain |
907 |
|
| 1 |
efrain |
908 |
|
|
|
909 |
|
|
|
910 |
}
|
|
|
911 |
|
|
|
912 |
|
|
|
913 |
public function authPosDispatch(MvcEvent $event)
|
|
|
914 |
{
|
| 90 |
efrain |
915 |
//$response = $event->getResponse();
|
|
|
916 |
// Functions::addCrossSiteToResponse($response);
|
| 1 |
efrain |
917 |
}
|
|
|
918 |
|
| 167 |
efrain |
919 |
|
|
|
920 |
/**
|
|
|
921 |
*
|
|
|
922 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
923 |
* @param int $user_id
|
|
|
924 |
* @return boolean
|
|
|
925 |
*/
|
|
|
926 |
private function isMicroLeargningAccessGranted($adapter, $user_id)
|
|
|
927 |
{
|
|
|
928 |
|
|
|
929 |
$accessGranted = false;
|
| 283 |
www |
930 |
$capsuleUserMapper = \LeadersLinked\Mapper\MicrolearningCapsuleUserMapper::getInstance($adapter);
|
| 167 |
efrain |
931 |
$now = $capsuleUserMapper->getDatebaseNow();
|
|
|
932 |
|
|
|
933 |
$records = $capsuleUserMapper->fetchAllActiveByUserId($user_id);
|
|
|
934 |
|
|
|
935 |
|
|
|
936 |
foreach($records as $record)
|
|
|
937 |
{
|
| 283 |
www |
938 |
if($record->access != \LeadersLinked\Model\MicrolearningCapsuleUser::ACCESS_UNLIMITED && $record->access != \LeadersLinked\Model\MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
|
| 167 |
efrain |
939 |
continue;
|
|
|
940 |
}
|
| 283 |
www |
941 |
if($record->access == \LeadersLinked\Model\MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
|
| 167 |
efrain |
942 |
if($now < $record->paid_from || $now > $record->paid_to) {
|
|
|
943 |
continue;
|
|
|
944 |
}
|
|
|
945 |
}
|
|
|
946 |
$accessGranted = true;
|
|
|
947 |
break;
|
|
|
948 |
}
|
|
|
949 |
|
|
|
950 |
return $accessGranted;
|
|
|
951 |
}
|
| 302 |
www |
952 |
|
|
|
953 |
|
|
|
954 |
|
|
|
955 |
/**
|
|
|
956 |
*
|
|
|
957 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
958 |
* @param int $user_id
|
|
|
959 |
* @return boolean
|
|
|
960 |
*/
|
|
|
961 |
private function isHabitsAccessGranted($adapter, $user_id)
|
|
|
962 |
{
|
|
|
963 |
|
|
|
964 |
$accessGranted = false;
|
|
|
965 |
$habitUserMapper = \LeadersLinked\Mapper\HabitUserMapper::getInstance($adapter);
|
|
|
966 |
$now = $habitUserMapper->getDatebaseNow();
|
|
|
967 |
|
|
|
968 |
$records = $habitUserMapper->fetchAllActiveByUserId($user_id);
|
|
|
969 |
|
|
|
970 |
foreach($records as $record)
|
|
|
971 |
{
|
|
|
972 |
if($record->access != \LeadersLinked\Model\MicrolearningCapsuleUser::ACCESS_UNLIMITED && $record->access != \LeadersLinked\Model\MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
|
|
|
973 |
continue;
|
|
|
974 |
}
|
|
|
975 |
|
|
|
976 |
if($record->access == \LeadersLinked\Model\MicrolearningCapsuleUser::ACCESS_PAY_PERIOD) {
|
|
|
977 |
if($now < $record->paid_from || $now > $record->paid_to) {
|
|
|
978 |
continue;
|
|
|
979 |
}
|
|
|
980 |
}
|
|
|
981 |
|
|
|
982 |
$accessGranted = true;
|
|
|
983 |
break;
|
|
|
984 |
}
|
|
|
985 |
|
|
|
986 |
return $accessGranted;
|
|
|
987 |
}
|
| 1 |
efrain |
988 |
|
|
|
989 |
|
|
|
990 |
|
|
|
991 |
}
|