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