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