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