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