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