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