Proyectos de Subversion LeadersLinked - Services

Rev

Rev 605 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 605 Rev 616
Línea 56... Línea 56...
56
 
56
 
57
 
57
 
Línea 58... Línea 58...
58
class AuthController extends AbstractActionController
58
class AuthController extends AbstractActionController
59
{
59
{
60
 
60
 
61
    
61
 
62
    /**
62
    /**
63
     *
63
     *
64
     * @var \Laminas\Db\Adapter\AdapterInterface
64
     * @var \Laminas\Db\Adapter\AdapterInterface
65
     */
65
     */
66
    private $adapter;
66
    private $adapter;
67
    
67
 
68
    /**
68
    /**
69
     *
69
     *
70
     * @var \LeadersLinked\Cache\CacheInterface
70
     * @var \LeadersLinked\Cache\CacheInterface
71
     */
71
     */
72
    private $cache;
72
    private $cache;
73
    
73
 
74
    
74
 
75
    /**
75
    /**
76
     *
76
     *
77
     * @var \Laminas\Log\LoggerInterface
77
     * @var \Laminas\Log\LoggerInterface
78
     */
78
     */
79
    private $logger;
79
    private $logger;
80
    
80
 
81
    /**
81
    /**
82
     *
82
     *
83
     * @var array
83
     * @var array
84
     */
84
     */
85
    private $config;
85
    private $config;
86
    
86
 
87
    
87
 
88
    /**
88
    /**
89
     *
89
     *
90
     * @var \Laminas\Mvc\I18n\Translator
90
     * @var \Laminas\Mvc\I18n\Translator
91
     */
91
     */
92
    private $translator;
92
    private $translator;
93
    
93
 
94
    
94
 
95
    /**
95
    /**
96
     *
96
     *
Línea 117... Línea 117...
117
        $request = $this->getRequest();
117
        $request = $this->getRequest();
Línea 118... Línea 118...
118
 
118
 
119
        if ($request->isPost()) {
119
        if ($request->isPost()) {
120
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
120
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
121
            $currentNetwork = $currentNetworkPlugin->getNetwork();
121
            $currentNetwork = $currentNetworkPlugin->getNetwork();
122
            
122
 
123
            $jwtToken = null;
123
            $jwtToken = null;
124
            $headers = getallheaders();
-
 
Línea -... Línea 124...
-
 
124
            $headers = getallheaders();
125
            
125
 
126
 
126
 
127
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
127
            if (!empty($headers['authorization']) || !empty($headers['Authorization'])) {
128
                
128
 
129
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
129
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
130
                
130
 
131
                
131
 
132
                if (substr($token, 0, 6 ) == 'Bearer') {
132
                if (substr($token, 0, 6) == 'Bearer') {
133
                    
133
 
134
                    $token = trim(substr($token, 7));
134
                    $token = trim(substr($token, 7));
135
                    
135
 
136
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
136
                    if (!empty($this->config['leaderslinked.jwt.key'])) {
137
                        $key = $this->config['leaderslinked.jwt.key'];
137
                        $key = $this->config['leaderslinked.jwt.key'];
138
                        
138
 
139
                        
139
 
140
                        try {
140
                        try {
141
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
141
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
142
                            
142
 
143
                            
143
 
144
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
144
                            if (empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
145
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
145
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
146
                            }
146
                            }
147
                            
147
 
148
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
148
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
149
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
149
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
150
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
150
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
151
                            if(!$jwtToken) {
151
                            if (!$jwtToken) {
152
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
-
 
153
                            }
152
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
154
 
153
                            }
155
                        } catch(\Exception $e) {
154
                        } catch (\Exception $e) {
156
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
155
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
157
                        }
156
                        }
158
                    } else {
157
                    } else {
Línea 174... Línea 173...
174
                return new JsonModel([
173
                return new JsonModel([
175
                    'success'   => false,
174
                    'success'   => false,
176
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
175
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
177
                ]);
176
                ]);
178
            }
177
            }
179
            
178
 
180
            
179
 
181
            $aes = $_SESSION['aes'];
180
            $aes = $_SESSION['aes'];
182
            unset( $_SESSION['aes'] );
181
            unset($_SESSION['aes']);
183
            
182
 
184
            if (!empty($dataPost['email'])) {
183
            if (!empty($dataPost['email'])) {
185
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $aes);
184
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $aes);
186
            }
185
            }
Línea 187... Línea 186...
187
 
186
 
188
 
187
 
189
            if (!empty($dataPost['password'])) {
188
            if (!empty($dataPost['password'])) {
190
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $aes);
189
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $aes);
191
            }
190
            }
192
            
191
 
Línea 193... Línea 192...
193
            
192
 
194
            $form->setData($dataPost);
193
            $form->setData($dataPost);
195
 
194
 
196
            if ($form->isValid()) {
195
            if ($form->isValid()) {
Línea 197... Línea 196...
197
                
196
 
198
                $dataPost = (array) $form->getData();
197
                $dataPost = (array) $form->getData();
199
           
198
 
200
 
199
 
201
                $email      = $dataPost['email'];
200
                $email      = $dataPost['email'];
202
                $password   = $dataPost['password'];
201
                $password   = $dataPost['password'];
Línea 203... Línea 202...
203
        
202
 
204
                
203
 
205
                
204
 
Línea 206... Línea 205...
206
    
205
 
Línea 207... Línea 206...
207
 
206
 
Línea 208... Línea 207...
208
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
207
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
209
                $authAdapter->setData($email, $password, $currentNetwork->id);
208
                $authAdapter->setData($email, $password, $currentNetwork->id);
Línea 210... Línea 209...
210
                $authService = new AuthenticationService();
209
                $authService = new AuthenticationService();
211
 
210
 
212
                $result = $authService->authenticate($authAdapter);
211
                $result = $authService->authenticate($authAdapter);
213
 
212
 
214
                if ($result->getCode() == AuthResult::SUCCESS) {
213
                if ($result->getCode() == AuthResult::SUCCESS) {
215
 
214
 
216
                    $identity = $result->getIdentity();
215
                    $identity = $result->getIdentity();
217
                    
216
 
218
 
217
 
219
                    $userMapper = UserMapper::getInstance($this->adapter);
218
                    $userMapper = UserMapper::getInstance($this->adapter);
Línea 220... Línea 219...
220
                    $user = $userMapper->fetchOne($identity['user_id']);
219
                    $user = $userMapper->fetchOne($identity['user_id']);
221
                    
220
 
222
  
221
 
223
                    if($token) {
222
                    if ($token) {
Línea 302... Línea 301...
302
 
301
 
303
 
302
 
304
                    $response = $this->getResponse();
303
                    $response = $this->getResponse();
305
                    $response->getHeaders()->addHeader($cookieEmail);
304
                    $response->getHeaders()->addHeader($cookieEmail);
306
                    */
305
                    */
Línea 307... Línea 306...
307
                    
306
 
Línea 308... Línea 307...
308
                    
307
 
Línea 309... Línea 308...
309
 
308
 
310
 
309
 
311
 
310
 
312
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
311
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
313
 
312
 
314
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
313
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
315
 
314
 
316
                    $url =  $this->url()->fromRoute('dashboard');
315
                    $url =  $this->url()->fromRoute('dashboard');
317
                    
316
 
318
                    if ($user_share_invitation && is_array($user_share_invitation)) {
317
                    if ($user_share_invitation && is_array($user_share_invitation)) {
319
                        
318
 
320
                        $content_uuid = $user_share_invitation['code'];
319
                        $content_uuid = $user_share_invitation['code'];
321
                        $content_type = $user_share_invitation['type'];
320
                        $content_type = $user_share_invitation['type'];
322
                        $content_user = $user_share_invitation['user'];
321
                        $content_user = $user_share_invitation['user'];
Línea 340... Línea 339...
340
                                $connection->status = Connection::STATUS_ACCEPTED;
339
                                $connection->status = Connection::STATUS_ACCEPTED;
Línea 341... Línea 340...
341
 
340
 
342
                                $connectionMapper->insert($connection);
341
                                $connectionMapper->insert($connection);
343
                            }
342
                            }
344
                        }
343
                        }
345
                        
344
 
346
                        if($content_type == 'feed') {
345
                        if ($content_type == 'feed') {
347
                            $url = $this->url()->fromRoute('dashboard', ['feed' => $content_uuid ]);
-
 
348
                            
-
 
349
                        }
346
                            $url = $this->url()->fromRoute('dashboard', ['feed' => $content_uuid]);
350
                        else if($content_type == 'post') {
347
                        } else if ($content_type == 'post') {
351
                            $url = $this->url()->fromRoute('post', ['id' => $content_uuid ]);
-
 
352
                        }
348
                            $url = $this->url()->fromRoute('post', ['id' => $content_uuid]);
353
                        else {
349
                        } else {
354
                            $url = $this->url()->fromRoute('dashboard');
350
                            $url = $this->url()->fromRoute('dashboard');
355
                        }
-
 
356
                        
351
                        }
357
                    }
352
                    }
358
                    
353
 
359
                    
354
 
360
                    $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
355
                    $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
361
                    
356
 
362
                    $networkMapper = NetworkMapper::getInstance($this->adapter);
357
                    $networkMapper = NetworkMapper::getInstance($this->adapter);
363
                    $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
358
                    $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
364
                    
359
 
365
                    if(!$network) {
360
                    if (!$network) {
366
                        $network = $networkMapper->fetchOneByDefault();
361
                        $network = $networkMapper->fetchOneByDefault();
367
                    }
362
                    }
368
                    
363
 
369
                    $hostname = trim($network->main_hostname);
364
                    $hostname = trim($network->main_hostname);
Línea 370... Línea 365...
370
                    $url = 'https://' . $hostname . $url;
365
                    $url = 'https://' . $hostname . $url;
371
 
366
 
372
                    
367
 
373
                    $data = [
368
                    $data = [
374
                        'redirect'  => $url,
369
                        'redirect'  => $url,
Línea 375... Línea 370...
375
                        'uuid'      => $user->uuid,
370
                        'uuid'      => $user->uuid,
376
                    ];
371
                    ];
377
 
372
 
378
                    
373
 
379
                  
374
 
380
                            
375
 
381
                    if($currentNetwork->xmpp_active) {
376
                    if ($currentNetwork->xmpp_active) {
382
                        $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
377
                        $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
383
                        $externalCredentials->getUserBy($user->id);
378
                        $externalCredentials->getUserBy($user->id);
384
                        
379
 
385
                        
380
 
386
                        $data['xmpp_domain'] = $currentNetwork->xmpp_domain;
381
                        $data['xmpp_domain'] = $currentNetwork->xmpp_domain;
387
                        $data['xmpp_hostname'] = $currentNetwork->xmpp_hostname;
382
                        $data['xmpp_hostname'] = $currentNetwork->xmpp_hostname;
388
                        $data['xmpp_port'] = $currentNetwork->xmpp_port;
383
                        $data['xmpp_port'] = $currentNetwork->xmpp_port;
389
                        $data['xmpp_username'] = $externalCredentials->getUsernameXmpp();
384
                        $data['xmpp_username'] = $externalCredentials->getUsernameXmpp();
-
 
385
                        $data['xmpp_pasword'] = $externalCredentials->getPasswordXmpp();
Línea 390... Línea -...
390
                        $data['xmpp_pasword'] = $externalCredentials->getPasswordXmpp();
-
 
391
                        $data['inmail_username'] = $externalCredentials->getUsernameInmail();
-
 
392
                        $data['inmail_pasword'] = $externalCredentials->getPasswordInmail();
386
                        $data['inmail_username'] = $externalCredentials->getUsernameInmail();
393
 
387
                        $data['inmail_pasword'] = $externalCredentials->getPasswordInmail();
394
			         }
388
                    }
395
                    
389
 
396
                    $data = [
390
                    $data = [
Línea 397... Línea 391...
397
                        'success'   => true,
391
                        'success'   => true,
398
                        'data'      => $data
392
                        'data'      => $data
Línea 399... Línea 393...
399
                    ];
393
                    ];
400
                    
394
 
-
 
395
 
401
 
396
                    $this->cache->removeItem('user_share_invitation');
-
 
397
                } else {
-
 
398
 
402
                    $this->cache->removeItem('user_share_invitation');
399
                    $message = $result->getMessages()[0];
-
 
400
                    if (!in_array($message, [
-
 
401
                        'ERROR_USER_NOT_FOUND',
-
 
402
                        'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED',
403
                } else {
403
                        'ERROR_USER_IS_BLOCKED',
Línea 404... Línea 404...
404
 
404
                        'ERROR_USER_IS_INACTIVE',
405
                    $message = $result->getMessages()[0];
405
                        'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED',
Línea 485... Línea 485...
485
                    'success'   => false,
485
                    'success'   => false,
486
                    'data'   => $messages
486
                    'data'   => $messages
487
                ]);
487
                ]);
488
            }
488
            }
489
        } else if ($request->isGet()) {
489
        } else if ($request->isGet()) {
490
            
490
 
491
            $aes = '';
491
            $aes = '';
492
            $jwtToken = null;
492
            $jwtToken = null;
493
            $headers = getallheaders();
493
            $headers = getallheaders();
494
            
494
 
495
            
495
 
496
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
496
            if (!empty($headers['authorization']) || !empty($headers['Authorization'])) {
497
                
497
 
498
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
498
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
499
                
499
 
500
                
500
 
501
                if (substr($token, 0, 6 ) == 'Bearer') {
501
                if (substr($token, 0, 6) == 'Bearer') {
502
                    
502
 
503
                    $token = trim(substr($token, 7));
503
                    $token = trim(substr($token, 7));
504
                    
504
 
505
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
505
                    if (!empty($this->config['leaderslinked.jwt.key'])) {
506
                        $key = $this->config['leaderslinked.jwt.key'];
506
                        $key = $this->config['leaderslinked.jwt.key'];
507
                        
507
 
508
                        
508
 
509
                        try {
509
                        try {
510
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
510
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
511
                            
511
 
512
                            
512
 
513
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
513
                            if (empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
514
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
514
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
515
                            }
515
                            }
516
                            
516
 
517
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
517
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
518
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
518
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
519
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
519
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
520
                        } catch(\Exception $e) {
520
                        } catch (\Exception $e) {
521
                            //Token invalido
521
                            //Token invalido
522
                        }
522
                        }
523
                    }
523
                    }
524
                }
524
                }
525
            }
525
            }
526
            
526
 
527
            if(!$jwtToken) {
527
            if (!$jwtToken) {
528
            
528
 
529
                $aes = Functions::generatePassword(16);
529
                $aes = Functions::generatePassword(16);
530
                
530
 
531
                $jwtToken = new JwtToken();
531
                $jwtToken = new JwtToken();
532
                $jwtToken->aes = $aes;
532
                $jwtToken->aes = $aes;
533
                
533
 
534
                $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
534
                $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
535
                if($jwtTokenMapper->insert($jwtToken)) {
535
                if ($jwtTokenMapper->insert($jwtToken)) {
536
                    $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
536
                    $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
537
                }
537
                }
538
                
538
 
539
                $token = '';
539
                $token = '';
540
                
540
 
541
                if(!empty($this->config['leaderslinked.jwt.key'])) {
541
                if (!empty($this->config['leaderslinked.jwt.key'])) {
542
                    $issuedAt   = new \DateTimeImmutable();
542
                    $issuedAt   = new \DateTimeImmutable();
543
                    $expire     = $issuedAt->modify('+365 days')->getTimestamp();
543
                    $expire     = $issuedAt->modify('+365 days')->getTimestamp();
544
                    $serverName = $_SERVER['HTTP_HOST'];
544
                    $serverName = $_SERVER['HTTP_HOST'];
545
                    $payload = [
545
                    $payload = [
546
                        'iat'  => $issuedAt->getTimestamp(),
546
                        'iat'  => $issuedAt->getTimestamp(),
547
                        'iss'  => $serverName,
547
                        'iss'  => $serverName,
548
                        'nbf'  => $issuedAt->getTimestamp(),
548
                        'nbf'  => $issuedAt->getTimestamp(),
549
                        'exp'  => $expire,
549
                        'exp'  => $expire,
550
                        'uuid' => $jwtToken->uuid,
550
                        'uuid' => $jwtToken->uuid,
551
                    ];
551
                    ];
552
                    
552
 
553
   
553
 
554
                    $key = $this->config['leaderslinked.jwt.key'];
554
                    $key = $this->config['leaderslinked.jwt.key'];
555
                    $token = JWT::encode($payload, $key, 'HS256');
555
                    $token = JWT::encode($payload, $key, 'HS256');
556
 
-
 
557
                }
556
                }
558
            } else {
557
            } else {
559
                if(!$jwtToken->user_id) {
558
                if (!$jwtToken->user_id) {
560
                    $aes = Functions::generatePassword(16);
559
                    $aes = Functions::generatePassword(16);
561
                    $jwtToken->aes = $aes;
560
                    $jwtToken->aes = $aes;
562
                    $jwtTokenMapper->update($jwtToken);
561
                    $jwtTokenMapper->update($jwtToken);
563
                }
562
                }
564
            }
563
            }
565
            
564
 
566
            
565
 
567
            
566
 
568
            
567
 
569
            
568
 
Línea 570... Línea 569...
570
 
569
 
571
 
570
 
572
            if ($this->config['leaderslinked.runmode.sandbox']) {
571
            if ($this->config['leaderslinked.runmode.sandbox']) {
Línea 582... Línea 581...
582
            if ($sandbox) {
581
            if ($sandbox) {
583
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
582
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
584
            } else {
583
            } else {
585
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
584
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
586
            }
585
            }
587
            
586
 
Línea 588... Línea 587...
588
 
587
 
589
            $parts = explode('.', $currentNetwork->main_hostname);
588
            $parts = explode('.', $currentNetwork->main_hostname);
590
            if($parts[1] === 'com') {
589
            if ($parts[1] === 'com') {
591
                $replace_main = false;
590
                $replace_main = false;
592
            } else {
591
            } else {
593
                $replace_main = true;
592
                $replace_main = true;
594
            }
-
 
Línea 595... Línea -...
595
            
-
 
596
 
-
 
597
                $storage = Storage::getInstance($this->config, $this->adapter);
-
 
598
                $path = $storage->getPathNetwork();
-
 
599
                
-
 
600
                if($currentNetwork->logo) {
-
 
601
                    $logo_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->logo);
-
 
602
                } else {
-
 
603
                    $logo_url = '';
-
 
604
                }
-
 
605
                
-
 
606
                if($currentNetwork->navbar) {
-
 
607
                    $navbar_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->navbar);
-
 
608
                } else {
-
 
609
                    $navbar_url = '';
-
 
610
                }
-
 
611
                
-
 
612
                if($currentNetwork->favico) {
-
 
613
                    $favico_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->favico);
-
 
614
                } else {
-
 
615
                    $favico_url = '';
-
 
Línea -... Línea 593...
-
 
593
            }
-
 
594
 
616
                }
595
 
-
 
596
            $storage = Storage::getInstance($this->config, $this->adapter);
-
 
597
            $path = $storage->getPathNetwork();
-
 
598
 
-
 
599
            if ($currentNetwork->logo) {
-
 
600
                $logo_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->logo);
-
 
601
            } else {
-
 
602
                $logo_url = '';
-
 
603
            }
-
 
604
 
-
 
605
            if ($currentNetwork->navbar) {
-
 
606
                $navbar_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->navbar);
-
 
607
            } else {
-
 
608
                $navbar_url = '';
-
 
609
            }
-
 
610
 
-
 
611
            if ($currentNetwork->favico) {
-
 
612
                $favico_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->favico);
-
 
613
            } else {
-
 
614
                $favico_url = '';
-
 
615
            }
Línea 617... Línea 616...
617
           
616
 
618
 
617
 
619
         
618
 
620
 
619
 
Línea 633... Línea 632...
633
                'favico_url'                    => $favico_url,
632
                'favico_url'                    => $favico_url,
634
                'intro'                         => $currentNetwork->intro ? $currentNetwork->intro : '',
633
                'intro'                         => $currentNetwork->intro ? $currentNetwork->intro : '',
635
                'is_logged_in'                  => $jwtToken->user_id ? true : false,
634
                'is_logged_in'                  => $jwtToken->user_id ? true : false,
Línea 636... Línea 635...
636
 
635
 
637
            ];
636
            ];
638
            
637
 
639
            if($currentNetwork->default == Network::DEFAULT_YES) {
638
            if ($currentNetwork->default == Network::DEFAULT_YES) {
640
                
639
 
641
   
640
 
642
                
641
 
643
                $currentUserPlugin = $this->plugin('currentUserPlugin');
642
                $currentUserPlugin = $this->plugin('currentUserPlugin');
644
                if ($currentUserPlugin->hasIdentity()) {
643
                if ($currentUserPlugin->hasIdentity()) {
645
                    
644
 
646
                    
645
 
647
                    $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
646
                    $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
648
                    $externalCredentials->getUserBy($currentUserPlugin->getUserId());
647
                    $externalCredentials->getUserBy($currentUserPlugin->getUserId());
649
                    
648
 
650
       
649
 
651
                    if($currentNetwork->xmpp_active) {
650
                    if ($currentNetwork->xmpp_active) {
652
                        $data['xmpp_domain']      = $currentNetwork->xmpp_domain;
651
                        $data['xmpp_domain']      = $currentNetwork->xmpp_domain;
653
                        $data['xmpp_hostname']    = $currentNetwork->xmpp_hostname;
652
                        $data['xmpp_hostname']    = $currentNetwork->xmpp_hostname;
654
                        $data['xmpp_port']        = $currentNetwork->xmpp_port;
653
                        $data['xmpp_port']        = $currentNetwork->xmpp_port;
655
                        $data['xmpp_username']    = $externalCredentials->getUsernameXmpp();
654
                        $data['xmpp_username']    = $externalCredentials->getUsernameXmpp();
656
                        $data['xmpp_password']    = $externalCredentials->getPasswordXmpp();
655
                        $data['xmpp_password']    = $externalCredentials->getPasswordXmpp();
657
                        $data['inmail_username']    = $externalCredentials->getUsernameInmail();
656
                        $data['inmail_username']    = $externalCredentials->getUsernameInmail();
658
                        $data['inmail_password']    = $externalCredentials->getPasswordInmail();
657
                        $data['inmail_password']    = $externalCredentials->getPasswordInmail();
659
                    }
658
                    }
660
                }
659
                }
661
            }
660
            }
662
            
661
 
663
            $data = [
662
            $data = [
664
                'success' => true,
663
                'success' => true,
665
                'data' =>  $data
664
                'data' =>  $data
666
            ];
-
 
667
           
665
            ];
668
        } else {
666
        } else {
669
            $data = [
667
            $data = [
670
                'success' => false,
668
                'success' => false,
671
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
669
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
Línea 874... Línea 872...
874
            return new JsonModel([
872
            return new JsonModel([
875
                'success'   => true,
873
                'success'   => true,
876
                'data'      => [
874
                'data'      => [
877
                    'message' => 'LABEL_SIGNOUT_SUCCESSFULLY',
875
                    'message' => 'LABEL_SIGNOUT_SUCCESSFULLY',
878
                    'url' => 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params)
876
                    'url' => 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params)
879
                ],    
877
                ],
880
                
878
 
881
            ]);
879
            ]);
882
            
880
 
883
            
881
 
884
           // $url = 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params);
882
            // $url = 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params);
885
           // return $this->redirect()->toUrl($url);
883
            // return $this->redirect()->toUrl($url);
886
        } else {
884
        } else {
Línea 887... Línea 885...
887
 
885
 
Línea 888... Línea 886...
888
 
886
 
889
            if ($currentUserPlugin->hasIdentity()) {
887
            if ($currentUserPlugin->hasIdentity()) {
Línea 890... Línea 888...
890
 
888
 
Línea 891... Línea 889...
891
                $this->logger->info('Desconexión de LeadersLinked', ['user_id' => $currentUserPlugin->getUserId(), 'ip' => Functions::getUserIP()]);
889
                $this->logger->info('Desconexión de LeadersLinked', ['user_id' => $currentUserPlugin->getUserId(), 'ip' => Functions::getUserIP()]);
892
            }
890
            }
893
 
891
 
894
            $currentUserPlugin->clearIdentity();
892
            $currentUserPlugin->clearIdentity();
895
 
893
 
896
           // return $this->redirect()->toRoute('home');
894
            // return $this->redirect()->toRoute('home');
897
           
895
 
898
            return new JsonModel([
896
            return new JsonModel([
899
                'success'   => true,
897
                'success'   => true,
900
                'data'      => [
898
                'data'      => [
901
                    'message' => 'LABEL_SIGNOUT_SUCCESSFULLY',
899
                    'message' => 'LABEL_SIGNOUT_SUCCESSFULLY',
902
                    'url' => '',
900
                    'url' => '',
Línea 903... Línea 901...
903
                ],
901
                ],
904
                
902
 
905
            ]);
903
            ]);
906
        }
904
        }
Línea -... Línea 905...
-
 
905
    }
907
    }
906
 
Línea 908... Línea 907...
908
 
907
 
909
 
908
    public function resetPasswordAction()
910
    public function resetPasswordAction()
-
 
911
    {
909
    {
912
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
910
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
Línea 913... Línea 911...
913
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
911
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
914
 
912
 
915
        $code =  Functions::sanitizeFilterString($this->params()->fromRoute('code', ''));
913
 
916
 
914
        $code =  Functions::sanitizeFilterString($this->params()->fromRoute('code', ''));
917
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
918
        $user = $userMapper->fetchOneByPasswordResetKeyAndNetworkId($code, $currentNetwork->id);
915
 
Línea -... Línea 916...
-
 
916
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
917
        $user = $userMapper->fetchOneByPasswordResetKeyAndNetworkId($code, $currentNetwork->id);
919
 
918
        if (!$user) {
920
        if (!$user) {
919
            $this->logger->err('Restablecer contraseña - Error código no existe', ['ip' => Functions::getUserIP()]);
921
            $this->logger->err('Restablecer contraseña - Error código no existe', ['ip' => Functions::getUserIP()]);
-
 
922
 
920
 
923
            return new JsonModel([
921
            return new JsonModel([
-
 
922
                'success'   => false,
924
                'success'   => false,
923
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_IS_INVALID'
925
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_IS_INVALID'
924
            ]);
926
            ]);
925
        }
927
 
926
 
928
        }
927
 
Línea 929... Línea 928...
929
 
928
 
930
        $password_generated_on = strtotime($user->password_generated_on);
-
 
931
        $expiry_time = $password_generated_on + $this->config['leaderslinked.security.reset_password_expired'];
929
        $password_generated_on = strtotime($user->password_generated_on);
932
 
930
        $expiry_time = $password_generated_on + $this->config['leaderslinked.security.reset_password_expired'];
933
        if (time() > $expiry_time) {
-
 
934
            $this->logger->err('Restablecer contraseña - Error código expirado', ['ip' => Functions::getUserIP()]);
931
        if (time() > $expiry_time) {
935
            return new JsonModel([
932
            $this->logger->err('Restablecer contraseña - Error código expirado', ['ip' => Functions::getUserIP()]);
936
                'success'   => false,
933
 
937
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_HAS_EXPIRED'
934
            return new JsonModel([
938
            ]);
935
                'success'   => false,
939
        }
936
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_HAS_EXPIRED'
Línea 940... Línea 937...
940
 
937
            ]);
941
        $request = $this->getRequest();
938
        }
942
 
939
 
943
        if ($request->isPost()) {
-
 
944
            $dataPost = $request->getPost()->toArray();
940
        $request = $this->getRequest();
945
 
941
        if ($request->isPost()) {
946
            if (empty($_SESSION['aes'])) {
942
            $dataPost = $request->getPost()->toArray();
Línea -... Línea 943...
-
 
943
            if (empty($_SESSION['aes'])) {
-
 
944
                return new JsonModel([
947
                return new JsonModel([
945
                    'success'   => false,
948
                    'success'   => false,
946
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
Línea 949... Línea 947...
949
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
947
                ]);
950
                ]);   
948
            }
951
            }
949
 
Línea -... Línea 950...
-
 
950
            if (!empty($dataPost['password'])) {
952
 
951
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
953
            if (!empty($dataPost['password'])) {
952
            }
Línea 954... Línea 953...
954
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
953
            if (!empty($dataPost['confirmation'])) {
955
            }
954
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
Línea 998... Línea 997...
998
 
997
 
Línea 999... Línea 998...
999
 
998
 
1000
                        $this->logger->info('Restablecer contraseña realizado', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
999
                        $this->logger->info('Restablecer contraseña realizado', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1001
 
1000
 
1002
 
1001
 
Línea 1003... Línea 1002...
1003
                        
1002
 
Línea 1054... Línea 1053...
1054
                'code' => $code,
1053
                'code' => $code,
1055
                'site_key' => $site_key,
1054
                'site_key' => $site_key,
1056
                'aes'       => $_SESSION['aes'],
1055
                'aes'       => $_SESSION['aes'],
1057
                'defaultNetwork' => $currentNetwork->default,
1056
                'defaultNetwork' => $currentNetwork->default,
1058
            ]);
1057
            ]);
1059
 
-
 
1060
        }
1058
        }
Línea 1061... Línea 1059...
1061
 
1059
 
Línea 1067... Línea 1065...
1067
        ]);
1065
        ]);
1068
    }
1066
    }
Línea 1069... Línea 1067...
1069
 
1067
 
1070
    public function forgotPasswordAction()
1068
    public function forgotPasswordAction()
-
 
1069
    {
1071
    {
1070
        // Obtiene el plugin de la red actual.
-
 
1071
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1072
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1072
        // Obtiene la información de la red actual.
Línea 1073... Línea -...
1073
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
-
 
1074
 
-
 
1075
        $request = $this->getRequest();
-
 
1076
 
-
 
1077
        if ($request->isGet()) {
-
 
1078
            if (empty($_SESSION['aes'])) {
-
 
1079
                $_SESSION['aes'] = Functions::generatePassword(16);
-
 
1080
            }
-
 
1081
 
-
 
1082
            $site_key = $this->config['leaderslinked.runmode.sandbox'] 
-
 
Línea 1083... Línea -...
1083
            ? $this->config['leaderslinked.google_captcha.sandbox_site_key'] 
-
 
1084
            : $this->config['leaderslinked.google_captcha.production_site_key'];
-
 
1085
 
-
 
1086
            return new JsonModel([
-
 
1087
                'site_key'  => $site_key,
-
 
1088
                'aes'       => $_SESSION['aes'],
-
 
Línea -... Línea 1073...
-
 
1073
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
-
 
1074
 
-
 
1075
 
1089
                'defaultNetwork' => $currentNetwork->default,
1076
 
-
 
1077
        // Obtiene la petición HTTP actual.
1090
            ]);
1078
        $request = $this->getRequest();
1091
        }
-
 
-
 
1079
        // Verifica si la petición es de tipo POST.
1092
 
1080
        if ($request->isPost()) {
-
 
1081
            // Obtiene los datos enviados por POST y los convierte a un array.
1093
        if ($request->isPost()) {
1082
            $dataPost = $request->getPost()->toArray();
1094
            $dataPost = $request->getPost()->toArray();
1083
            // Verifica si la clave AES no está presente en la sesión.
1095
 
1084
            if (empty($_SESSION['aes'])) {
1096
            if (empty($_SESSION['aes'])) {
1085
                // Retorna un error si no se encuentran las claves de encriptación.
1097
                return new JsonModel([
1086
                return new JsonModel([
Línea -... Línea 1087...
-
 
1087
                    'success'   => false,
1098
                    'success'   => false,
1088
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
-
 
1089
                ]);
1099
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
1090
            }
1100
                ]);
1091
 
Línea -... Línea 1092...
-
 
1092
            // Verifica si el campo 'email' no está vacío en los datos POST.
1101
            }
1093
            if (!empty($dataPost['email'])) {
-
 
1094
                // Desencripta el email utilizando la clave AES de la sesión.
1102
 
1095
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
Línea -... Línea 1096...
-
 
1096
            }
1103
            if (!empty($dataPost['email'])) {
1097
 
-
 
1098
            // Crea una nueva instancia del formulario ForgotPasswordForm, pasando la configuración.
-
 
1099
            $form = new ForgotPasswordForm($this->config);
-
 
1100
            // Establece los datos del POST en el formulario.
-
 
1101
            $form->setData($dataPost);
-
 
1102
 
-
 
1103
            // Verifica si el formulario es válido.
-
 
1104
            if ($form->isValid()) {
-
 
1105
                // Obtiene los datos validados del formulario como un array.
-
 
1106
                $dataPost = (array) $form->getData();
-
 
1107
                // Extrae el email de los datos del formulario.
-
 
1108
                $email      = $dataPost['email'];
-
 
1109
 
-
 
1110
                // Obtiene una instancia del UserMapper.
-
 
1111
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
1112
                // Busca un usuario por email y ID de red.
-
 
1113
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
-
 
1114
                // Verifica si no se encontró ningún usuario.
-
 
1115
                if (!$user) {
-
 
1116
                    // Registra un error si el email no existe.
-
 
1117
                    $this->logger->err('Olvidó contraseña ' . $email . '- Email no existe ', ['ip' => Functions::getUserIP()]);
-
 
1118
 
-
 
1119
                    // Retorna un error indicando que el email no está registrado.
-
 
1120
                    return new JsonModel([
-
 
1121
                        'success' => false,
-
 
1122
                        'data' =>  'ERROR_EMAIL_IS_NOT_REGISTERED'
-
 
1123
                    ]);
-
 
1124
                } else {
-
 
1125
                    // Verifica si el estado del usuario es inactivo.
-
 
1126
                    if ($user->status == User::STATUS_INACTIVE) {
-
 
1127
                        // Retorna un error indicando que el usuario está inactivo.
-
 
1128
                        return new JsonModel([
-
 
1129
                            'success' => false,
-
 
1130
                            'data' =>  'ERROR_USER_IS_INACTIVE'
-
 
1131
                        ]);
-
 
1132
                        // Verifica si el email del usuario no ha sido verificado.
-
 
1133
                    } else if ($user->email_verified == User::EMAIL_VERIFIED_NO) {
-
 
1134
                        // Registra un error si el email no ha sido verificado.
-
 
1135
                        $this->logger->err('Olvidó contraseña - Email no verificado ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1136
 
-
 
1137
                        // Retorna un error indicando que el email no ha sido verificado.
-
 
1138
                        return new JsonModel([
-
 
1139
                            'success' => false,
-
 
1140
                            'data' => 'ERROR_EMAIL_HAS_NOT_BEEN_VERIFIED'
-
 
1141
                        ]);
-
 
1142
                    } else {
-
 
1143
                        // Genera una clave de reseteo de contraseña utilizando el email del usuario y el timestamp actual.
-
 
1144
                        $password_reset_key = md5($user->email . time());
-
 
1145
                        // Actualiza la clave de reseteo de contraseña del usuario en la base de datos.
-
 
1146
                        $userMapper->updatePasswordResetKey((int) $user->id, $password_reset_key);
-
 
1147
 
-
 
1148
                        // Obtiene una instancia del EmailTemplateMapper.
-
 
1149
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
-
 
1150
                        // Busca una plantilla de email por código y ID de red.
-
 
1151
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RESET_PASSWORD, $currentNetwork->id);
-
 
1152
                        // Verifica si se encontró la plantilla de email.
-
 
1153
                        if ($emailTemplate) {
-
 
1154
                            // Prepara los datos para la plantilla de email.
-
 
1155
                            $arrayCont = [
-
 
1156
                                'firstname'             => $user->first_name,
-
 
1157
                                'lastname'              => $user->last_name,
-
 
1158
                                'other_user_firstname'  => '',
-
 
1159
                                'other_user_lastname'   => '',
-
 
1160
                                'company_name'          => '',
-
 
1161
                                'group_name'            => '',
-
 
1162
                                'content'               => '',
-
 
1163
                                'code'                  => '',
-
 
1164
                                // Genera el enlace para resetear la contraseña.
-
 
1165
                                'link'                  => $this->url()->fromRoute('reset-password', ['code' => $password_reset_key], ['force_canonical' => true])
-
 
1166
                            ];
-
 
1167
 
-
 
1168
                            // Crea una nueva instancia de QueueEmail.
-
 
1169
                            $email = new QueueEmail($this->adapter);
-
 
1170
                            // Procesa y envía el email utilizando la plantilla y los datos preparados.
-
 
1171
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
-
 
1172
                        }
-
 
1173
 
-
 
1174
                        // Registra una información indicando que se envió el link de recuperación.
-
 
1175
                        $this->logger->info('Olvidó contraseña - Se envio link de recuperación ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1176
 
-
 
1177
                        // Retorna una respuesta exitosa indicando que el link de recuperación fue enviado.
-
 
1178
                        return new JsonModel([
-
 
1179
                            'success' => true,
1104
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
1180
                            'data' => 'LABEL_RECOVERY_LINK_WAS_SENT_TO_YOUR_EMAIL'
Línea -... Línea 1181...
-
 
1181
                        ]);
-
 
1182
                    }
1105
            }
1183
                }
-
 
1184
            } else {
1106
 
1185
 
1107
            $form = new ForgotPasswordForm($this->config);
1186
                // Obtiene los mensajes de error del campo 'captcha' del formulario.
1108
            $form->setData($dataPost);
1187
                $form_messages =  $form->getMessages('captcha');
1109
 
1188
 
1110
            if (!$form->isValid()){
1189
 
Línea -... Línea 1190...
-
 
1190
                // Verifica si hay mensajes de error para el captcha.
1111
                $form_messages =  $form->getMessages('captcha');
1191
                if (!empty($form_messages)) {
-
 
1192
                    // Retorna un error indicando que el reCAPTCHA está vacío o es inválido.
1112
 
1193
                    return new JsonModel([
-
 
1194
                        'success'   => false,
1113
                if (!empty($form_messages)) {
1195
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
-
 
1196
                    ]);
1114
                    return new JsonModel([
1197
                }
1115
                        'success'   => false,
1198
 
Línea -... Línea 1199...
-
 
1199
                // Inicializa un array para almacenar los mensajes de error del formulario.
1116
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
1200
                $messages = [];
1117
                    ]);
1201
                // Obtiene todos los mensajes de error del formulario como un array.
1118
                }
1202
                $form_messages = (array) $form->getMessages();
1119
 
1203
                // Itera sobre los mensajes de error del formulario.
1120
                $messages = [];
1204
                foreach ($form_messages  as $fieldname => $field_messages) {
-
 
1205
                    // Agrupa los mensajes de error por nombre de campo.
-
 
1206
                    $messages[$fieldname] = array_values($field_messages);
Línea 1121... Línea -...
1121
                $form_messages = (array) $form->getMessages();
-
 
1122
                foreach ($form_messages  as $fieldname => $field_messages) {
-
 
1123
                    $messages[$fieldname] = array_values($field_messages);
-
 
1124
                }
1207
                }
1125
 
-
 
1126
                return new JsonModel([
-
 
1127
                    'success'   => false,
1208
 
1128
                    'data'      => $messages
-
 
1129
                ]);
-
 
1130
            }
-
 
1131
 
-
 
1132
            $dataPost = (array) $form->getData();
-
 
1133
            $email      = $dataPost['email'];
-
 
1134
 
-
 
1135
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
1136
            $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
-
 
1137
 
-
 
1138
            if (!$user) {
-
 
1139
                $this->logger->err('Olvidó contraseña ' . $email . '- Email no existe ', ['ip' => Functions::getUserIP()]);
-
 
1140
                return new JsonModel([
-
 
1141
                    'success' => false,
-
 
1142
                    'data' =>  'ERROR_EMAIL_IS_NOT_REGISTERED'
-
 
1143
                ]);
-
 
1144
            }
-
 
1145
 
-
 
1146
            
-
 
1147
            if ($user->status == User::STATUS_INACTIVE) {
1209
                // Retorna una respuesta de error con los mensajes del formulario.
1148
                return new JsonModel([
-
 
1149
                    'success' => false,
-
 
1150
                    'data' =>  'ERROR_USER_IS_INACTIVE'
-
 
1151
                ]);
1210
                return new JsonModel([
1152
            } 
-
 
1153
            
-
 
1154
            if ($user->email_verified == User::EMAIL_VERIFIED_NO) {
-
 
1155
                $this->logger->err('Olvidó contraseña - Email no verificado ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1156
                return new JsonModel([
-
 
1157
                    'success' => false,
-
 
1158
                    'data' => 'ERROR_EMAIL_HAS_NOT_BEEN_VERIFIED'
-
 
1159
                ]);
-
 
1160
            } 
-
 
1161
            
-
 
1162
            $password_reset_key = md5($user->email . time());
-
 
1163
            $userMapper->updatePasswordResetKey((int) $user->id, $password_reset_key);
1211
                    'success'   => false,
Línea 1164... Línea -...
1164
 
-
 
1165
            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
-
 
1166
            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RESET_PASSWORD, $currentNetwork->id);
-
 
1167
 
1212
                    'data'      => $messages
1168
            if (!$emailTemplate) {
1213
                ]);
1169
                $this->logger->err('Olvidó contraseña - Email template no existe ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
1170
                return new JsonModel([
-
 
1171
                    'success' => false,
1214
            }
1172
                    'data' => 'ERROR_EMAIL_TEMPLATE_NOT_FOUND'
-
 
1173
                ]);
1215
            // Verifica si la petición es de tipo GET.
1174
            }
1216
        } else  if ($request->isGet()) {
1175
 
-
 
1176
            $arrayCont = [
1217
 
1177
                'firstname'             => $user->first_name,
-
 
1178
                'lastname'              => $user->last_name,
-
 
1179
                'other_user_firstname'  => '',
1218
            // Verifica si la clave AES no está presente en la sesión.
1180
                'other_user_lastname'   => '',
-
 
1181
                'company_name'          => '',
-
 
1182
                'group_name'            => '',
-
 
1183
                'content'               => '',
-
 
1184
                'code'                  => '',
1219
            if (empty($_SESSION['aes'])) {
Línea 1185... Línea 1220...
1185
                'link'                  => $this->url()->fromRoute('reset-password', ['code' => $password_reset_key], ['force_canonical' => true])
1220
                // Genera una nueva clave AES y la guarda en la sesión.
1186
            ];
-
 
1187
 
1221
                $_SESSION['aes'] = Functions::generatePassword(16);
1188
            $email = new QueueEmail($this->adapter);
1222
            }
1189
            
1223
 
-
 
1224
            // Verifica si el entorno es sandbox.
1190
            if (!$email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name))) {
1225
            if ($this->config['leaderslinked.runmode.sandbox']) {
1191
                $this->logger->err('Olvidó contraseña - Error al enviar email ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1226
                // Obtiene la clave del sitio de Google reCAPTCHA para sandbox.
Línea -... Línea 1227...
-
 
1227
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
1192
                return new JsonModel([
1228
            } else {
1193
                    'success' => false,
1229
                // Obtiene la clave del sitio de Google reCAPTCHA para producción.
1194
                    'data' => 'ERROR_EMAIL_NOT_SENT'
1230
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
1195
                ]);
1231
            }
1196
            }
1232
 
Línea 1269... Línea 1305...
1269
 
1305
 
Línea 1270... Línea 1306...
1270
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
1306
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
1271
 
1307
 
1272
 
1308
 
1273
                    if ($user_share_invitation && is_array($user_share_invitation)) {
1309
                    if ($user_share_invitation && is_array($user_share_invitation)) {
1274
                        
1310
 
1275
                        $content_uuid = $user_share_invitation['code'];
1311
                        $content_uuid = $user_share_invitation['code'];
1276
                        $content_type = $user_share_invitation['type'];
1312
                        $content_type = $user_share_invitation['type'];
1277
                        $content_user = $user_share_invitation['user'];
1313
                        $content_user = $user_share_invitation['user'];
1278
                        
1314
 
1279
                        
1315
 
Línea 1280... Línea 1316...
1280
                        $userRedirect = $userMapper->fetchOneByUuid($content_user);
1316
                        $userRedirect = $userMapper->fetchOneByUuid($content_user);
Línea 1330... Línea 1366...
1330
 
1366
 
Línea 1331... Línea 1367...
1331
 
1367
 
1332
                                $this->cache->removeItem('user_share_invitation');
1368
                                $this->cache->removeItem('user_share_invitation');
1333
 
1369
 
1334
 
-
 
1335
                         
-
 
1336
                                if($content_type == 'feed') {
1370
 
1337
                                    $url = $this->url()->fromRoute('dashboard', ['feed' => $content_uuid ]);
1371
 
1338
                                    
-
 
1339
                                }
1372
                                if ($content_type == 'feed') {
1340
                                else if($content_type == 'post') {
1373
                                    $url = $this->url()->fromRoute('dashboard', ['feed' => $content_uuid]);
1341
                                    $url = $this->url()->fromRoute('post', ['id' => $content_uuid ]);
1374
                                } else if ($content_type == 'post') {
1342
                                }
1375
                                    $url = $this->url()->fromRoute('post', ['id' => $content_uuid]);
1343
                                else {
1376
                                } else {
1344
                                    $url = $this->url()->fromRoute('dashboard');
1377
                                    $url = $this->url()->fromRoute('dashboard');
1345
                                }
1378
                                }
1346
                                
1379
 
1347
                                $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
1380
                                $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
1348
                                
1381
 
1349
                                $networkMapper = NetworkMapper::getInstance($this->adapter);
1382
                                $networkMapper = NetworkMapper::getInstance($this->adapter);
1350
                                $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
1383
                                $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
1351
                                
1384
 
1352
                                if(!$network) {
1385
                                if (!$network) {
1353
                                    $network = $networkMapper->fetchOneByDefault();
1386
                                    $network = $networkMapper->fetchOneByDefault();
1354
                                }
1387
                                }
Línea 1355... Línea 1388...
1355
                                
1388
 
1356
                                $hostname = trim($network->main_hostname);
1389
                                $hostname = trim($network->main_hostname);
1357
                                $url = 'https://' . $hostname . $url;
1390
                                $url = 'https://' . $hostname . $url;
1358
                                
1391
 
Línea 1509... Línea 1542...
1509
 
1542
 
1510
 
1543
 
1511
 
1544
 
1512
            if ($user) {
1545
            if ($user) {
1513
                if (User::EMAIL_VERIFIED_YES == $user->email_verified) {
1546
                if (User::EMAIL_VERIFIED_YES == $user->email_verified) {
1514
                    
1547
 
1515
                    $this->logger->err('Verificación email - El código ya habia sido verificao ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1548
                    $this->logger->err('Verificación email - El código ya habia sido verificao ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1516
                    
1549
 
1517
                    $response = [
1550
                    $response = [
1518
                        'success' => false,
1551
                        'success' => false,
1519
                        'data' => 'ERROR_EMAIL_HAS_BEEN_PREVIOUSLY_VERIFIED'
1552
                        'data' => 'ERROR_EMAIL_HAS_BEEN_PREVIOUSLY_VERIFIED'
1520
                    ];
1553
                    ];
Línea 1521... Línea 1554...
1521
            
1554
 
Línea 1556... Línea 1589...
1556
 
1589
 
Línea 1557... Línea 1590...
1557
                        $this->cache->removeItem('user_share_invitation');
1590
                        $this->cache->removeItem('user_share_invitation');
1558
 
1591
 
1559
 
1592
 
1560
                        if ($currentNetwork->default == Network::DEFAULT_YES) {
1593
                        if ($currentNetwork->default == Network::DEFAULT_YES) {
1561
                            
1594
 
1562
                            $response = [
1595
                            $response = [
1563
                                'success' => true,
1596
                                'success' => true,
1564
                                'data' => 'LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED'
1597
                                'data' => 'LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED'
1565
                            ];
-
 
1566
                            
-
 
1567
                            return new JsonModel($response);
1598
                            ];
Línea 1568... Línea 1599...
1568
                            
1599
 
1569
     
1600
                            return new JsonModel($response);
Línea 1586... Línea 1617...
1586
                                ];
1617
                                ];
Línea 1587... Línea 1618...
1587
 
1618
 
1588
                                $email = new QueueEmail($this->adapter);
1619
                                $email = new QueueEmail($this->adapter);
1589
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1620
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1590
                            }
1621
                            }
1591
                            
1622
 
1592
                            $response = [
1623
                            $response = [
1593
                                'success' => true,
1624
                                'success' => true,
1594
                                'data' => 'LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED_WE_ARE_VERIFYING_YOUR_INFORMATION'
1625
                                'data' => 'LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED_WE_ARE_VERIFYING_YOUR_INFORMATION'
1595
                            ];
-
 
1596
                            
-
 
1597
                            return new JsonModel($response);
-
 
Línea -... Línea 1626...
-
 
1626
                            ];
1598
 
1627
 
1599
 
1628
                            return new JsonModel($response);
1600
                        }
1629
                        }
1601
                    } else {
1630
                    } else {
1602
                        $this->logger->err('Verificación email - Ha ocurrido un error ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1631
                        $this->logger->err('Verificación email - Ha ocurrido un error ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1603
                        
1632
 
1604
                        $response = [
1633
                        $response = [
1605
                            'success' => false,
1634
                            'success' => false,
1606
                            'data' => 'ERROR_THERE_WAS_AN_ERROR'
-
 
1607
                        ];
-
 
Línea -... Línea 1635...
-
 
1635
                            'data' => 'ERROR_THERE_WAS_AN_ERROR'
1608
                        
1636
                        ];
1609
                        return new JsonModel($response);
1637
 
1610
 
1638
                        return new JsonModel($response);
1611
                    }
1639
                    }
1612
                }
1640
                }
1613
            } else {
1641
            } else {
Línea 1614... Línea 1642...
1614
                
1642
 
1615
                
1643
 
1616
                $this->logger->err('Verificación email - El código no existe ', ['ip' => Functions::getUserIP()]);
1644
                $this->logger->err('Verificación email - El código no existe ', ['ip' => Functions::getUserIP()]);
1617
 
1645
 
1618
                $response = [
-
 
1619
                    'success' => false,
-
 
1620
                    'data' =>'ERROR_ACTIVATION_CODE_IS_NOT_VALID'
-
 
1621
                ];
-
 
Línea -... Línea 1646...
-
 
1646
                $response = [
1622
                
1647
                    'success' => false,
1623
                return new JsonModel($response);
-
 
1624
                
-
 
1625
                
1648
                    'data' => 'ERROR_ACTIVATION_CODE_IS_NOT_VALID'
1626
 
1649
                ];
1627
            }
1650
 
1628
 
1651
                return new JsonModel($response);
1629
          
1652
            }
1630
        } else {
1653
        } else {
Línea 1631... Línea 1654...
1631
            $response = [
1654
            $response = [
1632
                'success' => false,
1655
                'success' => false,
1633
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1656
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1634
            ];
1657
            ];
1635
        }
1658
        }
1636
 
1659
 
1637
        return new JsonModel($response);
1660
        return new JsonModel($response);
1638
    }
1661
    }
1639
    
1662
 
1640
    public function onroomAction()
1663
    public function onroomAction()
1641
    {
1664
    {
1642
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1665
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1643
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1666
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1644
        
1667
 
1645
        
1668
 
1646
        
1669
 
1647
        $request = $this->getRequest();
1670
        $request = $this->getRequest();
1648
        
1671
 
1649
        if ($request->isPost()) {
1672
        if ($request->isPost()) {
1650
            
1673
 
1651
            $dataPost = $request->getPost()->toArray();
1674
            $dataPost = $request->getPost()->toArray();
1652
            
1675
 
1653
            
1676
 
1654
            $form = new  MoodleForm();
1677
            $form = new  MoodleForm();
1655
            $form->setData($dataPost);
1678
            $form->setData($dataPost);
1656
            if ($form->isValid()) {
1679
            if ($form->isValid()) {
1657
                
1680
 
1658
                $dataPost   = (array) $form->getData();
1681
                $dataPost   = (array) $form->getData();
1659
                $username   = $dataPost['username'];
1682
                $username   = $dataPost['username'];
1660
                $password   = $dataPost['password'];
1683
                $password   = $dataPost['password'];
1661
                $timestamp  = $dataPost['timestamp'];
1684
                $timestamp  = $dataPost['timestamp'];
1662
                $rand       = $dataPost['rand'];
1685
                $rand       = $dataPost['rand'];
1663
                $data       = $dataPost['data'];
1686
                $data       = $dataPost['data'];
1664
                
1687
 
1665
                $config_username    = $this->config['leaderslinked.moodle.username'];
1688
                $config_username    = $this->config['leaderslinked.moodle.username'];
1666
                $config_password    = $this->config['leaderslinked.moodle.password'];
1689
                $config_password    = $this->config['leaderslinked.moodle.password'];
1667
                $config_rsa_n       = $this->config['leaderslinked.moodle.rsa_n'];
1690
                $config_rsa_n       = $this->config['leaderslinked.moodle.rsa_n'];
1668
                $config_rsa_d       = $this->config['leaderslinked.moodle.rsa_d'];
1691
                $config_rsa_d       = $this->config['leaderslinked.moodle.rsa_d'];
1669
                $config_rsa_e       = $this->config['leaderslinked.moodle.rsa_e'];
1692
                $config_rsa_e       = $this->config['leaderslinked.moodle.rsa_e'];
1670
                
1693
 
1671
                
1694
 
1672
                
1695
 
1673
                
1696
 
1674
                if (empty($username) || empty($password) || empty($timestamp) || empty($rand) || !is_integer($rand)) {
1697
                if (empty($username) || empty($password) || empty($timestamp) || empty($rand) || !is_integer($rand)) {
1675
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY1']);
1698
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY1']);
1676
                    exit;
1699
                    exit;
1677
                }
1700
                }
1678
                
1701
 
1679
                if ($username != $config_username) {
1702
                if ($username != $config_username) {
1680
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY2']);
1703
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY2']);
1681
                    exit;
1704
                    exit;
1682
                }
1705
                }
1683
                
1706
 
1684
                $dt = \DateTime::createFromFormat('Y-m-d\TH:i:s', $timestamp);
1707
                $dt = \DateTime::createFromFormat('Y-m-d\TH:i:s', $timestamp);
1685
                if (!$dt) {
1708
                if (!$dt) {
1686
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY3']);
1709
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY3']);
1687
                    exit;
1710
                    exit;
1688
                }
1711
                }
1689
                
1712
 
1690
                $t0 = $dt->getTimestamp();
1713
                $t0 = $dt->getTimestamp();
1691
                $t1 = strtotime('-5 minutes');
1714
                $t1 = strtotime('-5 minutes');
1692
                $t2 = strtotime('+5 minutes');
1715
                $t2 = strtotime('+5 minutes');
1693
                
1716
 
1694
                if ($t0 < $t1 || $t0 > $t2) {
1717
                if ($t0 < $t1 || $t0 > $t2) {
1695
                    //echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
1718
                    //echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
1696
                    //exit;
1719
                    //exit;
1697
                }
1720
                }
1698
                
1721
 
1699
                if (!password_verify($username . '-' . $config_password . '-' . $rand . '-' . $timestamp, $password)) {
1722
                if (!password_verify($username . '-' . $config_password . '-' . $rand . '-' . $timestamp, $password)) {
1700
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY5']);
1723
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY5']);
1701
                    exit;
1724
                    exit;
1702
                }
1725
                }
1703
                
1726
 
1704
                if (empty($data)) {
1727
                if (empty($data)) {
1705
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS1']);
1728
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS1']);
1706
                    exit;
1729
                    exit;
1707
                }
1730
                }
1708
                
1731
 
1709
                $data = base64_decode($data);
1732
                $data = base64_decode($data);
1710
                if (empty($data)) {
1733
                if (empty($data)) {
1711
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS2']);
1734
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS2']);
1712
                    exit;
1735
                    exit;
1713
                }
1736
                }
1714
                
1737
 
1715
                
1738
 
1716
                try {
1739
                try {
1717
                    $rsa = Rsa::getInstance();
1740
                    $rsa = Rsa::getInstance();
1718
                    $data = $rsa->decrypt($data,  $config_rsa_d,  $config_rsa_n);
1741
                    $data = $rsa->decrypt($data,  $config_rsa_d,  $config_rsa_n);
1719
                } catch (\Throwable $e) {
1742
                } catch (\Throwable $e) {
1720
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS3']);
1743
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS3']);
1721
                    exit;
1744
                    exit;
1722
                }
1745
                }
1723
                
1746
 
1724
                $data = (array) json_decode($data);
1747
                $data = (array) json_decode($data);
1725
                if (empty($data)) {
1748
                if (empty($data)) {
1726
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS4']);
1749
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS4']);
1727
                    exit;
1750
                    exit;
1728
                }
1751
                }
1729
                
1752
 
1730
                $email      = isset($data['email']) ? Functions::sanitizeFilterString($data['email']) : '';
1753
                $email      = isset($data['email']) ? Functions::sanitizeFilterString($data['email']) : '';
1731
                $first_name = isset($data['first_name']) ? Functions::sanitizeFilterString($data['first_name']) : '';
1754
                $first_name = isset($data['first_name']) ? Functions::sanitizeFilterString($data['first_name']) : '';
1732
                $last_name  = isset($data['last_name']) ? Functions::sanitizeFilterString($data['last_name']) : '';
1755
                $last_name  = isset($data['last_name']) ? Functions::sanitizeFilterString($data['last_name']) : '';
1733
                
1756
 
1734
                if (!filter_var($email, FILTER_VALIDATE_EMAIL) || empty($first_name) || empty($last_name)) {
1757
                if (!filter_var($email, FILTER_VALIDATE_EMAIL) || empty($first_name) || empty($last_name)) {
1735
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS5']);
1758
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS5']);
1736
                    exit;
1759
                    exit;
1737
                }
1760
                }
1738
                
1761
 
1739
                $userMapper = UserMapper::getInstance($this->adapter);
1762
                $userMapper = UserMapper::getInstance($this->adapter);
1740
                $user = $userMapper->fetchOneByEmail($email);
1763
                $user = $userMapper->fetchOneByEmail($email);
1741
                if (!$user) {
1764
                if (!$user) {
1742
                    
1765
 
Línea 1751... Línea 1774...
1751
                    $user->login_attempt = 0;
1774
                    $user->login_attempt = 0;
1752
                    $user->password = '-NO-PASSWORD-';
1775
                    $user->password = '-NO-PASSWORD-';
1753
                    $user->usertype_id = UserType::USER;
1776
                    $user->usertype_id = UserType::USER;
1754
                    $user->status = User::STATUS_ACTIVE;
1777
                    $user->status = User::STATUS_ACTIVE;
1755
                    $user->show_in_search = User::SHOW_IN_SEARCH_YES;
1778
                    $user->show_in_search = User::SHOW_IN_SEARCH_YES;
1756
                    
1779
 
1757
                    if ($userMapper->insert($user)) {
1780
                    if ($userMapper->insert($user)) {
1758
                        echo json_encode(['success' => false, 'data' => $userMapper->getError()]);
1781
                        echo json_encode(['success' => false, 'data' => $userMapper->getError()]);
1759
                        exit;
1782
                        exit;
1760
                    }
1783
                    }
1761
                    
1784
 
1762
                    $user = $userMapper->fetchOne($user->id);
1785
                    $user = $userMapper->fetchOne($user->id);
1763
                    
1786
 
1764
                    
1787
 
1765
                    
1788
 
1766
                    
1789
 
1767
                    $filename   = trim(isset($data['avatar_filename']) ? filter_var($data['avatar_filename'], FILTER_SANITIZE_EMAIL) : '');
1790
                    $filename   = trim(isset($data['avatar_filename']) ? filter_var($data['avatar_filename'], FILTER_SANITIZE_EMAIL) : '');
1768
                    $content    = isset($data['avatar_content']) ? Functions::sanitizeFilterString($data['avatar_content']) : '';
1791
                    $content    = isset($data['avatar_content']) ? Functions::sanitizeFilterString($data['avatar_content']) : '';
1769
                    
1792
 
1770
                    if ($filename && $content) {
1793
                    if ($filename && $content) {
1771
                        $source = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
1794
                        $source = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
1772
                        try {
1795
                        try {
1773
                            
1796
 
1774
                            
1797
 
1775
                            file_put_contents($source, base64_decode($content));
1798
                            file_put_contents($source, base64_decode($content));
1776
                            if (file_exists($source)) {
1799
                            if (file_exists($source)) {
1777
                                list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1800
                                list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1778
                                
1801
 
1779
                                $target_filename    = 'user-' . uniqid() . '.png';
1802
                                $target_filename    = 'user-' . uniqid() . '.png';
1780
                                $crop_to_dimensions = true;
1803
                                $crop_to_dimensions = true;
1781
                                
1804
 
1782
                                $image = Image::getInstance($this->config);
1805
                                $image = Image::getInstance($this->config);
1783
                                $target_path    = $image->getStorage()->getPathUser();
1806
                                $target_path    = $image->getStorage()->getPathUser();
1784
                                $unlink_source  = true;
1807
                                $unlink_source  = true;
1785
                                
1808
 
1786
                                
1809
 
1787
                                if (!$image->uploadProcessChangeSize($source, $target_path, $user->uuid, $target_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
1810
                                if (!$image->uploadProcessChangeSize($source, $target_path, $user->uuid, $target_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
1788
                                    return new JsonModel([
1811
                                    return new JsonModel([
1789
                                        'success'   => false,
1812
                                        'success'   => false,
1790
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1813
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1791
                                    ]);
1814
                                    ]);
1792
                                }
1815
                                }
1793
                                
1816
 
1794
                                $user->image = $target_filename;
1817
                                $user->image = $target_filename;
1795
                                $userMapper->updateImage($user);
1818
                                $userMapper->updateImage($user);
1796
                            }
1819
                            }
1797
                        } catch (\Throwable $e) {
1820
                        } catch (\Throwable $e) {
1798
                        } finally {
1821
                        } finally {
Línea 1800... Línea 1823...
1800
                                unlink($source);
1823
                                unlink($source);
1801
                            }
1824
                            }
1802
                        }
1825
                        }
1803
                    }
1826
                    }
1804
                }
1827
                }
1805
                
1828
 
1806
                $auth = new AuthEmailAdapter($this->adapter);
1829
                $auth = new AuthEmailAdapter($this->adapter);
1807
                $auth->setData($email);
1830
                $auth->setData($email);
1808
                
1831
 
1809
                $result = $auth->authenticate();
1832
                $result = $auth->authenticate();
1810
                if ($result->getCode() == AuthResult::SUCCESS) {
1833
                if ($result->getCode() == AuthResult::SUCCESS) {
1811
                    return $this->redirect()->toRoute('dashboard');
1834
                    return $this->redirect()->toRoute('dashboard');
1812
                } else {
1835
                } else {
1813
                    $message = $result->getMessages()[0];
1836
                    $message = $result->getMessages()[0];
1814
                    if (!in_array($message, [
1837
                    if (!in_array($message, [
-
 
1838
                        'ERROR_USER_NOT_FOUND',
1815
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
1839
                        'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED',
-
 
1840
                        'ERROR_USER_IS_BLOCKED',
-
 
1841
                        'ERROR_USER_IS_INACTIVE',
1816
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
1842
                        'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED',
-
 
1843
                        'ERROR_ENTERED_PASS_INCORRECT_2',
1817
                        'ERROR_ENTERED_PASS_INCORRECT_1'
1844
                        'ERROR_ENTERED_PASS_INCORRECT_1'
1818
                    ])) {
1845
                    ])) {
1819
                    }
1846
                    }
1820
                    
1847
 
1821
                    switch ($message) {
1848
                    switch ($message) {
1822
                        case 'ERROR_USER_NOT_FOUND':
1849
                        case 'ERROR_USER_NOT_FOUND':
1823
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
1850
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
1824
                            break;
1851
                            break;
1825
                            
1852
 
1826
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
1853
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
1827
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
1854
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
1828
                            break;
1855
                            break;
1829
                            
1856
 
1830
                        case 'ERROR_USER_IS_BLOCKED':
1857
                        case 'ERROR_USER_IS_BLOCKED':
1831
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1858
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1832
                            break;
1859
                            break;
1833
                            
1860
 
1834
                        case 'ERROR_USER_IS_INACTIVE':
1861
                        case 'ERROR_USER_IS_INACTIVE':
1835
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
1862
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
1836
                            break;
1863
                            break;
1837
                            
1864
 
1838
                            
1865
 
1839
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
1866
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
1840
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1867
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1841
                            break;
1868
                            break;
1842
                            
1869
 
1843
                            
1870
 
1844
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
1871
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
1845
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
1872
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
1846
                            break;
1873
                            break;
1847
                            
1874
 
1848
                            
1875
 
1849
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
1876
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
1850
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
1877
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
1851
                            break;
1878
                            break;
1852
                            
1879
 
1853
                            
1880
 
1854
                        default:
1881
                        default:
1855
                            $message = 'ERROR_UNKNOWN';
1882
                            $message = 'ERROR_UNKNOWN';
1856
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
1883
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
1857
                            break;
1884
                            break;
1858
                    }
1885
                    }
1859
                    
1886
 
1860
                    
1887
 
1861
                    
1888
 
1862
                    
1889
 
1863
                    return new JsonModel([
1890
                    return new JsonModel([
1864
                        'success'   => false,
1891
                        'success'   => false,
1865
                        'data'   => $message
1892
                        'data'   => $message
1866
                    ]);
1893
                    ]);
1867
                }
1894
                }
1868
            } else {
1895
            } else {
1869
                $messages = [];
1896
                $messages = [];
1870
                
1897
 
1871
                
1898
 
1872
                
1899
 
1873
                $form_messages = (array) $form->getMessages();
1900
                $form_messages = (array) $form->getMessages();
1874
                foreach ($form_messages  as $fieldname => $field_messages) {
1901
                foreach ($form_messages  as $fieldname => $field_messages) {
1875
                    
1902
 
1876
                    $messages[$fieldname] = array_values($field_messages);
1903
                    $messages[$fieldname] = array_values($field_messages);
1877
                }
1904
                }
1878
                
1905
 
1879
                return new JsonModel([
1906
                return new JsonModel([
1880
                    'success'   => false,
1907
                    'success'   => false,
1881
                    'data'   => $messages
1908
                    'data'   => $messages
1882
                ]);
1909
                ]);
1883
            }
1910
            }
1884
        } else {
1911
        } else {
1885
            $data = [
1912
            $data = [
1886
                'success' => false,
1913
                'success' => false,
1887
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1914
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1888
            ];
1915
            ];
1889
            
1916
 
1890
            return new JsonModel($data);
1917
            return new JsonModel($data);
1891
        }
1918
        }
1892
        
1919
 
1893
        return new JsonModel($data);
1920
        return new JsonModel($data);
1894
    }
1921
    }
Línea 1941... Línea 1968...
1941
                }
1968
                }
Línea 1942... Línea 1969...
1942
 
1969
 
1943
                $dt = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s',  gmdate('Y-m-d\TH:i:s'));
1970
                $dt = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s',  gmdate('Y-m-d\TH:i:s'));
1944
                $dtMax = $dt->add(\DateInterval::createFromDateString('5 minutes'));
1971
                $dtMax = $dt->add(\DateInterval::createFromDateString('5 minutes'));
1945
                $dtMin = $dt->sub(\DateInterval::createFromDateString('5 minutes'));
1972
                $dtMin = $dt->sub(\DateInterval::createFromDateString('5 minutes'));
1946
                
1973
 
1947
                
1974
 
1948
                $t0 = $dt->getTimestamp();
1975
                $t0 = $dt->getTimestamp();
1949
                $t1 = $dtMin->getTimestamp();
1976
                $t1 = $dtMin->getTimestamp();
1950
                $t2 = $dtMax->getTimestamp();
1977
                $t2 = $dtMax->getTimestamp();
1951
                if ($t0 < $t1 || $t0 > $t2) {
1978
                if ($t0 < $t1 || $t0 > $t2) {
1952
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
1979
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']);
1953
                    exit;
1980
                    exit;
Línea 1954... Línea 1981...
1954
                }
1981
                }
1955
 
1982
 
Línea 2012... Línea 2039...
2012
 
2039
 
2013
                    if ($userMapper->insert($user)) {
2040
                    if ($userMapper->insert($user)) {
2014
                        echo json_encode(['success' => false, 'data' => $userMapper->getError()]);
2041
                        echo json_encode(['success' => false, 'data' => $userMapper->getError()]);
2015
                        exit;
2042
                        exit;
2016
                    }
2043
                    }
2017
                    
2044
 
2018
                    $user = $userMapper->fetchOne($user->id);
2045
                    $user = $userMapper->fetchOne($user->id);
2019
                    
2046
 
2020
                    $userPassword = new UserPassword();
2047
                    $userPassword = new UserPassword();
2021
                    $userPassword->user_id = $user->id;
2048
                    $userPassword->user_id = $user->id;
2022
                    $userPassword->password = password_hash($password, PASSWORD_DEFAULT);
2049
                    $userPassword->password = password_hash($password, PASSWORD_DEFAULT);
2023
                    
2050
 
2024
                    $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
2051
                    $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
2025
                    $userPasswordMapper->insert($userPassword);
2052
                    $userPasswordMapper->insert($userPassword);
2026
                    
2053
 
2027
                    $userDefaultForConnection = $userMapper->fetchOneDefaultForConnection();
2054
                    $userDefaultForConnection = $userMapper->fetchOneDefaultForConnection();
2028
                    if($userDefaultForConnection) {
2055
                    if ($userDefaultForConnection) {
2029
                    
2056
 
2030
                        $connection = new Connection();
2057
                        $connection = new Connection();
2031
                        $connection->request_from = $userDefaultForConnection->id; 
2058
                        $connection->request_from = $userDefaultForConnection->id;
2032
                        $connection->request_to = $user->id;
2059
                        $connection->request_to = $user->id;
2033
                        $connection->status = Connection::STATUS_ACCEPTED;
2060
                        $connection->status = Connection::STATUS_ACCEPTED;
2034
                        
2061
 
2035
                        $connectionMapper = ConnectionMapper::getInstance($this->adapter);
2062
                        $connectionMapper = ConnectionMapper::getInstance($this->adapter);
2036
                        $connectionMapper->insert($connection);
2063
                        $connectionMapper->insert($connection);
2037
                    }
2064
                    }
Línea 2038... Línea 2065...
2038
                }
2065
                }
2039
 
2066
 
2040
                return new JsonModel([
2067
                return new JsonModel([
2041
                    'success'   => true,
2068
                    'success'   => true,
2042
                    'data'   => $user->uuid
-
 
2043
                ]);
2069
                    'data'   => $user->uuid
2044
        
2070
                ]);
Línea 2072... Línea 2098...
2072
 
2098
 
2073
    public function csrfAction()
2099
    public function csrfAction()
2074
    {
2100
    {
2075
        $request = $this->getRequest();
2101
        $request = $this->getRequest();
2076
        if ($request->isGet()) {
2102
        if ($request->isGet()) {
2077
            
2103
 
2078
            $jwtToken = null;
2104
            $jwtToken = null;
2079
            $headers = getallheaders();
2105
            $headers = getallheaders();
2080
            
2106
 
2081
 
2107
 
2082
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
2108
            if (!empty($headers['authorization']) || !empty($headers['Authorization'])) {
2083
                
2109
 
2084
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
2110
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
2085
                
2111
 
2086
                
2112
 
2087
                if (substr($token, 0, 6 ) == 'Bearer') {
2113
                if (substr($token, 0, 6) == 'Bearer') {
2088
                    
2114
 
2089
                    $token = trim(substr($token, 7));
2115
                    $token = trim(substr($token, 7));
2090
                    
2116
 
2091
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
2117
                    if (!empty($this->config['leaderslinked.jwt.key'])) {
2092
                        $key = $this->config['leaderslinked.jwt.key'];
2118
                        $key = $this->config['leaderslinked.jwt.key'];
2093
                        
2119
 
2094
                        
2120
 
2095
                        try {
2121
                        try {
2096
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
2122
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
2097
                            
2123
 
2098
                            
2124
 
2099
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
2125
                            if (empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
2100
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
2126
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
2101
                            }
2127
                            }
2102
                            
2128
 
2103
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
2129
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
2104
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2130
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2105
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
2131
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
2106
                            if(!$jwtToken) {
2132
                            if (!$jwtToken) {
2107
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
2133
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
2108
                            }
-
 
2109
                            
2134
                            }
2110
                        } catch(\Exception $e) {
2135
                        } catch (\Exception $e) {
2111
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
2136
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
2112
                        }
2137
                        }
2113
                    } else {
2138
                    } else {
2114
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
2139
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
Línea 2117... Línea 2142...
2117
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
2142
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
2118
                }
2143
                }
2119
            } else {
2144
            } else {
2120
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
2145
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
2121
            }
2146
            }
2122
            
2147
 
2123
            $jwtToken->csrf = md5(uniqid('CSFR-' . mt_rand(), true));
2148
            $jwtToken->csrf = md5(uniqid('CSFR-' . mt_rand(), true));
2124
            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2149
            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2125
            $jwtTokenMapper->update($jwtToken);
2150
            $jwtTokenMapper->update($jwtToken);
2126
             
2151
 
2127
            
2152
 
2128
           // error_log('token id = ' . $jwtToken->id . ' csrf = ' . $jwtToken->csrf);
2153
            // error_log('token id = ' . $jwtToken->id . ' csrf = ' . $jwtToken->csrf);
Línea 2129... Línea 2154...
2129
 
2154
 
2130
 
2155
 
2131
            return new JsonModel([
2156
            return new JsonModel([
Línea 2176... Línea 2201...
2176
        return new JsonModel([
2201
        return new JsonModel([
2177
            'success' => false,
2202
            'success' => false,
2178
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2203
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2179
        ]);
2204
        ]);
2180
    }
2205
    }
2181
    
2206
 
2182
    
2207
 
2183
    
2208
 
2184
    public function debugAction()
2209
    public function debugAction()
2185
    {
2210
    {
2186
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2211
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2187
        $currentNetwork = $currentNetworkPlugin->getNetwork();
2212
        $currentNetwork = $currentNetworkPlugin->getNetwork();
2188
        
2213
 
2189
        $request = $this->getRequest();
2214
        $request = $this->getRequest();
2190
        
2215
 
2191
        if ($request->isPost()) {
2216
        if ($request->isPost()) {
2192
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2217
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2193
            $currentNetwork = $currentNetworkPlugin->getNetwork();
2218
            $currentNetwork = $currentNetworkPlugin->getNetwork();
2194
            
2219
 
2195
            $jwtToken = null;
2220
            $jwtToken = null;
2196
            $headers = getallheaders();
2221
            $headers = getallheaders();
2197
            
2222
 
2198
            
2223
 
2199
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
2224
            if (!empty($headers['authorization']) || !empty($headers['Authorization'])) {
2200
                
2225
 
2201
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
2226
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
2202
                
2227
 
2203
                
2228
 
2204
                if (substr($token, 0, 6 ) == 'Bearer') {
2229
                if (substr($token, 0, 6) == 'Bearer') {
2205
                    
2230
 
2206
                    $token = trim(substr($token, 7));
2231
                    $token = trim(substr($token, 7));
2207
                    
2232
 
2208
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
2233
                    if (!empty($this->config['leaderslinked.jwt.key'])) {
2209
                        $key = $this->config['leaderslinked.jwt.key'];
2234
                        $key = $this->config['leaderslinked.jwt.key'];
2210
                        
2235
 
2211
                        
2236
 
2212
                        try {
2237
                        try {
2213
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
2238
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
2214
                            
2239
 
2215
                            
2240
 
2216
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
2241
                            if (empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
2217
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
2242
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
2218
                            }
2243
                            }
2219
                            
2244
 
2220
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
2245
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
2221
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2246
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2222
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
2247
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
2223
                            if(!$jwtToken) {
2248
                            if (!$jwtToken) {
2224
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
2249
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
2225
                            }
2250
                            }
2226
                            
-
 
2227
                        } catch(\Exception $e) {
2251
                        } catch (\Exception $e) {
2228
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
2252
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
2229
                        }
2253
                        }
2230
                    } else {
2254
                    } else {
2231
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
2255
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
2232
                    }
2256
                    }
Línea 2234... Línea 2258...
2234
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
2258
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
2235
                }
2259
                }
2236
            } else {
2260
            } else {
2237
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
2261
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
2238
            }
2262
            }
2239
            
2263
 
2240
            
2264
 
2241
            
2265
 
2242
            $form = new  SigninDebugForm($this->config);
2266
            $form = new  SigninDebugForm($this->config);
2243
            $dataPost = $request->getPost()->toArray();
2267
            $dataPost = $request->getPost()->toArray();
2244
            
2268
 
2245
            if (empty($_SESSION['aes'])) {
2269
            if (empty($_SESSION['aes'])) {
2246
                return new JsonModel([
2270
                return new JsonModel([
2247
                    'success'   => false,
2271
                    'success'   => false,
2248
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
2272
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
2249
                ]);
2273
                ]);
2250
            }
2274
            }
2251
            
2275
 
2252
            error_log(print_r($dataPost, true));
2276
            error_log(print_r($dataPost, true));
2253
            
2277
 
2254
            $aes = $_SESSION['aes'];
2278
            $aes = $_SESSION['aes'];
2255
            error_log('aes : ' . $aes);
2279
            error_log('aes : ' . $aes);
2256
            
2280
 
2257
            
2281
 
2258
            unset( $_SESSION['aes'] );
2282
            unset($_SESSION['aes']);
2259
            
2283
 
2260
            if (!empty($dataPost['email'])) {
2284
            if (!empty($dataPost['email'])) {
2261
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $aes);
2285
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $aes);
2262
            }
2286
            }
2263
            
2287
 
2264
            
2288
 
2265
            if (!empty($dataPost['password'])) {
2289
            if (!empty($dataPost['password'])) {
2266
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $aes);
2290
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $aes);
2267
            }
2291
            }
2268
            
2292
 
2269
            
2293
 
2270
            error_log(print_r($dataPost, true));
2294
            error_log(print_r($dataPost, true));
2271
            
2295
 
2272
            $form->setData($dataPost);
2296
            $form->setData($dataPost);
2273
            
2297
 
2274
            if ($form->isValid()) {
2298
            if ($form->isValid()) {
2275
                
2299
 
2276
                $dataPost = (array) $form->getData();
2300
                $dataPost = (array) $form->getData();
2277
                
2301
 
2278
                
2302
 
2279
                $email      = $dataPost['email'];
2303
                $email      = $dataPost['email'];
2280
                $password   = $dataPost['password'];
2304
                $password   = $dataPost['password'];
2281
                
2305
 
2282
                
2306
 
2283
                
2307
 
2284
                
2308
 
2285
                
2309
 
2286
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
2310
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
2287
                $authAdapter->setData($email, $password, $currentNetwork->id);
2311
                $authAdapter->setData($email, $password, $currentNetwork->id);
2288
                $authService = new AuthenticationService();
2312
                $authService = new AuthenticationService();
2289
                
2313
 
2290
                $result = $authService->authenticate($authAdapter);
2314
                $result = $authService->authenticate($authAdapter);
2291
                
2315
 
2292
                if ($result->getCode() == AuthResult::SUCCESS) {
2316
                if ($result->getCode() == AuthResult::SUCCESS) {
2293
                    
2317
 
2294
                    $identity = $result->getIdentity();
2318
                    $identity = $result->getIdentity();
2295
                    
2319
 
2296
                    
2320
 
2297
                    $userMapper = UserMapper::getInstance($this->adapter);
2321
                    $userMapper = UserMapper::getInstance($this->adapter);
2298
                    $user = $userMapper->fetchOne($identity['user_id']);
2322
                    $user = $userMapper->fetchOne($identity['user_id']);
2299
                    
2323
 
2300
                    
2324
 
2301
                    if($token) {
2325
                    if ($token) {
2302
                        $jwtToken->user_id = $user->id;
2326
                        $jwtToken->user_id = $user->id;
2303
                        $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2327
                        $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2304
                        $jwtTokenMapper->update($jwtToken);
2328
                        $jwtTokenMapper->update($jwtToken);
2305
                    }
2329
                    }
2306
                    
2330
 
2307
                    
2331
 
2308
                    $navigator = get_browser(null, true);
2332
                    $navigator = get_browser(null, true);
2309
                    $device_type    =  isset($navigator['device_type']) ? $navigator['device_type'] : '';
2333
                    $device_type    =  isset($navigator['device_type']) ? $navigator['device_type'] : '';
2310
                    $platform       =  isset($navigator['platform']) ? $navigator['platform'] : '';
2334
                    $platform       =  isset($navigator['platform']) ? $navigator['platform'] : '';
2311
                    $browser        =  isset($navigator['browser']) ? $navigator['browser'] : '';
2335
                    $browser        =  isset($navigator['browser']) ? $navigator['browser'] : '';
2312
                    
2336
 
2313
                    
2337
 
2314
                    $istablet = isset($navigator['istablet']) ?  intval($navigator['istablet']) : 0;
2338
                    $istablet = isset($navigator['istablet']) ?  intval($navigator['istablet']) : 0;
2315
                    $ismobiledevice = isset($navigator['ismobiledevice']) ? intval($navigator['ismobiledevice']) : 0;
2339
                    $ismobiledevice = isset($navigator['ismobiledevice']) ? intval($navigator['ismobiledevice']) : 0;
2316
                    $version = isset($navigator['version']) ? $navigator['version'] : '';
2340
                    $version = isset($navigator['version']) ? $navigator['version'] : '';
2317
                    
2341
 
2318
                    
2342
 
2319
                    $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
2343
                    $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
2320
                    $userBrowser = $userBrowserMapper->fetch($user->id, $device_type, $platform, $browser);
2344
                    $userBrowser = $userBrowserMapper->fetch($user->id, $device_type, $platform, $browser);
2321
                    if ($userBrowser) {
2345
                    if ($userBrowser) {
2322
                        $userBrowserMapper->update($userBrowser);
2346
                        $userBrowserMapper->update($userBrowser);
2323
                    } else {
2347
                    } else {
Línea 2327... Línea 2351...
2327
                        $userBrowser->platform          = $platform;
2351
                        $userBrowser->platform          = $platform;
2328
                        $userBrowser->device_type       = $device_type;
2352
                        $userBrowser->device_type       = $device_type;
2329
                        $userBrowser->is_tablet         = $istablet;
2353
                        $userBrowser->is_tablet         = $istablet;
2330
                        $userBrowser->is_mobile_device  = $ismobiledevice;
2354
                        $userBrowser->is_mobile_device  = $ismobiledevice;
2331
                        $userBrowser->version           = $version;
2355
                        $userBrowser->version           = $version;
2332
                        
2356
 
2333
                        $userBrowserMapper->insert($userBrowser);
2357
                        $userBrowserMapper->insert($userBrowser);
2334
                    }
2358
                    }
2335
                    //
2359
                    //
2336
                    
2360
 
2337
                    $ip = Functions::getUserIP();
2361
                    $ip = Functions::getUserIP();
2338
                    $ip = $ip == '127.0.0.1' ? '148.240.211.148' : $ip;
2362
                    $ip = $ip == '127.0.0.1' ? '148.240.211.148' : $ip;
2339
                    
2363
 
2340
                    $userIpMapper = UserIpMapper::getInstance($this->adapter);
2364
                    $userIpMapper = UserIpMapper::getInstance($this->adapter);
2341
                    $userIp = $userIpMapper->fetch($user->id, $ip);
2365
                    $userIp = $userIpMapper->fetch($user->id, $ip);
2342
                    if (empty($userIp)) {
2366
                    if (empty($userIp)) {
2343
                        
2367
 
2344
                        if ($this->config['leaderslinked.runmode.sandbox']) {
2368
                        if ($this->config['leaderslinked.runmode.sandbox']) {
2345
                            $filename = $this->config['leaderslinked.geoip2.production_database'];
2369
                            $filename = $this->config['leaderslinked.geoip2.production_database'];
2346
                        } else {
2370
                        } else {
2347
                            $filename = $this->config['leaderslinked.geoip2.sandbox_database'];
2371
                            $filename = $this->config['leaderslinked.geoip2.sandbox_database'];
2348
                        }
2372
                        }
2349
                        
2373
 
2350
                        $reader = new GeoIp2Reader($filename); //GeoIP2-City.mmdb');
2374
                        $reader = new GeoIp2Reader($filename); //GeoIP2-City.mmdb');
2351
                        $record = $reader->city($ip);
2375
                        $record = $reader->city($ip);
2352
                        if ($record) {
2376
                        if ($record) {
2353
                            $userIp = new UserIp();
2377
                            $userIp = new UserIp();
2354
                            $userIp->user_id = $user->id;
2378
                            $userIp->user_id = $user->id;
Línea 2359... Línea 2383...
2359
                            $userIp->country_name = !empty($record->country->name) ? Functions::utf8_decode($record->country->name) : '';
2383
                            $userIp->country_name = !empty($record->country->name) ? Functions::utf8_decode($record->country->name) : '';
2360
                            $userIp->ip = $ip;
2384
                            $userIp->ip = $ip;
2361
                            $userIp->latitude = !empty($record->location->latitude) ? $record->location->latitude : 0;
2385
                            $userIp->latitude = !empty($record->location->latitude) ? $record->location->latitude : 0;
2362
                            $userIp->longitude = !empty($record->location->longitude) ? $record->location->longitude : 0;
2386
                            $userIp->longitude = !empty($record->location->longitude) ? $record->location->longitude : 0;
2363
                            $userIp->postal_code = !empty($record->postal->code) ? $record->postal->code : '';
2387
                            $userIp->postal_code = !empty($record->postal->code) ? $record->postal->code : '';
2364
                            
2388
 
2365
                            $userIpMapper->insert($userIp);
2389
                            $userIpMapper->insert($userIp);
2366
                        }
2390
                        }
2367
                    } else {
2391
                    } else {
2368
                        $userIpMapper->update($userIp);
2392
                        $userIpMapper->update($userIp);
2369
                    }
2393
                    }
2370
                    
2394
 
2371
                    /*
2395
                    /*
2372
                     if ($remember) {
2396
                     if ($remember) {
2373
                     $expired = time() + 365 * 24 * 60 * 60;
2397
                     $expired = time() + 365 * 24 * 60 * 60;
Línea 2374... Línea 2398...
2374
                     
2398
                     
Línea 2380... Línea 2404...
2380
                     
2404
                     
2381
                     
2405
                     
2382
                     $response = $this->getResponse();
2406
                     $response = $this->getResponse();
2383
                     $response->getHeaders()->addHeader($cookieEmail);
2407
                     $response->getHeaders()->addHeader($cookieEmail);
2384
                     */
2408
                     */
2385
                    
2409
 
2386
                    
2410
 
2387
                    
2411
 
2388
                    
2412
 
2389
                    
2413
 
2390
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
2414
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
2391
                    
2415
 
2392
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
2416
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
2393
                    
2417
 
2394
                    $url =  $this->url()->fromRoute('dashboard');
2418
                    $url =  $this->url()->fromRoute('dashboard');
2395
                    
2419
 
2396
                    if ($user_share_invitation && is_array($user_share_invitation)) {
2420
                    if ($user_share_invitation && is_array($user_share_invitation)) {
2397
                        
2421
 
2398
                        $content_uuid = $user_share_invitation['code'];
2422
                        $content_uuid = $user_share_invitation['code'];
2399
                        $content_type = $user_share_invitation['type'];
2423
                        $content_type = $user_share_invitation['type'];
2400
                        $content_user = $user_share_invitation['user'];
2424
                        $content_user = $user_share_invitation['user'];
2401
                        
2425
 
2402
                        
2426
 
2403
                        
2427
 
2404
                        $userRedirect = $userMapper->fetchOneByUuid($content_user);
2428
                        $userRedirect = $userMapper->fetchOneByUuid($content_user);
2405
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
2429
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
2406
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
2430
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
2407
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
2431
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
2408
                            
2432
 
2409
                            if ($connection) {
2433
                            if ($connection) {
2410
                                
2434
 
2411
                                if ($connection->status != Connection::STATUS_ACCEPTED) {
2435
                                if ($connection->status != Connection::STATUS_ACCEPTED) {
2412
                                    $connectionMapper->approve($connection);
2436
                                    $connectionMapper->approve($connection);
2413
                                }
2437
                                }
2414
                            } else {
2438
                            } else {
2415
                                $connection = new Connection();
2439
                                $connection = new Connection();
2416
                                $connection->request_from = $user->id;
2440
                                $connection->request_from = $user->id;
2417
                                $connection->request_to = $userRedirect->id;
2441
                                $connection->request_to = $userRedirect->id;
2418
                                $connection->status = Connection::STATUS_ACCEPTED;
2442
                                $connection->status = Connection::STATUS_ACCEPTED;
2419
                                
2443
 
2420
                                $connectionMapper->insert($connection);
2444
                                $connectionMapper->insert($connection);
2421
                            }
2445
                            }
2422
                        }
2446
                        }
2423
                        
2447
 
2424
                        if($content_type == 'feed') {
-
 
2425
                            $url = $this->url()->fromRoute('dashboard', ['feed' => $content_uuid ]);
-
 
2426
                            
2448
                        if ($content_type == 'feed') {
2427
                        }
2449
                            $url = $this->url()->fromRoute('dashboard', ['feed' => $content_uuid]);
2428
                        else if($content_type == 'post') {
-
 
2429
                            $url = $this->url()->fromRoute('post', ['id' => $content_uuid ]);
2450
                        } else if ($content_type == 'post') {
2430
                        }
2451
                            $url = $this->url()->fromRoute('post', ['id' => $content_uuid]);
2431
                        else {
2452
                        } else {
2432
                            $url = $this->url()->fromRoute('dashboard');
-
 
2433
                        }
2453
                            $url = $this->url()->fromRoute('dashboard');
2434
                        
2454
                        }
2435
                    }
2455
                    }
2436
                    
2456
 
2437
                    
2457
 
2438
                    $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
2458
                    $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
2439
                    
2459
 
2440
                    $networkMapper = NetworkMapper::getInstance($this->adapter);
2460
                    $networkMapper = NetworkMapper::getInstance($this->adapter);
2441
                    $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
2461
                    $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
2442
                    
2462
 
2443
                    if(!$network) {
2463
                    if (!$network) {
2444
                        $network = $networkMapper->fetchOneByDefault();
2464
                        $network = $networkMapper->fetchOneByDefault();
2445
                    }
2465
                    }
2446
                    
2466
 
2447
                    $hostname = trim($network->main_hostname);
2467
                    $hostname = trim($network->main_hostname);
2448
                    $url = 'https://' . $hostname . $url;
2468
                    $url = 'https://' . $hostname . $url;
2449
                    
2469
 
2450
                    
2470
 
2451
                    $data = [
2471
                    $data = [
2452
                        'redirect'  => $url,
2472
                        'redirect'  => $url,
2453
                        'uuid'      => $user->uuid,
2473
                        'uuid'      => $user->uuid,
2454
                    ];
2474
                    ];
2455
                    
2475
 
2456
                    
2476
 
2457
                    
2477
 
2458
                    
2478
 
2459
                    if($currentNetwork->xmpp_active) {
2479
                    if ($currentNetwork->xmpp_active) {
2460
                        $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
2480
                        $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
2461
                        $externalCredentials->getUserBy($user->id);
2481
                        $externalCredentials->getUserBy($user->id);
2462
                        
2482
 
2463
                        
2483
 
2464
                        $data['xmpp_domain'] = $currentNetwork->xmpp_domain;
2484
                        $data['xmpp_domain'] = $currentNetwork->xmpp_domain;
2465
                        $data['xmpp_hostname'] = $currentNetwork->xmpp_hostname;
2485
                        $data['xmpp_hostname'] = $currentNetwork->xmpp_hostname;
2466
                        $data['xmpp_port'] = $currentNetwork->xmpp_port;
2486
                        $data['xmpp_port'] = $currentNetwork->xmpp_port;
2467
                        $data['xmpp_username'] = $externalCredentials->getUsernameXmpp();
2487
                        $data['xmpp_username'] = $externalCredentials->getUsernameXmpp();
2468
                        $data['xmpp_pasword'] = $externalCredentials->getPasswordXmpp();
2488
                        $data['xmpp_pasword'] = $externalCredentials->getPasswordXmpp();
2469
                        $data['inmail_username'] = $externalCredentials->getUsernameInmail();
-
 
2470
                        $data['inmail_pasword'] = $externalCredentials->getPasswordInmail();
2489
                        $data['inmail_username'] = $externalCredentials->getUsernameInmail();
2471
                        
2490
                        $data['inmail_pasword'] = $externalCredentials->getPasswordInmail();
2472
                    }
2491
                    }
2473
                    
2492
 
2474
                    $data = [
2493
                    $data = [
2475
                        'success'   => true,
2494
                        'success'   => true,
2476
                        'data'      => $data
2495
                        'data'      => $data
2477
                    ];
2496
                    ];
2478
                    
2497
 
2479
                    
2498
 
2480
                    $this->cache->removeItem('user_share_invitation');
2499
                    $this->cache->removeItem('user_share_invitation');
2481
                } else {
2500
                } else {
2482
                    
2501
 
-
 
2502
                    $message = $result->getMessages()[0];
2483
                    $message = $result->getMessages()[0];
2503
                    if (!in_array($message, [
-
 
2504
                        'ERROR_USER_NOT_FOUND',
-
 
2505
                        'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED',
2484
                    if (!in_array($message, [
2506
                        'ERROR_USER_IS_BLOCKED',
-
 
2507
                        'ERROR_USER_IS_INACTIVE',
-
 
2508
                        'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED',
-
 
2509
                        'ERROR_ENTERED_PASS_INCORRECT_2',
2485
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
2510
                        'ERROR_ENTERED_PASS_INCORRECT_1',
2486
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
2511
                        'ERROR_USER_REQUEST_ACCESS_IS_PENDING',
2487
                        'ERROR_ENTERED_PASS_INCORRECT_1', 'ERROR_USER_REQUEST_ACCESS_IS_PENDING', 'ERROR_USER_REQUEST_ACCESS_IS_REJECTED'
2512
                        'ERROR_USER_REQUEST_ACCESS_IS_REJECTED'
2488
                        
2513
 
2489
                        
2514
 
2490
                    ])) {
2515
                    ])) {
2491
                    }
2516
                    }
2492
                    
2517
 
2493
                    switch ($message) {
2518
                    switch ($message) {
2494
                        case 'ERROR_USER_NOT_FOUND':
2519
                        case 'ERROR_USER_NOT_FOUND':
2495
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
2520
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
2496
                            break;
2521
                            break;
2497
                            
2522
 
2498
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
2523
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
2499
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
2524
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
2500
                            break;
2525
                            break;
2501
                            
2526
 
2502
                        case 'ERROR_USER_IS_BLOCKED':
2527
                        case 'ERROR_USER_IS_BLOCKED':
2503
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
2528
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
2504
                            break;
2529
                            break;
2505
                            
2530
 
2506
                        case 'ERROR_USER_IS_INACTIVE':
2531
                        case 'ERROR_USER_IS_INACTIVE':
2507
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
2532
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
2508
                            break;
2533
                            break;
2509
                            
2534
 
2510
                            
2535
 
2511
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
2536
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
2512
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
2537
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
2513
                            break;
2538
                            break;
2514
                            
2539
 
2515
                            
2540
 
2516
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
2541
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
2517
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
2542
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
2518
                            break;
2543
                            break;
2519
                            
2544
 
2520
                            
2545
 
2521
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
2546
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
2522
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
2547
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
2523
                            break;
2548
                            break;
2524
                            
2549
 
2525
                            
2550
 
2526
                        case 'ERROR_USER_REQUEST_ACCESS_IS_PENDING':
2551
                        case 'ERROR_USER_REQUEST_ACCESS_IS_PENDING':
2527
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Falta verificar que pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
2552
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Falta verificar que pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
2528
                            break;
2553
                            break;
2529
                            
2554
 
2530
                        case  'ERROR_USER_REQUEST_ACCESS_IS_REJECTED':
2555
                        case  'ERROR_USER_REQUEST_ACCESS_IS_REJECTED':
2531
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Rechazado por no pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
2556
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Rechazado por no pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
2532
                            break;
2557
                            break;
2533
                            
2558
 
2534
                            
2559
 
2535
                        default:
2560
                        default:
2536
                            $message = 'ERROR_UNKNOWN';
2561
                            $message = 'ERROR_UNKNOWN';
2537
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
2562
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
2538
                            break;
2563
                            break;
2539
                    }
2564
                    }
2540
                    
2565
 
2541
                    
2566
 
2542
                    
2567
 
2543
                    
2568
 
2544
                    $data = [
2569
                    $data = [
2545
                        'success'   => false,
2570
                        'success'   => false,
2546
                        'data'   => $message
2571
                        'data'   => $message
2547
                    ];
2572
                    ];
2548
                }
2573
                }
2549
                
2574
 
2550
                return new JsonModel($data);
2575
                return new JsonModel($data);
2551
            } else {
2576
            } else {
2552
                $messages = [];
2577
                $messages = [];
2553
                
2578
 
2554
                
2579
 
2555
                
2580
 
2556
                $form_messages = (array) $form->getMessages();
2581
                $form_messages = (array) $form->getMessages();
2557
                foreach ($form_messages  as $fieldname => $field_messages) {
2582
                foreach ($form_messages  as $fieldname => $field_messages) {
2558
                    
2583
 
2559
                    $messages[$fieldname] = array_values($field_messages);
2584
                    $messages[$fieldname] = array_values($field_messages);
2560
                }
2585
                }
2561
                
2586
 
2562
                return new JsonModel([
2587
                return new JsonModel([
2563
                    'success'   => false,
2588
                    'success'   => false,
2564
                    'data'   => $messages
2589
                    'data'   => $messages
2565
                ]);
2590
                ]);
2566
            }
2591
            }
2567
        } else if ($request->isGet()) {
2592
        } else if ($request->isGet()) {
2568
            
2593
 
2569
            $aes = '';
2594
            $aes = '';
2570
            $jwtToken = null;
2595
            $jwtToken = null;
2571
            $headers = getallheaders();
2596
            $headers = getallheaders();
2572
            
2597
 
2573
            
2598
 
2574
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
2599
            if (!empty($headers['authorization']) || !empty($headers['Authorization'])) {
2575
                
2600
 
2576
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
2601
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
2577
                
2602
 
2578
                
2603
 
2579
                if (substr($token, 0, 6 ) == 'Bearer') {
2604
                if (substr($token, 0, 6) == 'Bearer') {
2580
                    
2605
 
2581
                    $token = trim(substr($token, 7));
2606
                    $token = trim(substr($token, 7));
2582
                    
2607
 
2583
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
2608
                    if (!empty($this->config['leaderslinked.jwt.key'])) {
2584
                        $key = $this->config['leaderslinked.jwt.key'];
2609
                        $key = $this->config['leaderslinked.jwt.key'];
2585
                        
2610
 
2586
                        
2611
 
2587
                        try {
2612
                        try {
2588
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
2613
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
2589
                            
2614
 
2590
                            
2615
 
2591
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
2616
                            if (empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
2592
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
2617
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
2593
                            }
2618
                            }
2594
                            
2619
 
2595
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
2620
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
2596
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2621
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2597
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
2622
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
2598
                        } catch(\Exception $e) {
2623
                        } catch (\Exception $e) {
2599
                            //Token invalido
2624
                            //Token invalido
2600
                        }
2625
                        }
2601
                    }
2626
                    }
Línea 2602... Línea 2627...
2602
                }
2627
                }
2603
            }
2628
            }
2604
 
2629
 
2605
            
2630
 
2606
            if(!$jwtToken) {
2631
            if (!$jwtToken) {
2607
                
2632
 
2608
                $aes = Functions::generatePassword(16);
2633
                $aes = Functions::generatePassword(16);
2609
                
2634
 
2610
                $jwtToken = new JwtToken();
2635
                $jwtToken = new JwtToken();
2611
                $jwtToken->aes = $aes;
2636
                $jwtToken->aes = $aes;
2612
                
2637
 
2613
                $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2638
                $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2614
                if($jwtTokenMapper->insert($jwtToken)) {
2639
                if ($jwtTokenMapper->insert($jwtToken)) {
2615
                    $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
2640
                    $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
2616
                }
2641
                }
2617
                
2642
 
2618
                $token = '';
2643
                $token = '';
2619
                
2644
 
2620
                if(!empty($this->config['leaderslinked.jwt.key'])) {
2645
                if (!empty($this->config['leaderslinked.jwt.key'])) {
2621
                    $issuedAt   = new \DateTimeImmutable();
2646
                    $issuedAt   = new \DateTimeImmutable();
2622
                    $expire     = $issuedAt->modify('+365 days')->getTimestamp();
2647
                    $expire     = $issuedAt->modify('+365 days')->getTimestamp();
2623
                    $serverName = $_SERVER['HTTP_HOST'];
2648
                    $serverName = $_SERVER['HTTP_HOST'];
2624
                    $payload = [
2649
                    $payload = [
2625
                        'iat'  => $issuedAt->getTimestamp(),
2650
                        'iat'  => $issuedAt->getTimestamp(),
2626
                        'iss'  => $serverName,
2651
                        'iss'  => $serverName,
2627
                        'nbf'  => $issuedAt->getTimestamp(),
2652
                        'nbf'  => $issuedAt->getTimestamp(),
2628
                        'exp'  => $expire,
2653
                        'exp'  => $expire,
2629
                        'uuid' => $jwtToken->uuid,
2654
                        'uuid' => $jwtToken->uuid,
2630
                    ];
2655
                    ];
2631
                    
2656
 
2632
                    
2657
 
2633
                    $key = $this->config['leaderslinked.jwt.key'];
2658
                    $key = $this->config['leaderslinked.jwt.key'];
2634
                    $token = JWT::encode($payload, $key, 'HS256');
2659
                    $token = JWT::encode($payload, $key, 'HS256');
2635
                }
2660
                }
2636
            }
2661
            }
2637
            
2662
 
2638
            
2663
 
2639
            
2664
 
2640
            
2665
 
2641
            
2666
 
2642
            
2667
 
2643
            
2668
 
2644
            if ($this->config['leaderslinked.runmode.sandbox']) {
2669
            if ($this->config['leaderslinked.runmode.sandbox']) {
2645
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
2670
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
2646
            } else {
2671
            } else {
2647
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
2672
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
2648
            }
2673
            }
2649
            
2674
 
2650
            
2675
 
2651
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
2676
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
2652
            
2677
 
2653
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
2678
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
2654
            if ($sandbox) {
2679
            if ($sandbox) {
2655
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
2680
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
2656
            } else {
2681
            } else {
2657
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
2682
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
2658
            }
2683
            }
2659
            
2684
 
2660
            
2685
 
2661
            $parts = explode('.', $currentNetwork->main_hostname);
2686
            $parts = explode('.', $currentNetwork->main_hostname);
2662
            if($parts[1] === 'com') {
2687
            if ($parts[1] === 'com') {
2663
                $replace_main = false;
2688
                $replace_main = false;
2664
            } else {
2689
            } else {
2665
                $replace_main = true;
2690
                $replace_main = true;
2666
            }
2691
            }
2667
            
2692
 
2668
            
2693
 
2669
            $storage = Storage::getInstance($this->config, $this->adapter);
2694
            $storage = Storage::getInstance($this->config, $this->adapter);
2670
            $path = $storage->getPathNetwork();
2695
            $path = $storage->getPathNetwork();
2671
            
2696
 
2672
            if($currentNetwork->logo) {
2697
            if ($currentNetwork->logo) {
2673
                $logo_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->logo);
2698
                $logo_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->logo);
2674
            } else {
2699
            } else {
2675
                $logo_url = '';
2700
                $logo_url = '';
2676
            }
2701
            }
2677
            
2702
 
2678
            if($currentNetwork->navbar) {
2703
            if ($currentNetwork->navbar) {
2679
                $navbar_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->navbar);
2704
                $navbar_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->navbar);
2680
            } else {
2705
            } else {
2681
                $navbar_url = '';
2706
                $navbar_url = '';
2682
            }
2707
            }
2683
            
2708
 
2684
            if($currentNetwork->favico) {
2709
            if ($currentNetwork->favico) {
2685
                $favico_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->favico);
2710
                $favico_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->favico);
2686
            } else {
2711
            } else {
2687
                $favico_url = '';
2712
                $favico_url = '';
2688
            }
2713
            }
2689
            
2714
 
2690
            
2715
 
2691
            
2716
 
2692
            
2717
 
2693
            $data = [
2718
            $data = [
2694
                'google_map_key'                => $google_map_key,
2719
                'google_map_key'                => $google_map_key,
Línea 2703... Línea 2728...
2703
                'logo_url'                      => $logo_url,
2728
                'logo_url'                      => $logo_url,
2704
                'navbar_url'                    => $navbar_url,
2729
                'navbar_url'                    => $navbar_url,
2705
                'favico_url'                    => $favico_url,
2730
                'favico_url'                    => $favico_url,
2706
                'intro'                         => $currentNetwork->intro ? $currentNetwork->intro : '',
2731
                'intro'                         => $currentNetwork->intro ? $currentNetwork->intro : '',
2707
                'is_logged_in'                  => $jwtToken->user_id ? true : false,
2732
                'is_logged_in'                  => $jwtToken->user_id ? true : false,
2708
                
2733
 
2709
            ];
2734
            ];
2710
            
2735
 
2711
            if($currentNetwork->default == Network::DEFAULT_YES) {
2736
            if ($currentNetwork->default == Network::DEFAULT_YES) {
2712
                
2737
 
2713
                
2738
 
2714
                
2739
 
2715
                $currentUserPlugin = $this->plugin('currentUserPlugin');
2740
                $currentUserPlugin = $this->plugin('currentUserPlugin');
2716
                if ($currentUserPlugin->hasIdentity()) {
2741
                if ($currentUserPlugin->hasIdentity()) {
2717
                    
2742
 
2718
                    
2743
 
2719
                    $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
2744
                    $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
2720
                    $externalCredentials->getUserBy($currentUserPlugin->getUserId());
2745
                    $externalCredentials->getUserBy($currentUserPlugin->getUserId());
2721
                    
2746
 
2722
                    
2747
 
2723
                    if($currentNetwork->xmpp_active) {
2748
                    if ($currentNetwork->xmpp_active) {
2724
                        $data['xmpp_domain']      = $currentNetwork->xmpp_domain;
2749
                        $data['xmpp_domain']      = $currentNetwork->xmpp_domain;
2725
                        $data['xmpp_hostname']    = $currentNetwork->xmpp_hostname;
2750
                        $data['xmpp_hostname']    = $currentNetwork->xmpp_hostname;
2726
                        $data['xmpp_port']        = $currentNetwork->xmpp_port;
2751
                        $data['xmpp_port']        = $currentNetwork->xmpp_port;
2727
                        $data['xmpp_username']    = $externalCredentials->getUsernameXmpp();
2752
                        $data['xmpp_username']    = $externalCredentials->getUsernameXmpp();
2728
                        $data['xmpp_password']    = $externalCredentials->getPasswordXmpp();
2753
                        $data['xmpp_password']    = $externalCredentials->getPasswordXmpp();
2729
                        $data['inmail_username']    = $externalCredentials->getUsernameInmail();
2754
                        $data['inmail_username']    = $externalCredentials->getUsernameInmail();
2730
                        $data['inmail_password']    = $externalCredentials->getPasswordInmail();
2755
                        $data['inmail_password']    = $externalCredentials->getPasswordInmail();
2731
                    }
2756
                    }
2732
                }
2757
                }
2733
            }
2758
            }
2734
            
2759
 
2735
            $data = [
2760
            $data = [
2736
                'success' => true,
2761
                'success' => true,
2737
                'data' =>  $data
2762
                'data' =>  $data
2738
            ];
2763
            ];
2739
            
-
 
2740
        } else {
2764
        } else {
2741
            $data = [
2765
            $data = [
2742
                'success' => false,
2766
                'success' => false,
2743
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2767
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2744
            ];
2768
            ];
2745
            
2769
 
2746
            return new JsonModel($data);
2770
            return new JsonModel($data);
2747
        }
2771
        }
2748
        
2772
 
2749
        return new JsonModel($data);
2773
        return new JsonModel($data);
2750
    }
2774
    }
2751
   
-
 
2752
    
-
 
2753
   
-
 
2754
}
2775
}