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