Proyectos de Subversion LeadersLinked - Services

Rev

Rev 99 | Rev 106 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Nullix\CryptoJsAes\CryptoJsAes;
8
use GeoIp2\Database\Reader as GeoIp2Reader;
9
 
10
use Laminas\Authentication\AuthenticationService;
11
use Laminas\Authentication\Result as AuthResult;
12
use Laminas\Mvc\Controller\AbstractActionController;
13
use Laminas\View\Model\JsonModel;
14
 
15
use LeadersLinked\Form\Auth\SigninForm;
16
use LeadersLinked\Form\Auth\ResetPasswordForm;
17
use LeadersLinked\Form\Auth\ForgotPasswordForm;
18
use LeadersLinked\Form\Auth\SignupForm;
19
 
20
use LeadersLinked\Mapper\ConnectionMapper;
21
use LeadersLinked\Mapper\EmailTemplateMapper;
22
use LeadersLinked\Mapper\NetworkMapper;
23
use LeadersLinked\Mapper\UserMapper;
24
 
25
use LeadersLinked\Model\User;
26
use LeadersLinked\Model\UserType;
27
use LeadersLinked\Library\QueueEmail;
28
use LeadersLinked\Library\Functions;
29
use LeadersLinked\Model\EmailTemplate;
30
use LeadersLinked\Mapper\UserPasswordMapper;
31
use LeadersLinked\Model\UserBrowser;
32
use LeadersLinked\Mapper\UserBrowserMapper;
33
use LeadersLinked\Mapper\UserIpMapper;
34
use LeadersLinked\Model\UserIp;
35
use LeadersLinked\Form\Auth\MoodleForm;
36
use LeadersLinked\Library\Rsa;
37
use LeadersLinked\Library\Image;
38
 
39
use LeadersLinked\Authentication\AuthAdapter;
40
use LeadersLinked\Authentication\AuthEmailAdapter;
41
 
42
use LeadersLinked\Model\UserPassword;
43
 
44
use LeadersLinked\Model\Connection;
45
use LeadersLinked\Authentication\AuthImpersonateAdapter;
46
use LeadersLinked\Model\Network;
23 efrain 47
use LeadersLinked\Model\JwtToken;
48
use LeadersLinked\Mapper\JwtTokenMapper;
49
use Firebase\JWT\JWT;
24 efrain 50
use Firebase\JWT\Key;
1 efrain 51
 
52
 
53
 
54
class AuthController extends AbstractActionController
55
{
56
    /**
57
     *
58
     * @var \Laminas\Db\Adapter\AdapterInterface
59
     */
60
    private $adapter;
61
 
62
    /**
63
     *
64
     * @var \LeadersLinked\Cache\CacheInterface
65
     */
66
    private $cache;
67
 
68
 
69
    /**
70
     *
71
     * @var \Laminas\Log\LoggerInterface
72
     */
73
    private $logger;
74
 
75
    /**
76
     *
77
     * @var array
78
     */
79
    private $config;
80
 
81
 
82
    /**
83
     *
84
     * @var \Laminas\Mvc\I18n\Translator
85
     */
86
    private $translator;
87
 
88
 
89
    /**
90
     *
91
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
92
     * @param \LeadersLinked\Cache\CacheInterface $cache
93
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
94
     * @param array $config
95
     * @param \Laminas\Mvc\I18n\Translator $translator
96
     */
97
    public function __construct($adapter, $cache, $logger, $config, $translator)
98
    {
99
        $this->adapter      = $adapter;
100
        $this->cache        = $cache;
101
        $this->logger       = $logger;
102
        $this->config       = $config;
103
        $this->translator   = $translator;
104
    }
105
 
106
    public function signinAction()
107
    {
108
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
109
        $currentNetwork = $currentNetworkPlugin->getNetwork();
110
 
111
        $request = $this->getRequest();
112
 
113
        if ($request->isPost()) {
114
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
115
            $currentNetwork = $currentNetworkPlugin->getNetwork();
24 efrain 116
 
117
            $jwtToken = null;
118
            $headers = getallheaders();
33 efrain 119
 
53 efrain 120
 
34 efrain 121
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
24 efrain 122
 
34 efrain 123
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
124
 
125
 
24 efrain 126
                if (substr($token, 0, 6 ) == 'Bearer') {
127
 
128
                    $token = trim(substr($token, 7));
129
 
130
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
131
                        $key = $this->config['leaderslinked.jwt.key'];
132
 
133
 
134
                        try {
135
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
136
 
137
 
138
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
139
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
140
                            }
141
 
142
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
143
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
144
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
145
                            if(!$jwtToken) {
146
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
147
                            }
1 efrain 148
 
24 efrain 149
                        } catch(\Exception $e) {
150
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
151
                        }
152
                    } else {
153
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
154
                    }
155
                } else {
156
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
157
                }
158
            } else {
159
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
160
            }
1 efrain 161
 
24 efrain 162
 
1 efrain 163
            $form = new  SigninForm($this->config);
164
            $dataPost = $request->getPost()->toArray();
58 efrain 165
/*
1 efrain 166
            if (empty($_SESSION['aes'])) {
167
                return new JsonModel([
168
                    'success'   => false,
169
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
170
                ]);
171
            }
28 efrain 172
 
1 efrain 173
            if (!empty($dataPost['email'])) {
174
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
175
            }
176
 
177
 
178
            if (!empty($dataPost['password'])) {
179
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
58 efrain 180
            }*/
1 efrain 181
 
182
            $form->setData($dataPost);
183
 
184
            if ($form->isValid()) {
24 efrain 185
 
1 efrain 186
                $dataPost = (array) $form->getData();
187
 
188
                $email      = $dataPost['email'];
189
                $password   = $dataPost['password'];
190
                $remember   = $dataPost['remember'];
30 efrain 191
 
192
 
31 efrain 193
 
1 efrain 194
 
195
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
196
                $authAdapter->setData($email, $password, $currentNetwork->id);
197
                $authService = new AuthenticationService();
198
 
199
                $result = $authService->authenticate($authAdapter);
200
 
201
                if ($result->getCode() == AuthResult::SUCCESS) {
202
 
203
 
204
                    $userMapper = UserMapper::getInstance($this->adapter);
205
                    $user = $userMapper->fetchOneByEmail($email);
36 efrain 206
 
207
 
208
                    if($token) {
37 efrain 209
                        $jwtToken->user_id = $user->id;
36 efrain 210
                        $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
37 efrain 211
                        $jwtTokenMapper->update($jwtToken);
36 efrain 212
                    }
213
 
1 efrain 214
 
215
                    $navigator = get_browser(null, true);
216
                    $device_type    =  isset($navigator['device_type']) ? $navigator['device_type'] : '';
217
                    $platform       =  isset($navigator['platform']) ? $navigator['platform'] : '';
218
                    $browser        =  isset($navigator['browser']) ? $navigator['browser'] : '';
219
 
220
 
221
                    $istablet = isset($navigator['istablet']) ?  intval($navigator['istablet']) : 0;
222
                    $ismobiledevice = isset($navigator['ismobiledevice']) ? intval($navigator['ismobiledevice']) : 0;
223
                    $version = isset($navigator['version']) ? $navigator['version'] : '';
224
 
225
 
226
                    $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
227
                    $userBrowser = $userBrowserMapper->fetch($user->id, $device_type, $platform, $browser);
228
                    if ($userBrowser) {
229
                        $userBrowserMapper->update($userBrowser);
230
                    } else {
231
                        $userBrowser = new UserBrowser();
232
                        $userBrowser->user_id           = $user->id;
233
                        $userBrowser->browser           = $browser;
234
                        $userBrowser->platform          = $platform;
235
                        $userBrowser->device_type       = $device_type;
236
                        $userBrowser->is_tablet         = $istablet;
237
                        $userBrowser->is_mobile_device  = $ismobiledevice;
238
                        $userBrowser->version           = $version;
239
 
240
                        $userBrowserMapper->insert($userBrowser);
241
                    }
242
                    //
243
 
244
                    $ip = Functions::getUserIP();
245
                    $ip = $ip == '127.0.0.1' ? '148.240.211.148' : $ip;
246
 
247
                    $userIpMapper = UserIpMapper::getInstance($this->adapter);
248
                    $userIp = $userIpMapper->fetch($user->id, $ip);
249
                    if (empty($userIp)) {
250
 
251
                        if ($this->config['leaderslinked.runmode.sandbox']) {
252
                            $filename = $this->config['leaderslinked.geoip2.production_database'];
253
                        } else {
254
                            $filename = $this->config['leaderslinked.geoip2.sandbox_database'];
255
                        }
256
 
257
                        $reader = new GeoIp2Reader($filename); //GeoIP2-City.mmdb');
258
                        $record = $reader->city($ip);
259
                        if ($record) {
260
                            $userIp = new UserIp();
261
                            $userIp->user_id = $user->id;
262
                            $userIp->city = !empty($record->city->name) ? Functions::utf8_decode($record->city->name) : '';
263
                            $userIp->state_code = !empty($record->mostSpecificSubdivision->isoCode) ? Functions::utf8_decode($record->mostSpecificSubdivision->isoCode) : '';
264
                            $userIp->state_name = !empty($record->mostSpecificSubdivision->name) ? Functions::utf8_decode($record->mostSpecificSubdivision->name) : '';
265
                            $userIp->country_code = !empty($record->country->isoCode) ? Functions::utf8_decode($record->country->isoCode) : '';
266
                            $userIp->country_name = !empty($record->country->name) ? Functions::utf8_decode($record->country->name) : '';
267
                            $userIp->ip = $ip;
268
                            $userIp->latitude = !empty($record->location->latitude) ? $record->location->latitude : 0;
269
                            $userIp->longitude = !empty($record->location->longitude) ? $record->location->longitude : 0;
270
                            $userIp->postal_code = !empty($record->postal->code) ? $record->postal->code : '';
271
 
272
                            $userIpMapper->insert($userIp);
273
                        }
274
                    } else {
275
                        $userIpMapper->update($userIp);
276
                    }
277
 
24 efrain 278
                    /*
1 efrain 279
                    if ($remember) {
280
                        $expired = time() + 365 * 24 * 60 * 60;
281
 
282
                        $cookieEmail = new SetCookie('email', $email, $expired);
283
                    } else {
284
                        $expired = time() - 7200;
285
                        $cookieEmail = new SetCookie('email', '', $expired);
286
                    }
287
 
288
 
289
                    $response = $this->getResponse();
290
                    $response->getHeaders()->addHeader($cookieEmail);
24 efrain 291
                    */
292
 
293
 
1 efrain 294
 
295
 
296
 
297
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
298
 
299
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
300
 
301
                    if ($user_share_invitation) {
302
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
303
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
304
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
305
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
306
 
307
                            if ($connection) {
308
 
309
                                if ($connection->status != Connection::STATUS_ACCEPTED) {
310
                                    $connectionMapper->approve($connection);
311
                                }
312
                            } else {
313
                                $connection = new Connection();
314
                                $connection->request_from = $user->id;
315
                                $connection->request_to = $userRedirect->id;
316
                                $connection->status = Connection::STATUS_ACCEPTED;
317
 
318
                                $connectionMapper->insert($connection);
319
                            }
320
                        }
321
                    }
322
 
323
 
324
 
325
                    $data = [
326
                        'success'   => true,
327
                        'data'      => $this->url()->fromRoute('dashboard'),
328
                    ];
329
 
330
                    $this->cache->removeItem('user_share_invitation');
331
                } else {
332
 
333
                    $message = $result->getMessages()[0];
334
                    if (!in_array($message, [
335
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
336
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
337
                        'ERROR_ENTERED_PASS_INCORRECT_1', 'ERROR_USER_REQUEST_ACCESS_IS_PENDING', 'ERROR_USER_REQUEST_ACCESS_IS_REJECTED'
338
 
339
 
340
                    ])) {
341
                    }
342
 
343
                    switch ($message) {
344
                        case 'ERROR_USER_NOT_FOUND':
345
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
346
                            break;
347
 
348
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
349
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
350
                            break;
351
 
352
                        case 'ERROR_USER_IS_BLOCKED':
353
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
354
                            break;
355
 
356
                        case 'ERROR_USER_IS_INACTIVE':
357
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
358
                            break;
359
 
360
 
361
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
362
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
363
                            break;
364
 
365
 
366
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
367
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
368
                            break;
369
 
370
 
371
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
372
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
373
                            break;
374
 
375
 
376
                        case 'ERROR_USER_REQUEST_ACCESS_IS_PENDING':
377
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Falta verificar que pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
378
                            break;
379
 
380
                        case  'ERROR_USER_REQUEST_ACCESS_IS_REJECTED':
381
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Rechazado por no pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
382
                            break;
383
 
384
 
385
                        default:
386
                            $message = 'ERROR_UNKNOWN';
387
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
388
                            break;
389
                    }
390
 
391
 
392
 
393
 
394
                    $data = [
395
                        'success'   => false,
396
                        'data'   => $message
397
                    ];
398
                }
399
 
67 efrain 400
                return new JsonModel($data);
1 efrain 401
            } else {
402
                $messages = [];
403
 
404
 
405
 
406
                $form_messages = (array) $form->getMessages();
407
                foreach ($form_messages  as $fieldname => $field_messages) {
408
 
409
                    $messages[$fieldname] = array_values($field_messages);
410
                }
67 efrain 411
 
412
                return new JsonModel([
1 efrain 413
                    'success'   => false,
414
                    'data'   => $messages
67 efrain 415
                ]);
1 efrain 416
            }
417
        } else if ($request->isGet()) {
418
 
23 efrain 419
            $aes = Functions::generatePassword(16);
1 efrain 420
 
23 efrain 421
            $jwtToken = new JwtToken();
422
            $jwtToken->aes = $aes;
423
 
424
            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
425
            if($jwtTokenMapper->insert($jwtToken)) {
426
                $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
1 efrain 427
            }
23 efrain 428
 
429
            $token = '';
430
 
431
            if(!empty($this->config['leaderslinked.jwt.key'])) {
432
                $issuedAt   = new \DateTimeImmutable();
433
                $expire     = $issuedAt->modify('+24 hours')->getTimestamp();
434
                $serverName = $_SERVER['HTTP_HOST'];
435
                $payload = [
436
                    'iat'  => $issuedAt->getTimestamp(),
437
                    'iss'  => $serverName,
438
                    'nbf'  => $issuedAt->getTimestamp(),
439
                    'exp'  => $expire,
440
                    'uuid' => $jwtToken->uuid,
441
                ];
442
 
443
 
444
                $key = $this->config['leaderslinked.jwt.key'];
445
                $token = JWT::encode($payload, $key, 'HS256');
446
            }
447
 
448
 
449
 
1 efrain 450
 
23 efrain 451
 
1 efrain 452
            if ($this->config['leaderslinked.runmode.sandbox']) {
453
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
454
            } else {
455
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
456
            }
457
 
458
 
459
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
460
 
461
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
462
            if ($sandbox) {
463
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
464
            } else {
465
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
466
            }
467
 
468
 
469
            $data = [
23 efrain 470
                'google_map_key'                => $google_map_key,
471
                'email'                         => '',
472
                'remember'                      => false,
473
                'site_key'                      => $site_key,
474
                'theme_id'                      => $currentNetwork->theme_id,
475
                'aes'                           => $aes,
476
                'jwt'                           => $token,
477
                'defaultNetwork'                => $currentNetwork->default,
478
                'access_usign_social_networks'  => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
60 efrain 479
                'logo_url'                      => $this->url()->fromRoute('storage-network', ['type' => 'logo'],['force_canonical' => true]),
480
                'navbar_url'                    => $this->url()->fromRoute('storage-network', ['type' => 'navbar'],['force_canonical' => true]),
481
                'favico_url'                    => $this->url()->fromRoute('storage-network', ['type' => 'favico'],['force_canonical' => true]),
23 efrain 482
                'intro'                         => $currentNetwork->intro,
483
                'is_logged_in'                  => false
1 efrain 484
 
485
            ];
49 efrain 486
 
487
            $data = [
488
                'success' => true,
50 efrain 489
                'data' =>  $data
49 efrain 490
            ];
1 efrain 491
 
492
        } else {
493
            $data = [
494
                'success' => false,
495
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
496
            ];
497
 
67 efrain 498
            return new JsonModel($data);
1 efrain 499
        }
500
 
67 efrain 501
        return new JsonModel($data);
1 efrain 502
    }
503
 
504
    public function facebookAction()
505
    {
506
 
507
        $request = $this->getRequest();
508
        if ($request->isGet()) {
509
            /*
510
          //  try {
511
                $app_id = $this->config['leaderslinked.facebook.app_id'];
512
                $app_password = $this->config['leaderslinked.facebook.app_password'];
513
                $app_graph_version = $this->config['leaderslinked.facebook.app_graph_version'];
514
                //$app_url_auth = $this->config['leaderslinked.facebook.app_url_auth'];
515
                //$redirect_url = $this->config['leaderslinked.facebook.app_redirect_url'];
516
 
517
                [facebook]
518
                app_id=343770226993130
519
                app_password=028ee729090fd591e50a17a786666c12
520
                app_graph_version=v17
521
                app_redirect_url=https://leaderslinked.com/oauth/facebook
522
 
523
                https://www.facebook.com/v17.0/dialog/oauth?client_id=343770226993130&redirect_uri= https://dev.leaderslinked.com/oauth/facebook&state=AE12345678
524
 
525
 
526
                $s = 'https://www.facebook.com/v17.0/dialog/oauth' .
527
                    '?client_id='
528
                    '&redirect_uri={"https://www.domain.com/login"}
529
                    '&state={"{st=state123abc,ds=123456789}"}
530
 
531
                $fb = new \Facebook\Facebook([
532
                    'app_id' => $app_id,
533
                    'app_secret' => $app_password,
534
                    'default_graph_version' => $app_graph_version,
535
                ]);
536
 
537
                $app_url_auth =  $this->url()->fromRoute('oauth/facebook', [], ['force_canonical' => true]);
538
                $helper = $fb->getRedirectLoginHelper();
539
                $permissions = ['email', 'public_profile']; // Optional permissions
540
                $facebookUrl = $helper->getLoginUrl($app_url_auth, $permissions);
541
 
542
 
543
 
544
                return new JsonModel([
545
                    'success' => false,
546
                    'data' => $facebookUrl
547
                ]);
548
            } catch (\Throwable $e) {
549
                return new JsonModel([
550
                    'success' => false,
551
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_FACEBOOK'
552
                ]);
553
            }*/
554
        } else {
555
            return new JsonModel([
556
                'success' => false,
557
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
558
            ]);
559
        }
560
    }
561
 
562
    public function twitterAction()
563
    {
564
        $request = $this->getRequest();
565
        if ($request->isGet()) {
566
 
567
            try {
568
                if ($this->config['leaderslinked.runmode.sandbox']) {
569
 
570
                    $twitter_api_key = $this->config['leaderslinked.twitter.sandbox_api_key'];
571
                    $twitter_api_secret = $this->config['leaderslinked.twitter.sandbox_api_secret'];
572
                } else {
573
                    $twitter_api_key = $this->config['leaderslinked.twitter.production_api_key'];
574
                    $twitter_api_secret = $this->config['leaderslinked.twitter.production_api_secret'];
575
                }
576
 
577
                /*
578
                 echo '$twitter_api_key = ' . $twitter_api_key . PHP_EOL;
579
                 echo '$twitter_api_secret = ' . $twitter_api_secret . PHP_EOL;
580
                 exit;
581
                 */
582
 
583
                //Twitter
584
                //$redirect_url =  $this->url()->fromRoute('oauth/twitter', [], ['force_canonical' => true]);
585
                $redirect_url = $this->config['leaderslinked.twitter.app_redirect_url'];
586
                $twitter = new \Abraham\TwitterOAuth\TwitterOAuth($twitter_api_key, $twitter_api_secret);
587
                $request_token =  $twitter->oauth('oauth/request_token', ['oauth_callback' => $redirect_url]);
588
                $twitterUrl = $twitter->url('oauth/authorize', ['oauth_token' => $request_token['oauth_token']]);
589
 
590
                $twitterSession = new \Laminas\Session\Container('twitter');
591
                $twitterSession->oauth_token = $request_token['oauth_token'];
592
                $twitterSession->oauth_token_secret = $request_token['oauth_token_secret'];
593
 
594
                return new JsonModel([
595
                    'success' => true,
596
                    'data' =>  $twitterUrl
597
                ]);
598
            } catch (\Throwable $e) {
599
                return new JsonModel([
600
                    'success' => false,
601
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_TWITTER'
602
                ]);
603
            }
604
        } else {
605
            return new JsonModel([
606
                'success' => false,
607
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
608
            ]);
609
        }
610
    }
611
 
612
    public function googleAction()
613
    {
614
        $request = $this->getRequest();
615
        if ($request->isGet()) {
616
 
617
            try {
618
 
619
 
620
                //Google
621
                $google = new \Google_Client();
622
                $google->setAuthConfig('data/google/auth-leaderslinked/apps.google.com_secreto_cliente.json');
623
                $google->setAccessType("offline");        // offline access
624
 
625
                $google->setIncludeGrantedScopes(true);   // incremental auth
626
 
627
                $google->addScope('profile');
628
                $google->addScope('email');
629
 
630
                // $redirect_url =  $this->url()->fromRoute('oauth/google', [], ['force_canonical' => true]);
631
                $redirect_url = $this->config['leaderslinked.google_auth.app_redirect_url'];
632
 
633
                $google->setRedirectUri($redirect_url);
634
                $googleUrl = $google->createAuthUrl();
635
 
636
                return new JsonModel([
637
                    'success' => true,
638
                    'data' =>  $googleUrl
639
                ]);
640
            } catch (\Throwable $e) {
641
                return new JsonModel([
642
                    'success' => false,
643
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_GOOGLE'
644
                ]);
645
            }
646
        } else {
647
            return new JsonModel([
648
                'success' => false,
649
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
650
            ]);
651
        }
652
    }
653
 
654
    public function signoutAction()
655
    {
656
        $currentUserPlugin = $this->plugin('currentUserPlugin');
657
        $currentUser = $currentUserPlugin->getRawUser();
658
        if ($currentUserPlugin->hasImpersonate()) {
659
 
660
 
661
            $userMapper = UserMapper::getInstance($this->adapter);
662
            $userMapper->leaveImpersonate($currentUser->id);
663
 
664
            $networkMapper = NetworkMapper::getInstance($this->adapter);
665
            $network = $networkMapper->fetchOne($currentUser->network_id);
666
 
667
 
668
            if (!$currentUser->one_time_password) {
669
                $one_time_password = Functions::generatePassword(25);
670
 
671
                $currentUser->one_time_password = $one_time_password;
672
 
673
                $userMapper = UserMapper::getInstance($this->adapter);
674
                $userMapper->updateOneTimePassword($currentUser, $one_time_password);
675
            }
676
 
677
 
678
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
679
            if ($sandbox) {
680
                $salt = $this->config['leaderslinked.backend.sandbox_salt'];
681
            } else {
682
                $salt = $this->config['leaderslinked.backend.production_salt'];
683
            }
684
 
685
            $rand = 1000 + mt_rand(1, 999);
686
            $timestamp = time();
687
            $password = md5($currentUser->one_time_password . '-' . $rand . '-' . $timestamp . '-' . $salt);
688
 
689
            $params = [
690
                'user_uuid' => $currentUser->uuid,
691
                'password' => $password,
692
                'rand' => $rand,
693
                'time' => $timestamp,
694
            ];
695
 
696
            $currentUserPlugin->clearIdentity();
697
 
698
            return new JsonModel([
699
                'success'   => true,
700
                'data'      => [
701
                    'message' => 'LABEL_SIGNOUT_SUCCESSFULLY',
702
                    'url' => 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params)
703
                ],
704
 
705
            ]);
706
 
707
 
708
           // $url = 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params);
709
           // return $this->redirect()->toUrl($url);
710
        } else {
711
 
712
 
713
            if ($currentUserPlugin->hasIdentity()) {
714
 
715
                $this->logger->info('Desconexión de LeadersLinked', ['user_id' => $currentUserPlugin->getUserId(), 'ip' => Functions::getUserIP()]);
716
            }
717
 
718
            $currentUserPlugin->clearIdentity();
719
 
720
           // return $this->redirect()->toRoute('home');
721
 
722
            return new JsonModel([
723
                'success'   => true,
724
                'data'      => [
725
                    'message' => 'LABEL_SIGNOUT_SUCCESSFULLY',
726
                    'url' => '',
727
                ],
728
 
729
            ]);
730
        }
731
    }
732
 
733
 
734
    public function resetPasswordAction()
735
    {
736
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
737
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
738
 
739
 
740
        $flashMessenger = $this->plugin('FlashMessenger');
741
        $code =  Functions::sanitizeFilterString($this->params()->fromRoute('code', ''));
742
 
743
        $userMapper = UserMapper::getInstance($this->adapter);
744
        $user = $userMapper->fetchOneByPasswordResetKeyAndNetworkId($code, $currentNetwork->id);
745
        if (!$user) {
746
            $this->logger->err('Restablecer contraseña - Error código no existe', ['ip' => Functions::getUserIP()]);
747
 
748
            return new JsonModel([
749
                'success'   => true,
750
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_IS_INVALID'
751
            ]);
752
 
753
        }
754
 
755
 
756
 
757
        $password_generated_on = strtotime($user->password_generated_on);
758
        $expiry_time = $password_generated_on + $this->config['leaderslinked.security.reset_password_expired'];
759
        if (time() > $expiry_time) {
760
            $this->logger->err('Restablecer contraseña - Error código expirado', ['ip' => Functions::getUserIP()]);
761
 
762
            return new JsonModel([
763
                'success'   => true,
764
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_HAS_EXPIRED'
765
            ]);
766
        }
767
 
768
        $request = $this->getRequest();
769
        if ($request->isPost()) {
770
            $dataPost = $request->getPost()->toArray();
771
            if (empty($_SESSION['aes'])) {
772
                return new JsonModel([
773
                    'success'   => false,
774
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
775
                ]);
776
 
777
 
778
            }
779
 
780
            if (!empty($dataPost['password'])) {
781
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
782
            }
783
            if (!empty($dataPost['confirmation'])) {
784
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
785
            }
786
 
787
 
788
 
789
            $form = new ResetPasswordForm($this->config);
790
            $form->setData($dataPost);
791
 
792
            if ($form->isValid()) {
793
                $data = (array) $form->getData();
794
                $password = $data['password'];
795
 
796
 
797
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
798
                $userPasswords = $userPasswordMapper->fetchAllByUserId($user->id);
799
 
800
                $oldPassword = false;
801
                foreach ($userPasswords as $userPassword) {
802
                    if (password_verify($password, $userPassword->password) || (md5($password) == $userPassword->password)) {
803
                        $oldPassword = true;
804
                        break;
805
                    }
806
                }
807
 
808
                if ($oldPassword) {
809
                    $this->logger->err('Restablecer contraseña - Error contraseña ya utilizada anteriormente', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
810
 
811
                    return new JsonModel([
812
                        'success'   => false,
813
                        'data'      => 'ERROR_PASSWORD_HAS_ALREADY_BEEN_USED'
814
 
815
                    ]);
816
                } else {
817
                    $password_hash = password_hash($password, PASSWORD_DEFAULT);
818
 
819
 
820
                    $result = $userMapper->updatePassword($user, $password_hash);
821
                    if ($result) {
822
 
823
                        $userPassword = new UserPassword();
824
                        $userPassword->user_id = $user->id;
825
                        $userPassword->password = $password_hash;
826
                        $userPasswordMapper->insert($userPassword);
827
 
828
 
829
                        $this->logger->info('Restablecer contraseña realizado', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
830
 
831
 
832
                        $flashMessenger->addSuccessMessage('LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED');
833
 
834
                        return new JsonModel([
835
                            'success'   => true,
836
                            'data'      => [
837
                                'message' => 'LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED',
838
                                'redirect' => $this->url()->fromRoute('home'),
839
                            ],
840
 
841
                        ]);
842
                    } else {
843
                        $this->logger->err('Restablecer contraseña - Error desconocido', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
844
 
845
                        return new JsonModel([
846
                            'success'   => false,
847
                            'data'      => 'ERROR_THERE_WAS_AN_ERROR'
848
 
849
                        ]);
850
                    }
851
                }
852
            } else {
853
                $form_messages =  $form->getMessages('captcha');
854
                if (!empty($form_messages)) {
855
                    return new JsonModel([
856
                        'success'   => false,
857
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
858
                    ]);
859
                }
860
 
861
                $messages = [];
862
 
863
                $form_messages = (array) $form->getMessages();
864
                foreach ($form_messages  as $fieldname => $field_messages) {
865
                    $messages[$fieldname] = array_values($field_messages);
866
                }
867
 
868
                return new JsonModel([
869
                    'success'   => false,
870
                    'data'   => $messages
871
                ]);
872
            }
873
        } else if ($request->isGet()) {
874
 
875
            if (empty($_SESSION['aes'])) {
876
                $_SESSION['aes'] = Functions::generatePassword(16);
877
            }
878
 
879
            if ($this->config['leaderslinked.runmode.sandbox']) {
880
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
881
            } else {
882
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
883
            }
884
 
885
 
886
            return new JsonModel([
887
                'code' => $code,
888
                'site_key' => $site_key,
889
                'aes'       => $_SESSION['aes'],
890
                'defaultNetwork' => $currentNetwork->default,
891
            ]);
892
 
893
        }
894
 
895
 
896
 
897
        return new JsonModel([
898
            'success' => false,
899
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
900
        ]);
901
    }
902
 
903
    public function forgotPasswordAction()
904
    {
905
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
906
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
907
 
908
 
909
 
910
        $request = $this->getRequest();
911
        if ($request->isPost()) {
912
            $dataPost = $request->getPost()->toArray();
913
            if (empty($_SESSION['aes'])) {
914
                return new JsonModel([
915
                    'success'   => false,
916
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
917
                ]);
918
            }
919
 
920
            if (!empty($dataPost['email'])) {
921
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
922
            }
923
 
924
            $form = new ForgotPasswordForm($this->config);
925
            $form->setData($dataPost);
926
 
927
            if ($form->isValid()) {
928
                $dataPost = (array) $form->getData();
929
                $email      = $dataPost['email'];
930
 
931
                $userMapper = UserMapper::getInstance($this->adapter);
932
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
933
                if (!$user) {
934
                    $this->logger->err('Olvidó contraseña ' . $email . '- Email no existe ', ['ip' => Functions::getUserIP()]);
935
 
936
                    return new JsonModel([
937
                        'success' => false,
938
                        'data' =>  'ERROR_EMAIL_IS_NOT_REGISTERED'
939
                    ]);
940
                } else {
941
                    if ($user->status == User::STATUS_INACTIVE) {
942
                        return new JsonModel([
943
                            'success' => false,
944
                            'data' =>  'ERROR_USER_IS_INACTIVE'
945
                        ]);
946
                    } else if ($user->email_verified == User::EMAIL_VERIFIED_NO) {
947
                        $this->logger->err('Olvidó contraseña - Email no verificado ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
948
 
949
                        return new JsonModel([
950
                            'success' => false,
951
                            'data' => 'ERROR_EMAIL_HAS_NOT_BEEN_VERIFIED'
952
                        ]);
953
                    } else {
954
                        $password_reset_key = md5($user->email . time());
955
                        $userMapper->updatePasswordResetKey((int) $user->id, $password_reset_key);
956
 
957
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
958
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RESET_PASSWORD, $currentNetwork->id);
959
                        if ($emailTemplate) {
960
                            $arrayCont = [
961
                                'firstname'             => $user->first_name,
962
                                'lastname'              => $user->last_name,
963
                                'other_user_firstname'  => '',
964
                                'other_user_lastname'   => '',
965
                                'company_name'          => '',
966
                                'group_name'            => '',
967
                                'content'               => '',
968
                                'code'                  => '',
969
                                'link'                  => $this->url()->fromRoute('reset-password', ['code' => $password_reset_key], ['force_canonical' => true])
970
                            ];
971
 
972
                            $email = new QueueEmail($this->adapter);
973
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
974
                        }
975
                        $flashMessenger = $this->plugin('FlashMessenger');
976
                        $flashMessenger->addSuccessMessage('LABEL_RECOVERY_LINK_WAS_SENT_TO_YOUR_EMAIL');
977
 
978
                        $this->logger->info('Olvidó contraseña - Se envio link de recuperación ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
979
 
980
                        return new JsonModel([
981
                            'success' => true,
982
                        ]);
983
                    }
984
                }
985
            } else {
986
 
987
 
988
                $form_messages =  $form->getMessages('captcha');
989
 
990
 
991
 
992
                if (!empty($form_messages)) {
993
                    return new JsonModel([
994
                        'success'   => false,
995
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
996
                    ]);
997
                }
998
 
999
                $messages = [];
1000
                $form_messages = (array) $form->getMessages();
1001
                foreach ($form_messages  as $fieldname => $field_messages) {
1002
                    $messages[$fieldname] = array_values($field_messages);
1003
                }
1004
 
1005
                return new JsonModel([
1006
                    'success'   => false,
1007
                    'data'      => $messages
1008
                ]);
1009
            }
1010
        } else  if ($request->isGet()) {
1011
 
1012
            if (empty($_SESSION['aes'])) {
1013
                $_SESSION['aes'] = Functions::generatePassword(16);
1014
            }
1015
 
1016
            if ($this->config['leaderslinked.runmode.sandbox']) {
1017
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
1018
            } else {
1019
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
1020
            }
1021
 
1022
            return new JsonModel([
1023
                'site_key'  => $site_key,
1024
                'aes'       => $_SESSION['aes'],
1025
                'defaultNetwork' => $currentNetwork->default,
1026
            ]);
1027
        }
1028
 
1029
        return new JsonModel([
1030
            'success' => false,
1031
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1032
        ]);
1033
    }
1034
 
1035
    public function signupAction()
1036
    {
1037
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1038
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1039
 
1040
 
1041
        $request = $this->getRequest();
1042
        if ($request->isPost()) {
1043
            $dataPost = $request->getPost()->toArray();
1044
 
1045
            if (empty($_SESSION['aes'])) {
1046
                return new JsonModel([
1047
                    'success'   => false,
1048
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
1049
                ]);
1050
            }
1051
 
1052
            if (!empty($dataPost['email'])) {
1053
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
1054
            }
1055
 
1056
            if (!empty($dataPost['password'])) {
1057
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
1058
            }
1059
 
1060
            if (!empty($dataPost['confirmation'])) {
1061
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
1062
            }
1063
 
1064
            if (empty($dataPost['is_adult'])) {
1065
                $dataPost['is_adult'] = User::IS_ADULT_NO;
1066
            } else {
1067
                $dataPost['is_adult'] = $dataPost['is_adult'] == User::IS_ADULT_YES ? User::IS_ADULT_YES : User::IS_ADULT_NO;
1068
            }
1069
 
1070
 
1071
 
1072
            $form = new SignupForm($this->config);
1073
            $form->setData($dataPost);
1074
 
1075
            if ($form->isValid()) {
1076
                $dataPost = (array) $form->getData();
1077
 
1078
                $email = $dataPost['email'];
1079
 
1080
                $userMapper = UserMapper::getInstance($this->adapter);
1081
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
1082
                if ($user) {
1083
                    $this->logger->err('Registro ' . $email . '- Email ya  existe ', ['ip' => Functions::getUserIP()]);
1084
 
1085
 
1086
 
1087
                    return new JsonModel([
1088
                        'success' => false,
1089
                        'data' => 'ERROR_EMAIL_IS_REGISTERED'
1090
                    ]);
1091
                } else {
1092
 
1093
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
1094
 
1095
 
1096
                    if ($user_share_invitation) {
1097
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
1098
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE) {
1099
                            $password_hash = password_hash($dataPost['password'], PASSWORD_DEFAULT);
1100
 
1101
                            $user = new User();
1102
                            $user->network_id           = $currentNetwork->id;
1103
                            $user->email                = $dataPost['email'];
1104
                            $user->first_name           = $dataPost['first_name'];
1105
                            $user->last_name            = $dataPost['last_name'];
1106
                            $user->usertype_id          = UserType::USER;
1107
                            $user->password             = $password_hash;
1108
                            $user->password_updated_on  = date('Y-m-d H:i:s');
1109
                            $user->status               = User::STATUS_ACTIVE;
1110
                            $user->blocked              = User::BLOCKED_NO;
1111
                            $user->email_verified       = User::EMAIL_VERIFIED_YES;
1112
                            $user->login_attempt        = 0;
1113
                            $user->is_adult             = $dataPost['is_adult'];
1114
                            $user->request_access       = User::REQUEST_ACCESS_APPROVED;
1115
 
1116
 
1117
 
1118
 
1119
 
1120
                            if ($userMapper->insert($user)) {
1121
 
1122
                                $userPassword = new UserPassword();
1123
                                $userPassword->user_id = $user->id;
1124
                                $userPassword->password = $password_hash;
1125
 
1126
                                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1127
                                $userPasswordMapper->insert($userPassword);
1128
 
1129
 
1130
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1131
                                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
1132
 
1133
                                if ($connection) {
1134
 
1135
                                    if ($connection->status != Connection::STATUS_ACCEPTED) {
1136
                                        $connectionMapper->approve($connection);
1137
                                    }
1138
                                } else {
1139
                                    $connection = new Connection();
1140
                                    $connection->request_from = $user->id;
1141
                                    $connection->request_to = $userRedirect->id;
1142
                                    $connection->status = Connection::STATUS_ACCEPTED;
1143
 
1144
                                    $connectionMapper->insert($connection);
1145
                                }
1146
 
1147
 
1148
                                $this->cache->removeItem('user_share_invitation');
1149
 
1150
 
1151
 
1152
                                $data = [
1153
                                    'success'   => true,
1154
                                    'data'      => $this->url()->fromRoute('home'),
1155
                                ];
1156
 
1157
 
1158
                                $this->logger->info('Registro con Exito ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1159
 
1160
                                return new JsonModel($data);
1161
                            }
1162
                        }
1163
                    }
1164
 
1165
 
1166
 
1167
 
1168
                    $timestamp = time();
1169
                    $activation_key = sha1($dataPost['email'] . uniqid() . $timestamp);
1170
 
1171
                    $password_hash = password_hash($dataPost['password'], PASSWORD_DEFAULT);
1172
 
1173
                    $user = new User();
1174
                    $user->network_id           = $currentNetwork->id;
1175
                    $user->email                = $dataPost['email'];
1176
                    $user->first_name           = $dataPost['first_name'];
1177
                    $user->last_name            = $dataPost['last_name'];
1178
                    $user->usertype_id          = UserType::USER;
1179
                    $user->password             = $password_hash;
1180
                    $user->password_updated_on  = date('Y-m-d H:i:s');
1181
                    $user->activation_key       = $activation_key;
1182
                    $user->status               = User::STATUS_INACTIVE;
1183
                    $user->blocked              = User::BLOCKED_NO;
1184
                    $user->email_verified       = User::EMAIL_VERIFIED_NO;
1185
                    $user->login_attempt        = 0;
1186
 
1187
                    if ($currentNetwork->default == Network::DEFAULT_YES) {
1188
                        $user->request_access = User::REQUEST_ACCESS_APPROVED;
1189
                    } else {
1190
                        $user->request_access = User::REQUEST_ACCESS_PENDING;
1191
                    }
1192
 
1193
 
1194
 
1195
                    if ($userMapper->insert($user)) {
1196
 
1197
                        $userPassword = new UserPassword();
1198
                        $userPassword->user_id = $user->id;
1199
                        $userPassword->password = $password_hash;
1200
 
1201
                        $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1202
                        $userPasswordMapper->insert($userPassword);
1203
 
1204
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1205
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_USER_REGISTER, $currentNetwork->id);
1206
                        if ($emailTemplate) {
1207
                            $arrayCont = [
1208
                                'firstname'             => $user->first_name,
1209
                                'lastname'              => $user->last_name,
1210
                                'other_user_firstname'  => '',
1211
                                'other_user_lastname'   => '',
1212
                                'company_name'          => '',
1213
                                'group_name'            => '',
1214
                                'content'               => '',
1215
                                'code'                  => '',
1216
                                'link'                  => $this->url()->fromRoute('activate-account', ['code' => $user->activation_key], ['force_canonical' => true])
1217
                            ];
1218
 
1219
                            $email = new QueueEmail($this->adapter);
1220
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1221
                        }
1222
                        $flashMessenger = $this->plugin('FlashMessenger');
1223
                        $flashMessenger->addSuccessMessage('LABEL_REGISTRATION_DONE');
1224
 
1225
                        $this->logger->info('Registro con Exito ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1226
 
1227
                        return new JsonModel([
1228
                            'success' => true,
1229
                        ]);
1230
                    } else {
1231
                        $this->logger->err('Registro ' . $email . '- Ha ocurrido un error ', ['ip' => Functions::getUserIP()]);
1232
 
1233
                        return new JsonModel([
1234
                            'success' => false,
1235
                            'data' => 'ERROR_THERE_WAS_AN_ERROR'
1236
                        ]);
1237
                    }
1238
                }
1239
            } else {
1240
 
1241
                $form_messages =  $form->getMessages('captcha');
1242
                if (!empty($form_messages)) {
1243
                    return new JsonModel([
1244
                        'success'   => false,
1245
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
1246
                    ]);
1247
                }
1248
 
1249
                $messages = [];
1250
 
1251
                $form_messages = (array) $form->getMessages();
1252
                foreach ($form_messages  as $fieldname => $field_messages) {
1253
                    $messages[$fieldname] = array_values($field_messages);
1254
                }
1255
 
1256
                return new JsonModel([
1257
                    'success'   => false,
1258
                    'data'   => $messages
1259
                ]);
1260
            }
1261
        } else if ($request->isGet()) {
1262
 
1263
            if (empty($_SESSION['aes'])) {
1264
                $_SESSION['aes'] = Functions::generatePassword(16);
1265
            }
1266
 
1267
            if ($this->config['leaderslinked.runmode.sandbox']) {
1268
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
1269
            } else {
1270
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
1271
            }
1272
 
1273
            $email      = isset($_COOKIE['email']) ? $_COOKIE['email'] : '';
1274
 
1275
            return new JsonModel([
1276
                'site_key'  => $site_key,
1277
                'aes'       => $_SESSION['aes'],
1278
                'defaultNetwork' => $currentNetwork->default,
1279
            ]);
1280
        }
1281
 
1282
        return new JsonModel([
1283
            'success' => false,
1284
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1285
        ]);
1286
    }
1287
 
1288
    public function activateAccountAction()
1289
    {
1290
 
1291
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1292
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1293
 
1294
 
1295
 
1296
        $request = $this->getRequest();
1297
        if ($request->isGet()) {
1298
            $code   =  Functions::sanitizeFilterString($this->params()->fromRoute('code'));
1299
            $userMapper = UserMapper::getInstance($this->adapter);
1300
            $user = $userMapper->fetchOneByActivationKeyAndNetworkId($code, $currentNetwork->id);
1301
 
1302
            $flashMessenger = $this->plugin('FlashMessenger');
1303
 
1304
            if ($user) {
1305
                if (User::EMAIL_VERIFIED_YES == $user->email_verified) {
1306
 
1307
                    $this->logger->err('Verificación email - El código ya habia sido verificao ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1308
 
1309
                    $flashMessenger->addErrorMessage('ERROR_EMAIL_HAS_BEEN_PREVIOUSLY_VERIFIED');
1310
                } else {
1311
 
1312
                    if ($userMapper->activateAccount((int) $user->id)) {
1313
 
1314
                        $this->logger->info('Verificación email realizada ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1315
 
1316
 
1317
 
1318
                        $user_share_invitation = $this->cache->getItem('user_share_invitation');
1319
 
1320
                        if ($user_share_invitation) {
1321
                            $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
1322
                            if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
1323
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1324
                                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
1325
 
1326
                                if ($connection) {
1327
 
1328
                                    if ($connection->status != Connection::STATUS_ACCEPTED) {
1329
                                        $connectionMapper->approve($connection);
1330
                                    }
1331
                                } else {
1332
                                    $connection = new Connection();
1333
                                    $connection->request_from = $user->id;
1334
                                    $connection->request_to = $userRedirect->id;
1335
                                    $connection->status = Connection::STATUS_ACCEPTED;
1336
 
1337
                                    $connectionMapper->insert($connection);
1338
                                }
1339
                            }
1340
                        }
1341
 
1342
 
1343
 
1344
                        $this->cache->removeItem('user_share_invitation');
1345
 
1346
 
1347
                        if ($currentNetwork->default == Network::DEFAULT_YES) {
1348
                            $flashMessenger->addSuccessMessage('LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED');
1349
                        } else {
1350
 
1351
                            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1352
                            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_REQUEST_ACCESS_PENDING, $currentNetwork->id);
1353
 
1354
                            if ($emailTemplate) {
1355
                                $arrayCont = [
1356
                                    'firstname'             => $user->first_name,
1357
                                    'lastname'              => $user->last_name,
1358
                                    'other_user_firstname'  => '',
1359
                                    'other_user_lastname'   => '',
1360
                                    'company_name'          => '',
1361
                                    'group_name'            => '',
1362
                                    'content'               => '',
1363
                                    'code'                  => '',
1364
                                    'link'                  => '',
1365
                                ];
1366
 
1367
                                $email = new QueueEmail($this->adapter);
1368
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1369
                            }
1370
 
1371
 
1372
                            $flashMessenger->addSuccessMessage('LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED_WE_ARE_VERIFYING_YOUR_INFORMATION');
1373
                        }
1374
                    } else {
1375
                        $this->logger->err('Verificación email - Ha ocurrido un error ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1376
 
1377
                        $flashMessenger->addErrorMessage('ERROR_THERE_WAS_AN_ERROR');
1378
                    }
1379
                }
1380
            } else {
1381
                $this->logger->err('Verificación email - El código no existe ', ['ip' => Functions::getUserIP()]);
1382
 
1383
                $flashMessenger->addErrorMessage('ERROR_ACTIVATION_CODE_IS_NOT_VALID');
1384
            }
1385
 
1386
            return $this->redirect()->toRoute('home');
1387
        } else {
1388
            $response = [
1389
                'success' => false,
1390
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1391
            ];
1392
        }
1393
 
1394
        return new JsonModel($response);
1395
    }
1396
 
1397
 
1398
 
1399
    public function onroomAction()
1400
    {
1401
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1402
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1403
 
1404
 
1405
 
1406
        $request = $this->getRequest();
1407
 
1408
        if ($request->isPost()) {
1409
 
1410
            $dataPost = $request->getPost()->toArray();
1411
 
1412
 
1413
            $form = new  MoodleForm();
1414
            $form->setData($dataPost);
1415
            if ($form->isValid()) {
1416
 
1417
                $dataPost   = (array) $form->getData();
1418
                $username   = $dataPost['username'];
1419
                $password   = $dataPost['password'];
1420
                $timestamp  = $dataPost['timestamp'];
1421
                $rand       = $dataPost['rand'];
1422
                $data       = $dataPost['data'];
1423
 
1424
                $config_username    = $this->config['leaderslinked.moodle.username'];
1425
                $config_password    = $this->config['leaderslinked.moodle.password'];
1426
                $config_rsa_n       = $this->config['leaderslinked.moodle.rsa_n'];
1427
                $config_rsa_d       = $this->config['leaderslinked.moodle.rsa_d'];
1428
                $config_rsa_e       = $this->config['leaderslinked.moodle.rsa_e'];
1429
 
1430
 
1431
 
1432
 
1433
                if (empty($username) || empty($password) || empty($timestamp) || empty($rand) || !is_integer($rand)) {
1434
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY1']);
1435
                    exit;
1436
                }
1437
 
1438
                if ($username != $config_username) {
1439
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY2']);
1440
                    exit;
1441
                }
1442
 
1443
                $dt = \DateTime::createFromFormat('Y-m-d\TH:i:s', $timestamp);
1444
                if (!$dt) {
1445
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY3']);
1446
                    exit;
1447
                }
1448
 
1449
                $t0 = $dt->getTimestamp();
1450
                $t1 = strtotime('-5 minutes');
1451
                $t2 = strtotime('+5 minutes');
1452
 
1453
                if ($t0 < $t1 || $t0 > $t2) {
1454
                    //echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
1455
                    //exit;
1456
                }
1457
 
1458
                if (!password_verify($username . '-' . $config_password . '-' . $rand . '-' . $timestamp, $password)) {
1459
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY5']);
1460
                    exit;
1461
                }
1462
 
1463
                if (empty($data)) {
1464
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS1']);
1465
                    exit;
1466
                }
1467
 
1468
                $data = base64_decode($data);
1469
                if (empty($data)) {
1470
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS2']);
1471
                    exit;
1472
                }
1473
 
1474
 
1475
                try {
1476
                    $rsa = Rsa::getInstance();
1477
                    $data = $rsa->decrypt($data,  $config_rsa_d,  $config_rsa_n);
1478
                } catch (\Throwable $e) {
1479
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS3']);
1480
                    exit;
1481
                }
1482
 
1483
                $data = (array) json_decode($data);
1484
                if (empty($data)) {
1485
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS4']);
1486
                    exit;
1487
                }
1488
 
1489
                $email      = isset($data['email']) ? Functions::sanitizeFilterString($data['email']) : '';
1490
                $first_name = isset($data['first_name']) ? Functions::sanitizeFilterString($data['first_name']) : '';
1491
                $last_name  = isset($data['last_name']) ? Functions::sanitizeFilterString($data['last_name']) : '';
1492
 
1493
                if (!filter_var($email, FILTER_VALIDATE_EMAIL) || empty($first_name) || empty($last_name)) {
1494
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS5']);
1495
                    exit;
1496
                }
1497
 
1498
                $userMapper = UserMapper::getInstance($this->adapter);
1499
                $user = $userMapper->fetchOneByEmail($email);
1500
                if (!$user) {
1501
 
1502
 
1503
                    $user = new User();
1504
                    $user->network_id = $currentNetwork->id;
1505
                    $user->blocked = User::BLOCKED_NO;
1506
                    $user->email = $email;
1507
                    $user->email_verified = User::EMAIL_VERIFIED_YES;
1508
                    $user->first_name = $first_name;
1509
                    $user->last_name = $last_name;
1510
                    $user->login_attempt = 0;
1511
                    $user->password = '-NO-PASSWORD-';
1512
                    $user->usertype_id = UserType::USER;
1513
                    $user->status = User::STATUS_ACTIVE;
1514
                    $user->show_in_search = User::SHOW_IN_SEARCH_YES;
1515
 
1516
                    if ($userMapper->insert($user)) {
1517
                        echo json_encode(['success' => false, 'data' => $userMapper->getError()]);
1518
                        exit;
1519
                    }
1520
 
1521
 
1522
 
1523
 
1524
                    $filename   = trim(isset($data['avatar_filename']) ? filter_var($data['avatar_filename'], FILTER_SANITIZE_EMAIL) : '');
1525
                    $content    = isset($data['avatar_content']) ? Functions::sanitizeFilterString($data['avatar_content']) : '';
1526
 
1527
                    if ($filename && $content) {
1528
                        $source = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
1529
                        try {
1530
                            file_put_contents($source, base64_decode($content));
1531
                            if (file_exists($source)) {
1532
                                $target_path = $this->config['leaderslinked.fullpath.user'] . $user->uuid;
1533
                                list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1534
 
1535
                                $target_filename    = 'user-' . uniqid() . '.png';
1536
                                $crop_to_dimensions = true;
1537
 
1538
                                if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1539
                                    return new JsonModel([
1540
                                        'success'   => false,
1541
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1542
                                    ]);
1543
                                }
1544
 
1545
                                $user->image = $target_filename;
1546
                                $userMapper->updateImage($user);
1547
                            }
1548
                        } catch (\Throwable $e) {
1549
                        } finally {
1550
                            if (file_exists($source)) {
1551
                                unlink($source);
1552
                            }
1553
                        }
1554
                    }
1555
                }
1556
 
1557
                $auth = new AuthEmailAdapter($this->adapter);
1558
                $auth->setData($email);
1559
 
1560
                $result = $auth->authenticate();
1561
                if ($result->getCode() == AuthResult::SUCCESS) {
1562
                    return $this->redirect()->toRoute('dashboard');
1563
                } else {
1564
                    $message = $result->getMessages()[0];
1565
                    if (!in_array($message, [
1566
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
1567
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
1568
                        'ERROR_ENTERED_PASS_INCORRECT_1'
1569
                    ])) {
1570
                    }
1571
 
1572
                    switch ($message) {
1573
                        case 'ERROR_USER_NOT_FOUND':
1574
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
1575
                            break;
1576
 
1577
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
1578
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
1579
                            break;
1580
 
1581
                        case 'ERROR_USER_IS_BLOCKED':
1582
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1583
                            break;
1584
 
1585
                        case 'ERROR_USER_IS_INACTIVE':
1586
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
1587
                            break;
1588
 
1589
 
1590
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
1591
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1592
                            break;
1593
 
1594
 
1595
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
1596
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
1597
                            break;
1598
 
1599
 
1600
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
1601
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
1602
                            break;
1603
 
1604
 
1605
                        default:
1606
                            $message = 'ERROR_UNKNOWN';
1607
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
1608
                            break;
1609
                    }
1610
 
1611
 
1612
 
1613
 
1614
                    return new JsonModel([
1615
                        'success'   => false,
1616
                        'data'   => $message
1617
                    ]);
1618
                }
1619
            } else {
1620
                $messages = [];
1621
 
1622
 
1623
 
1624
                $form_messages = (array) $form->getMessages();
1625
                foreach ($form_messages  as $fieldname => $field_messages) {
1626
 
1627
                    $messages[$fieldname] = array_values($field_messages);
1628
                }
1629
 
1630
                return new JsonModel([
1631
                    'success'   => false,
1632
                    'data'   => $messages
1633
                ]);
1634
            }
1635
        } else {
1636
            $data = [
1637
                'success' => false,
1638
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1639
            ];
1640
 
1641
            return new JsonModel($data);
1642
        }
1643
 
1644
        return new JsonModel($data);
1645
    }
1646
 
1647
    public function csrfAction()
1648
    {
1649
        $request = $this->getRequest();
1650
        if ($request->isGet()) {
95 efrain 1651
 
1652
            $jwtToken = null;
1653
            $headers = getallheaders();
1654
 
1655
 
1656
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
1657
 
1658
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
1659
 
1660
 
1661
                if (substr($token, 0, 6 ) == 'Bearer') {
1662
 
1663
                    $token = trim(substr($token, 7));
1664
 
1665
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
1666
                        $key = $this->config['leaderslinked.jwt.key'];
1667
 
1668
 
1669
                        try {
1670
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
1671
 
1672
 
1673
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
1674
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
1675
                            }
1676
 
1677
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
1678
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
1679
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
1680
                            if(!$jwtToken) {
1681
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
1682
                            }
1683
 
1684
                        } catch(\Exception $e) {
1685
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
1686
                        }
1687
                    } else {
1688
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
1689
                    }
1690
                } else {
1691
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
1692
                }
1693
            } else {
1694
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
1695
            }
1696
 
1697
            $jwtToken->csrf = md5(uniqid('CSFR-' . mt_rand(), true));
1698
            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
1699
            $jwtTokenMapper->update($jwtToken);
100 efrain 1700
 
1701
 
1702
            error_log('token id = ' . $jwtToken->id . ' csrf = ' . $jwtToken->csrf);
1 efrain 1703
 
1704
 
1705
            return new JsonModel([
1706
                'success' => true,
99 efrain 1707
                'data' => $jwtToken->csrf
1 efrain 1708
            ]);
1709
        } else {
1710
            return new JsonModel([
1711
                'success' => false,
1712
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1713
            ]);
1714
        }
1715
    }
1716
 
1717
    public function impersonateAction()
1718
    {
1719
        $request = $this->getRequest();
1720
        if ($request->isGet()) {
1721
            $user_uuid  = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));
1722
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
1723
            $timestamp  = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_NUMBER_INT);
1724
            $password   = Functions::sanitizeFilterString($this->params()->fromQuery('password'));
1725
 
1726
 
1727
            if (!$user_uuid || !$rand || !$timestamp || !$password) {
1728
                throw new \Exception('ERROR_PARAMETERS_ARE_INVALID');
1729
            }
1730
 
1731
 
1732
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1733
            $currentUserPlugin->clearIdentity();
1734
 
1735
 
1736
            $authAdapter = new AuthImpersonateAdapter($this->adapter, $this->config);
1737
            $authAdapter->setDataAdmin($user_uuid, $password, $timestamp, $rand);
1738
 
1739
            $authService = new AuthenticationService();
1740
            $result = $authService->authenticate($authAdapter);
1741
 
1742
 
1743
            if ($result->getCode() == AuthResult::SUCCESS) {
1744
                return $this->redirect()->toRoute('dashboard');
1745
            } else {
1746
                throw new \Exception($result->getMessages()[0]);
1747
            }
1748
        }
1749
 
1750
        return new JsonModel([
1751
            'success' => false,
1752
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1753
        ]);
1754
    }
1755
}