Proyectos de Subversion LeadersLinked - Services

Rev

Rev 191 | Rev 249 | 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;
211 efrain 51
use LeadersLinked\Form\Auth\SigninDebugForm;
1 efrain 52
 
53
 
54
 
55
class AuthController extends AbstractActionController
56
{
57
    /**
58
     *
59
     * @var \Laminas\Db\Adapter\AdapterInterface
60
     */
61
    private $adapter;
62
 
63
    /**
64
     *
65
     * @var \LeadersLinked\Cache\CacheInterface
66
     */
67
    private $cache;
68
 
69
 
70
    /**
71
     *
72
     * @var \Laminas\Log\LoggerInterface
73
     */
74
    private $logger;
75
 
76
    /**
77
     *
78
     * @var array
79
     */
80
    private $config;
81
 
82
 
83
    /**
84
     *
85
     * @var \Laminas\Mvc\I18n\Translator
86
     */
87
    private $translator;
88
 
89
 
90
    /**
91
     *
92
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
93
     * @param \LeadersLinked\Cache\CacheInterface $cache
94
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
95
     * @param array $config
96
     * @param \Laminas\Mvc\I18n\Translator $translator
97
     */
98
    public function __construct($adapter, $cache, $logger, $config, $translator)
99
    {
100
        $this->adapter      = $adapter;
101
        $this->cache        = $cache;
102
        $this->logger       = $logger;
103
        $this->config       = $config;
104
        $this->translator   = $translator;
105
    }
106
 
107
    public function signinAction()
108
    {
109
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
110
        $currentNetwork = $currentNetworkPlugin->getNetwork();
111
 
112
        $request = $this->getRequest();
113
 
114
        if ($request->isPost()) {
115
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
116
            $currentNetwork = $currentNetworkPlugin->getNetwork();
24 efrain 117
 
118
            $jwtToken = null;
119
            $headers = getallheaders();
33 efrain 120
 
53 efrain 121
 
34 efrain 122
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
24 efrain 123
 
34 efrain 124
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
125
 
126
 
24 efrain 127
                if (substr($token, 0, 6 ) == 'Bearer') {
128
 
129
                    $token = trim(substr($token, 7));
130
 
131
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
132
                        $key = $this->config['leaderslinked.jwt.key'];
133
 
134
 
135
                        try {
136
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
137
 
138
 
139
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
140
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
141
                            }
142
 
143
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
144
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
145
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
146
                            if(!$jwtToken) {
147
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
148
                            }
1 efrain 149
 
24 efrain 150
                        } catch(\Exception $e) {
151
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
152
                        }
153
                    } else {
154
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
155
                    }
156
                } else {
157
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
158
                }
159
            } else {
160
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
161
            }
1 efrain 162
 
24 efrain 163
 
1 efrain 164
            $form = new  SigninForm($this->config);
165
            $dataPost = $request->getPost()->toArray();
144 efrain 166
 
1 efrain 167
            if (empty($_SESSION['aes'])) {
168
                return new JsonModel([
169
                    'success'   => false,
170
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
171
                ]);
172
            }
28 efrain 173
 
1 efrain 174
            if (!empty($dataPost['email'])) {
175
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
176
            }
177
 
178
 
179
            if (!empty($dataPost['password'])) {
180
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
144 efrain 181
            }
1 efrain 182
 
183
            $form->setData($dataPost);
184
 
185
            if ($form->isValid()) {
24 efrain 186
 
1 efrain 187
                $dataPost = (array) $form->getData();
188
 
189
                $email      = $dataPost['email'];
190
                $password   = $dataPost['password'];
191
                $remember   = $dataPost['remember'];
30 efrain 192
 
193
 
31 efrain 194
 
1 efrain 195
 
196
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
197
                $authAdapter->setData($email, $password, $currentNetwork->id);
198
                $authService = new AuthenticationService();
199
 
200
                $result = $authService->authenticate($authAdapter);
201
 
202
                if ($result->getCode() == AuthResult::SUCCESS) {
203
 
155 efrain 204
                    $identity = $result->getIdentity();
205
 
1 efrain 206
 
207
                    $userMapper = UserMapper::getInstance($this->adapter);
155 efrain 208
                    $user = $userMapper->fetchOne($identity['user_id']);
36 efrain 209
 
210
 
211
                    if($token) {
37 efrain 212
                        $jwtToken->user_id = $user->id;
36 efrain 213
                        $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
37 efrain 214
                        $jwtTokenMapper->update($jwtToken);
36 efrain 215
                    }
216
 
1 efrain 217
 
218
                    $navigator = get_browser(null, true);
219
                    $device_type    =  isset($navigator['device_type']) ? $navigator['device_type'] : '';
220
                    $platform       =  isset($navigator['platform']) ? $navigator['platform'] : '';
221
                    $browser        =  isset($navigator['browser']) ? $navigator['browser'] : '';
222
 
223
 
224
                    $istablet = isset($navigator['istablet']) ?  intval($navigator['istablet']) : 0;
225
                    $ismobiledevice = isset($navigator['ismobiledevice']) ? intval($navigator['ismobiledevice']) : 0;
226
                    $version = isset($navigator['version']) ? $navigator['version'] : '';
227
 
228
 
229
                    $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
230
                    $userBrowser = $userBrowserMapper->fetch($user->id, $device_type, $platform, $browser);
231
                    if ($userBrowser) {
232
                        $userBrowserMapper->update($userBrowser);
233
                    } else {
234
                        $userBrowser = new UserBrowser();
235
                        $userBrowser->user_id           = $user->id;
236
                        $userBrowser->browser           = $browser;
237
                        $userBrowser->platform          = $platform;
238
                        $userBrowser->device_type       = $device_type;
239
                        $userBrowser->is_tablet         = $istablet;
240
                        $userBrowser->is_mobile_device  = $ismobiledevice;
241
                        $userBrowser->version           = $version;
242
 
243
                        $userBrowserMapper->insert($userBrowser);
244
                    }
245
                    //
246
 
247
                    $ip = Functions::getUserIP();
248
                    $ip = $ip == '127.0.0.1' ? '148.240.211.148' : $ip;
249
 
250
                    $userIpMapper = UserIpMapper::getInstance($this->adapter);
251
                    $userIp = $userIpMapper->fetch($user->id, $ip);
252
                    if (empty($userIp)) {
253
 
254
                        if ($this->config['leaderslinked.runmode.sandbox']) {
255
                            $filename = $this->config['leaderslinked.geoip2.production_database'];
256
                        } else {
257
                            $filename = $this->config['leaderslinked.geoip2.sandbox_database'];
258
                        }
259
 
260
                        $reader = new GeoIp2Reader($filename); //GeoIP2-City.mmdb');
261
                        $record = $reader->city($ip);
262
                        if ($record) {
263
                            $userIp = new UserIp();
264
                            $userIp->user_id = $user->id;
265
                            $userIp->city = !empty($record->city->name) ? Functions::utf8_decode($record->city->name) : '';
266
                            $userIp->state_code = !empty($record->mostSpecificSubdivision->isoCode) ? Functions::utf8_decode($record->mostSpecificSubdivision->isoCode) : '';
267
                            $userIp->state_name = !empty($record->mostSpecificSubdivision->name) ? Functions::utf8_decode($record->mostSpecificSubdivision->name) : '';
268
                            $userIp->country_code = !empty($record->country->isoCode) ? Functions::utf8_decode($record->country->isoCode) : '';
269
                            $userIp->country_name = !empty($record->country->name) ? Functions::utf8_decode($record->country->name) : '';
270
                            $userIp->ip = $ip;
271
                            $userIp->latitude = !empty($record->location->latitude) ? $record->location->latitude : 0;
272
                            $userIp->longitude = !empty($record->location->longitude) ? $record->location->longitude : 0;
273
                            $userIp->postal_code = !empty($record->postal->code) ? $record->postal->code : '';
274
 
275
                            $userIpMapper->insert($userIp);
276
                        }
277
                    } else {
278
                        $userIpMapper->update($userIp);
279
                    }
280
 
24 efrain 281
                    /*
1 efrain 282
                    if ($remember) {
283
                        $expired = time() + 365 * 24 * 60 * 60;
284
 
285
                        $cookieEmail = new SetCookie('email', $email, $expired);
286
                    } else {
287
                        $expired = time() - 7200;
288
                        $cookieEmail = new SetCookie('email', '', $expired);
289
                    }
290
 
291
 
292
                    $response = $this->getResponse();
293
                    $response->getHeaders()->addHeader($cookieEmail);
24 efrain 294
                    */
295
 
296
 
1 efrain 297
 
298
 
299
 
300
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
301
 
302
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
303
 
304
                    if ($user_share_invitation) {
305
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
306
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
307
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
308
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
309
 
310
                            if ($connection) {
311
 
312
                                if ($connection->status != Connection::STATUS_ACCEPTED) {
313
                                    $connectionMapper->approve($connection);
314
                                }
315
                            } else {
316
                                $connection = new Connection();
317
                                $connection->request_from = $user->id;
318
                                $connection->request_to = $userRedirect->id;
319
                                $connection->status = Connection::STATUS_ACCEPTED;
320
 
321
                                $connectionMapper->insert($connection);
322
                            }
323
                        }
324
                    }
325
 
326
 
327
 
328
                    $data = [
329
                        'success'   => true,
330
                        'data'      => $this->url()->fromRoute('dashboard'),
331
                    ];
332
 
333
                    $this->cache->removeItem('user_share_invitation');
334
                } else {
335
 
336
                    $message = $result->getMessages()[0];
337
                    if (!in_array($message, [
338
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
339
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
340
                        'ERROR_ENTERED_PASS_INCORRECT_1', 'ERROR_USER_REQUEST_ACCESS_IS_PENDING', 'ERROR_USER_REQUEST_ACCESS_IS_REJECTED'
341
 
342
 
343
                    ])) {
344
                    }
345
 
346
                    switch ($message) {
347
                        case 'ERROR_USER_NOT_FOUND':
348
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
349
                            break;
350
 
351
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
352
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
353
                            break;
354
 
355
                        case 'ERROR_USER_IS_BLOCKED':
356
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
357
                            break;
358
 
359
                        case 'ERROR_USER_IS_INACTIVE':
360
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
361
                            break;
362
 
363
 
364
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
365
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
366
                            break;
367
 
368
 
369
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
370
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
371
                            break;
372
 
373
 
374
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
375
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
376
                            break;
377
 
378
 
379
                        case 'ERROR_USER_REQUEST_ACCESS_IS_PENDING':
380
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Falta verificar que pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
381
                            break;
382
 
383
                        case  'ERROR_USER_REQUEST_ACCESS_IS_REJECTED':
384
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Rechazado por no pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
385
                            break;
386
 
387
 
388
                        default:
389
                            $message = 'ERROR_UNKNOWN';
390
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
391
                            break;
392
                    }
393
 
394
 
395
 
396
 
397
                    $data = [
398
                        'success'   => false,
399
                        'data'   => $message
400
                    ];
401
                }
402
 
67 efrain 403
                return new JsonModel($data);
1 efrain 404
            } else {
405
                $messages = [];
406
 
407
 
408
 
409
                $form_messages = (array) $form->getMessages();
410
                foreach ($form_messages  as $fieldname => $field_messages) {
411
 
412
                    $messages[$fieldname] = array_values($field_messages);
413
                }
67 efrain 414
 
415
                return new JsonModel([
1 efrain 416
                    'success'   => false,
417
                    'data'   => $messages
67 efrain 418
                ]);
1 efrain 419
            }
420
        } else if ($request->isGet()) {
421
 
120 efrain 422
            $aes = '';
107 efrain 423
            $jwtToken = null;
424
            $headers = getallheaders();
1 efrain 425
 
23 efrain 426
 
107 efrain 427
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
428
 
429
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
430
 
431
 
432
                if (substr($token, 0, 6 ) == 'Bearer') {
433
 
434
                    $token = trim(substr($token, 7));
435
 
436
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
437
                        $key = $this->config['leaderslinked.jwt.key'];
438
 
439
 
440
                        try {
441
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
442
 
443
 
444
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
445
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
446
                            }
447
 
448
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
449
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
450
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
451
                        } catch(\Exception $e) {
452
                            //Token invalido
453
                        }
454
                    }
455
                }
1 efrain 456
            }
23 efrain 457
 
107 efrain 458
            if(!$jwtToken) {
23 efrain 459
 
107 efrain 460
                $aes = Functions::generatePassword(16);
23 efrain 461
 
107 efrain 462
                $jwtToken = new JwtToken();
463
                $jwtToken->aes = $aes;
23 efrain 464
 
107 efrain 465
                $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
466
                if($jwtTokenMapper->insert($jwtToken)) {
467
                    $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
468
                }
469
 
470
                $token = '';
471
 
472
                if(!empty($this->config['leaderslinked.jwt.key'])) {
473
                    $issuedAt   = new \DateTimeImmutable();
474
                    $expire     = $issuedAt->modify('+24 hours')->getTimestamp();
475
                    $serverName = $_SERVER['HTTP_HOST'];
476
                    $payload = [
477
                        'iat'  => $issuedAt->getTimestamp(),
478
                        'iss'  => $serverName,
479
                        'nbf'  => $issuedAt->getTimestamp(),
480
                        'exp'  => $expire,
481
                        'uuid' => $jwtToken->uuid,
482
                    ];
483
 
484
 
485
                    $key = $this->config['leaderslinked.jwt.key'];
486
                    $token = JWT::encode($payload, $key, 'HS256');
487
                }
23 efrain 488
            }
489
 
490
 
491
 
107 efrain 492
 
493
 
1 efrain 494
 
23 efrain 495
 
1 efrain 496
            if ($this->config['leaderslinked.runmode.sandbox']) {
497
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
498
            } else {
499
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
500
            }
501
 
502
 
503
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
504
 
505
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
506
            if ($sandbox) {
507
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
508
            } else {
509
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
510
            }
149 efrain 511
 
1 efrain 512
 
189 efrain 513
            $parts = explode('.', $currentNetwork->main_hostname);
514
            if($parts[1] === 'com') {
515
                $replace_main = false;
516
            } else {
517
                $replace_main = true;
518
            }
148 efrain 519
 
520
 
189 efrain 521
 
148 efrain 522
            $logo_url = $this->url()->fromRoute('storage-network', ['type' => 'logo'],['force_canonical' => true]);
189 efrain 523
            if($replace_main) {
524
                $logo_url = str_replace($currentNetwork->main_hostname, $currentNetwork->service_hostname, $logo_url);
525
            }
526
 
527
 
191 efrain 528
 
529
 
148 efrain 530
            if($currentNetwork->alternative_hostname) {
531
                $logo_url = str_replace($currentNetwork->alternative_hostname, $currentNetwork->service_hostname, $logo_url);
532
 
533
            }
534
 
535
 
536
            $navbar_url = $this->url()->fromRoute('storage-network', ['type' => 'navbar'],['force_canonical' => true]);
189 efrain 537
            if($replace_main) {
538
                $navbar_url = str_replace($currentNetwork->main_hostname, $currentNetwork->service_hostname, $navbar_url);
539
            }
148 efrain 540
            if($currentNetwork->alternative_hostname) {
541
                $navbar_url = str_replace($currentNetwork->alternative_hostname, $currentNetwork->service_hostname, $navbar_url);
542
 
543
            }
544
 
545
 
546
            $favico_url= $this->url()->fromRoute('storage-network', ['type' => 'favico'],['force_canonical' => true]);
189 efrain 547
            if($replace_main) {
548
                $favico_url = str_replace($currentNetwork->main_hostname, $currentNetwork->service_hostname, $favico_url);
549
            }
148 efrain 550
            if($currentNetwork->alternative_hostname) {
551
                $favico_url = str_replace($currentNetwork->alternative_hostname, $currentNetwork->service_hostname, $favico_url);
552
 
553
            }
150 efrain 554
 
1 efrain 555
 
151 efrain 556
 
1 efrain 557
            $data = [
23 efrain 558
                'google_map_key'                => $google_map_key,
559
                'email'                         => '',
560
                'remember'                      => false,
561
                'site_key'                      => $site_key,
562
                'theme_id'                      => $currentNetwork->theme_id,
563
                'aes'                           => $aes,
564
                'jwt'                           => $token,
565
                'defaultNetwork'                => $currentNetwork->default,
566
                'access_usign_social_networks'  => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
148 efrain 567
                'logo_url'                      => $logo_url,
568
                'navbar_url'                    => $navbar_url,
569
                'favico_url'                    => $favico_url,
108 efrain 570
                'intro'                         => $currentNetwork->intro ? $currentNetwork->intro : '',
107 efrain 571
                'is_logged_in'                  => $jwtToken->user_id ? true : false,
1 efrain 572
 
573
            ];
49 efrain 574
 
575
            $data = [
576
                'success' => true,
50 efrain 577
                'data' =>  $data
49 efrain 578
            ];
1 efrain 579
 
580
        } else {
581
            $data = [
582
                'success' => false,
583
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
584
            ];
585
 
67 efrain 586
            return new JsonModel($data);
1 efrain 587
        }
588
 
67 efrain 589
        return new JsonModel($data);
1 efrain 590
    }
591
 
592
    public function facebookAction()
593
    {
594
 
595
        $request = $this->getRequest();
596
        if ($request->isGet()) {
597
            /*
598
          //  try {
599
                $app_id = $this->config['leaderslinked.facebook.app_id'];
600
                $app_password = $this->config['leaderslinked.facebook.app_password'];
601
                $app_graph_version = $this->config['leaderslinked.facebook.app_graph_version'];
602
                //$app_url_auth = $this->config['leaderslinked.facebook.app_url_auth'];
603
                //$redirect_url = $this->config['leaderslinked.facebook.app_redirect_url'];
604
 
605
                [facebook]
606
                app_id=343770226993130
607
                app_password=028ee729090fd591e50a17a786666c12
608
                app_graph_version=v17
609
                app_redirect_url=https://leaderslinked.com/oauth/facebook
610
 
611
                https://www.facebook.com/v17.0/dialog/oauth?client_id=343770226993130&redirect_uri= https://dev.leaderslinked.com/oauth/facebook&state=AE12345678
612
 
613
 
614
                $s = 'https://www.facebook.com/v17.0/dialog/oauth' .
615
                    '?client_id='
616
                    '&redirect_uri={"https://www.domain.com/login"}
617
                    '&state={"{st=state123abc,ds=123456789}"}
618
 
619
                $fb = new \Facebook\Facebook([
620
                    'app_id' => $app_id,
621
                    'app_secret' => $app_password,
622
                    'default_graph_version' => $app_graph_version,
623
                ]);
624
 
625
                $app_url_auth =  $this->url()->fromRoute('oauth/facebook', [], ['force_canonical' => true]);
626
                $helper = $fb->getRedirectLoginHelper();
627
                $permissions = ['email', 'public_profile']; // Optional permissions
628
                $facebookUrl = $helper->getLoginUrl($app_url_auth, $permissions);
629
 
630
 
631
 
632
                return new JsonModel([
633
                    'success' => false,
634
                    'data' => $facebookUrl
635
                ]);
636
            } catch (\Throwable $e) {
637
                return new JsonModel([
638
                    'success' => false,
639
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_FACEBOOK'
640
                ]);
641
            }*/
642
        } else {
643
            return new JsonModel([
644
                'success' => false,
645
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
646
            ]);
647
        }
648
    }
649
 
650
    public function twitterAction()
651
    {
652
        $request = $this->getRequest();
653
        if ($request->isGet()) {
654
 
655
            try {
656
                if ($this->config['leaderslinked.runmode.sandbox']) {
657
 
658
                    $twitter_api_key = $this->config['leaderslinked.twitter.sandbox_api_key'];
659
                    $twitter_api_secret = $this->config['leaderslinked.twitter.sandbox_api_secret'];
660
                } else {
661
                    $twitter_api_key = $this->config['leaderslinked.twitter.production_api_key'];
662
                    $twitter_api_secret = $this->config['leaderslinked.twitter.production_api_secret'];
663
                }
664
 
665
                /*
666
                 echo '$twitter_api_key = ' . $twitter_api_key . PHP_EOL;
667
                 echo '$twitter_api_secret = ' . $twitter_api_secret . PHP_EOL;
668
                 exit;
669
                 */
670
 
671
                //Twitter
672
                //$redirect_url =  $this->url()->fromRoute('oauth/twitter', [], ['force_canonical' => true]);
673
                $redirect_url = $this->config['leaderslinked.twitter.app_redirect_url'];
674
                $twitter = new \Abraham\TwitterOAuth\TwitterOAuth($twitter_api_key, $twitter_api_secret);
675
                $request_token =  $twitter->oauth('oauth/request_token', ['oauth_callback' => $redirect_url]);
676
                $twitterUrl = $twitter->url('oauth/authorize', ['oauth_token' => $request_token['oauth_token']]);
677
 
678
                $twitterSession = new \Laminas\Session\Container('twitter');
679
                $twitterSession->oauth_token = $request_token['oauth_token'];
680
                $twitterSession->oauth_token_secret = $request_token['oauth_token_secret'];
681
 
682
                return new JsonModel([
683
                    'success' => true,
684
                    'data' =>  $twitterUrl
685
                ]);
686
            } catch (\Throwable $e) {
687
                return new JsonModel([
688
                    'success' => false,
689
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_TWITTER'
690
                ]);
691
            }
692
        } else {
693
            return new JsonModel([
694
                'success' => false,
695
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
696
            ]);
697
        }
698
    }
699
 
700
    public function googleAction()
701
    {
702
        $request = $this->getRequest();
703
        if ($request->isGet()) {
704
 
705
            try {
706
 
707
 
708
                //Google
709
                $google = new \Google_Client();
710
                $google->setAuthConfig('data/google/auth-leaderslinked/apps.google.com_secreto_cliente.json');
711
                $google->setAccessType("offline");        // offline access
712
 
713
                $google->setIncludeGrantedScopes(true);   // incremental auth
714
 
715
                $google->addScope('profile');
716
                $google->addScope('email');
717
 
718
                // $redirect_url =  $this->url()->fromRoute('oauth/google', [], ['force_canonical' => true]);
719
                $redirect_url = $this->config['leaderslinked.google_auth.app_redirect_url'];
720
 
721
                $google->setRedirectUri($redirect_url);
722
                $googleUrl = $google->createAuthUrl();
723
 
724
                return new JsonModel([
725
                    'success' => true,
726
                    'data' =>  $googleUrl
727
                ]);
728
            } catch (\Throwable $e) {
729
                return new JsonModel([
730
                    'success' => false,
731
                    'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_GOOGLE'
732
                ]);
733
            }
734
        } else {
735
            return new JsonModel([
736
                'success' => false,
737
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
738
            ]);
739
        }
740
    }
741
 
742
    public function signoutAction()
743
    {
744
        $currentUserPlugin = $this->plugin('currentUserPlugin');
745
        $currentUser = $currentUserPlugin->getRawUser();
746
        if ($currentUserPlugin->hasImpersonate()) {
747
 
748
 
749
            $userMapper = UserMapper::getInstance($this->adapter);
750
            $userMapper->leaveImpersonate($currentUser->id);
751
 
752
            $networkMapper = NetworkMapper::getInstance($this->adapter);
753
            $network = $networkMapper->fetchOne($currentUser->network_id);
754
 
755
 
756
            if (!$currentUser->one_time_password) {
757
                $one_time_password = Functions::generatePassword(25);
758
 
759
                $currentUser->one_time_password = $one_time_password;
760
 
761
                $userMapper = UserMapper::getInstance($this->adapter);
762
                $userMapper->updateOneTimePassword($currentUser, $one_time_password);
763
            }
764
 
765
 
766
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
767
            if ($sandbox) {
768
                $salt = $this->config['leaderslinked.backend.sandbox_salt'];
769
            } else {
770
                $salt = $this->config['leaderslinked.backend.production_salt'];
771
            }
772
 
773
            $rand = 1000 + mt_rand(1, 999);
774
            $timestamp = time();
775
            $password = md5($currentUser->one_time_password . '-' . $rand . '-' . $timestamp . '-' . $salt);
776
 
777
            $params = [
778
                'user_uuid' => $currentUser->uuid,
779
                'password' => $password,
780
                'rand' => $rand,
781
                'time' => $timestamp,
782
            ];
783
 
784
            $currentUserPlugin->clearIdentity();
785
 
786
            return new JsonModel([
787
                'success'   => true,
788
                'data'      => [
789
                    'message' => 'LABEL_SIGNOUT_SUCCESSFULLY',
790
                    'url' => 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params)
791
                ],
792
 
793
            ]);
794
 
795
 
796
           // $url = 'https://' . $network->main_hostname . '/signin/impersonate' . '?' . http_build_query($params);
797
           // return $this->redirect()->toUrl($url);
798
        } else {
799
 
800
 
801
            if ($currentUserPlugin->hasIdentity()) {
802
 
803
                $this->logger->info('Desconexión de LeadersLinked', ['user_id' => $currentUserPlugin->getUserId(), 'ip' => Functions::getUserIP()]);
804
            }
805
 
806
            $currentUserPlugin->clearIdentity();
807
 
808
           // return $this->redirect()->toRoute('home');
809
 
810
            return new JsonModel([
811
                'success'   => true,
812
                'data'      => [
813
                    'message' => 'LABEL_SIGNOUT_SUCCESSFULLY',
814
                    'url' => '',
815
                ],
816
 
817
            ]);
818
        }
819
    }
820
 
821
 
822
    public function resetPasswordAction()
823
    {
824
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
825
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
826
 
827
 
828
        $code =  Functions::sanitizeFilterString($this->params()->fromRoute('code', ''));
829
 
830
        $userMapper = UserMapper::getInstance($this->adapter);
831
        $user = $userMapper->fetchOneByPasswordResetKeyAndNetworkId($code, $currentNetwork->id);
832
        if (!$user) {
833
            $this->logger->err('Restablecer contraseña - Error código no existe', ['ip' => Functions::getUserIP()]);
834
 
835
            return new JsonModel([
183 efrain 836
                'success'   => false,
1 efrain 837
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_IS_INVALID'
838
            ]);
839
 
840
        }
841
 
842
 
843
 
844
        $password_generated_on = strtotime($user->password_generated_on);
845
        $expiry_time = $password_generated_on + $this->config['leaderslinked.security.reset_password_expired'];
846
        if (time() > $expiry_time) {
847
            $this->logger->err('Restablecer contraseña - Error código expirado', ['ip' => Functions::getUserIP()]);
848
 
849
            return new JsonModel([
181 efrain 850
                'success'   => false,
1 efrain 851
                'data'      => 'ERROR_PASSWORD_RECOVER_CODE_HAS_EXPIRED'
852
            ]);
853
        }
854
 
855
        $request = $this->getRequest();
856
        if ($request->isPost()) {
857
            $dataPost = $request->getPost()->toArray();
858
            if (empty($_SESSION['aes'])) {
859
                return new JsonModel([
860
                    'success'   => false,
861
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
862
                ]);
863
 
864
 
865
            }
866
 
867
            if (!empty($dataPost['password'])) {
868
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
869
            }
870
            if (!empty($dataPost['confirmation'])) {
871
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
872
            }
873
 
874
 
875
 
876
            $form = new ResetPasswordForm($this->config);
877
            $form->setData($dataPost);
878
 
879
            if ($form->isValid()) {
880
                $data = (array) $form->getData();
881
                $password = $data['password'];
882
 
883
 
884
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
885
                $userPasswords = $userPasswordMapper->fetchAllByUserId($user->id);
886
 
887
                $oldPassword = false;
888
                foreach ($userPasswords as $userPassword) {
889
                    if (password_verify($password, $userPassword->password) || (md5($password) == $userPassword->password)) {
890
                        $oldPassword = true;
891
                        break;
892
                    }
893
                }
894
 
895
                if ($oldPassword) {
896
                    $this->logger->err('Restablecer contraseña - Error contraseña ya utilizada anteriormente', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
897
 
898
                    return new JsonModel([
899
                        'success'   => false,
900
                        'data'      => 'ERROR_PASSWORD_HAS_ALREADY_BEEN_USED'
901
 
902
                    ]);
903
                } else {
904
                    $password_hash = password_hash($password, PASSWORD_DEFAULT);
905
 
906
 
907
                    $result = $userMapper->updatePassword($user, $password_hash);
908
                    if ($result) {
909
 
910
                        $userPassword = new UserPassword();
911
                        $userPassword->user_id = $user->id;
912
                        $userPassword->password = $password_hash;
913
                        $userPasswordMapper->insert($userPassword);
914
 
915
 
916
                        $this->logger->info('Restablecer contraseña realizado', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
917
 
918
 
180 efrain 919
 
1 efrain 920
                        return new JsonModel([
921
                            'success'   => true,
138 efrain 922
                            'data'      => 'LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED'
1 efrain 923
 
924
                        ]);
925
                    } else {
926
                        $this->logger->err('Restablecer contraseña - Error desconocido', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
927
 
928
                        return new JsonModel([
929
                            'success'   => false,
930
                            'data'      => 'ERROR_THERE_WAS_AN_ERROR'
931
 
932
                        ]);
933
                    }
934
                }
935
            } else {
936
                $form_messages =  $form->getMessages('captcha');
937
                if (!empty($form_messages)) {
938
                    return new JsonModel([
939
                        'success'   => false,
940
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
941
                    ]);
942
                }
943
 
944
                $messages = [];
945
 
946
                $form_messages = (array) $form->getMessages();
947
                foreach ($form_messages  as $fieldname => $field_messages) {
948
                    $messages[$fieldname] = array_values($field_messages);
949
                }
950
 
951
                return new JsonModel([
952
                    'success'   => false,
953
                    'data'   => $messages
954
                ]);
955
            }
956
        } else if ($request->isGet()) {
957
 
958
            if (empty($_SESSION['aes'])) {
959
                $_SESSION['aes'] = Functions::generatePassword(16);
960
            }
961
 
962
            if ($this->config['leaderslinked.runmode.sandbox']) {
963
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
964
            } else {
965
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
966
            }
967
 
968
 
969
            return new JsonModel([
970
                'code' => $code,
971
                'site_key' => $site_key,
972
                'aes'       => $_SESSION['aes'],
973
                'defaultNetwork' => $currentNetwork->default,
974
            ]);
975
 
976
        }
977
 
978
 
979
 
980
        return new JsonModel([
981
            'success' => false,
982
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
983
        ]);
984
    }
985
 
986
    public function forgotPasswordAction()
987
    {
988
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
989
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
990
 
991
 
992
 
993
        $request = $this->getRequest();
994
        if ($request->isPost()) {
995
            $dataPost = $request->getPost()->toArray();
996
            if (empty($_SESSION['aes'])) {
997
                return new JsonModel([
998
                    'success'   => false,
999
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
1000
                ]);
1001
            }
1002
 
1003
            if (!empty($dataPost['email'])) {
1004
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
1005
            }
1006
 
1007
            $form = new ForgotPasswordForm($this->config);
1008
            $form->setData($dataPost);
1009
 
1010
            if ($form->isValid()) {
1011
                $dataPost = (array) $form->getData();
1012
                $email      = $dataPost['email'];
1013
 
1014
                $userMapper = UserMapper::getInstance($this->adapter);
1015
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
1016
                if (!$user) {
1017
                    $this->logger->err('Olvidó contraseña ' . $email . '- Email no existe ', ['ip' => Functions::getUserIP()]);
1018
 
1019
                    return new JsonModel([
1020
                        'success' => false,
1021
                        'data' =>  'ERROR_EMAIL_IS_NOT_REGISTERED'
1022
                    ]);
1023
                } else {
1024
                    if ($user->status == User::STATUS_INACTIVE) {
1025
                        return new JsonModel([
1026
                            'success' => false,
1027
                            'data' =>  'ERROR_USER_IS_INACTIVE'
1028
                        ]);
1029
                    } else if ($user->email_verified == User::EMAIL_VERIFIED_NO) {
1030
                        $this->logger->err('Olvidó contraseña - Email no verificado ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1031
 
1032
                        return new JsonModel([
1033
                            'success' => false,
1034
                            'data' => 'ERROR_EMAIL_HAS_NOT_BEEN_VERIFIED'
1035
                        ]);
1036
                    } else {
1037
                        $password_reset_key = md5($user->email . time());
1038
                        $userMapper->updatePasswordResetKey((int) $user->id, $password_reset_key);
1039
 
1040
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1041
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RESET_PASSWORD, $currentNetwork->id);
1042
                        if ($emailTemplate) {
1043
                            $arrayCont = [
1044
                                'firstname'             => $user->first_name,
1045
                                'lastname'              => $user->last_name,
1046
                                'other_user_firstname'  => '',
1047
                                'other_user_lastname'   => '',
1048
                                'company_name'          => '',
1049
                                'group_name'            => '',
1050
                                'content'               => '',
1051
                                'code'                  => '',
1052
                                'link'                  => $this->url()->fromRoute('reset-password', ['code' => $password_reset_key], ['force_canonical' => true])
1053
                            ];
1054
 
1055
                            $email = new QueueEmail($this->adapter);
1056
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1057
                        }
1058
 
1059
                        $this->logger->info('Olvidó contraseña - Se envio link de recuperación ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1060
 
1061
                        return new JsonModel([
1062
                            'success' => true,
180 efrain 1063
                            'data' => 'LABEL_RECOVERY_LINK_WAS_SENT_TO_YOUR_EMAIL'
1 efrain 1064
                        ]);
1065
                    }
1066
                }
1067
            } else {
1068
 
1069
 
1070
                $form_messages =  $form->getMessages('captcha');
1071
 
1072
 
1073
 
1074
                if (!empty($form_messages)) {
1075
                    return new JsonModel([
1076
                        'success'   => false,
1077
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
1078
                    ]);
1079
                }
1080
 
1081
                $messages = [];
1082
                $form_messages = (array) $form->getMessages();
1083
                foreach ($form_messages  as $fieldname => $field_messages) {
1084
                    $messages[$fieldname] = array_values($field_messages);
1085
                }
1086
 
1087
                return new JsonModel([
1088
                    'success'   => false,
1089
                    'data'      => $messages
1090
                ]);
1091
            }
1092
        } else  if ($request->isGet()) {
1093
 
1094
            if (empty($_SESSION['aes'])) {
1095
                $_SESSION['aes'] = Functions::generatePassword(16);
1096
            }
1097
 
1098
            if ($this->config['leaderslinked.runmode.sandbox']) {
1099
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
1100
            } else {
1101
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
1102
            }
1103
 
1104
            return new JsonModel([
1105
                'site_key'  => $site_key,
1106
                'aes'       => $_SESSION['aes'],
1107
                'defaultNetwork' => $currentNetwork->default,
1108
            ]);
1109
        }
1110
 
1111
        return new JsonModel([
1112
            'success' => false,
1113
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1114
        ]);
1115
    }
1116
 
1117
    public function signupAction()
1118
    {
1119
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1120
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1121
 
1122
 
1123
        $request = $this->getRequest();
1124
        if ($request->isPost()) {
1125
            $dataPost = $request->getPost()->toArray();
1126
 
1127
            if (empty($_SESSION['aes'])) {
1128
                return new JsonModel([
1129
                    'success'   => false,
1130
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
1131
                ]);
1132
            }
1133
 
1134
            if (!empty($dataPost['email'])) {
1135
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $_SESSION['aes']);
1136
            }
1137
 
1138
            if (!empty($dataPost['password'])) {
1139
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $_SESSION['aes']);
1140
            }
1141
 
1142
            if (!empty($dataPost['confirmation'])) {
1143
                $dataPost['confirmation'] = CryptoJsAes::decrypt($dataPost['confirmation'], $_SESSION['aes']);
1144
            }
1145
 
1146
            if (empty($dataPost['is_adult'])) {
1147
                $dataPost['is_adult'] = User::IS_ADULT_NO;
1148
            } else {
1149
                $dataPost['is_adult'] = $dataPost['is_adult'] == User::IS_ADULT_YES ? User::IS_ADULT_YES : User::IS_ADULT_NO;
1150
            }
1151
 
1152
 
1153
 
1154
            $form = new SignupForm($this->config);
1155
            $form->setData($dataPost);
1156
 
1157
            if ($form->isValid()) {
1158
                $dataPost = (array) $form->getData();
1159
 
1160
                $email = $dataPost['email'];
1161
 
1162
                $userMapper = UserMapper::getInstance($this->adapter);
1163
                $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
1164
                if ($user) {
1165
                    $this->logger->err('Registro ' . $email . '- Email ya  existe ', ['ip' => Functions::getUserIP()]);
1166
 
1167
 
1168
 
1169
                    return new JsonModel([
1170
                        'success' => false,
1171
                        'data' => 'ERROR_EMAIL_IS_REGISTERED'
1172
                    ]);
1173
                } else {
1174
 
1175
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
1176
 
1177
 
1178
                    if ($user_share_invitation) {
1179
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
1180
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE) {
1181
                            $password_hash = password_hash($dataPost['password'], PASSWORD_DEFAULT);
1182
 
1183
                            $user = new User();
1184
                            $user->network_id           = $currentNetwork->id;
1185
                            $user->email                = $dataPost['email'];
1186
                            $user->first_name           = $dataPost['first_name'];
1187
                            $user->last_name            = $dataPost['last_name'];
1188
                            $user->usertype_id          = UserType::USER;
1189
                            $user->password             = $password_hash;
1190
                            $user->password_updated_on  = date('Y-m-d H:i:s');
1191
                            $user->status               = User::STATUS_ACTIVE;
1192
                            $user->blocked              = User::BLOCKED_NO;
1193
                            $user->email_verified       = User::EMAIL_VERIFIED_YES;
1194
                            $user->login_attempt        = 0;
1195
                            $user->is_adult             = $dataPost['is_adult'];
1196
                            $user->request_access       = User::REQUEST_ACCESS_APPROVED;
1197
 
1198
 
1199
 
1200
 
1201
 
1202
                            if ($userMapper->insert($user)) {
1203
 
1204
                                $userPassword = new UserPassword();
1205
                                $userPassword->user_id = $user->id;
1206
                                $userPassword->password = $password_hash;
1207
 
1208
                                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1209
                                $userPasswordMapper->insert($userPassword);
1210
 
1211
 
1212
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1213
                                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
1214
 
1215
                                if ($connection) {
1216
 
1217
                                    if ($connection->status != Connection::STATUS_ACCEPTED) {
1218
                                        $connectionMapper->approve($connection);
1219
                                    }
1220
                                } else {
1221
                                    $connection = new Connection();
1222
                                    $connection->request_from = $user->id;
1223
                                    $connection->request_to = $userRedirect->id;
1224
                                    $connection->status = Connection::STATUS_ACCEPTED;
1225
 
1226
                                    $connectionMapper->insert($connection);
1227
                                }
1228
 
1229
 
1230
                                $this->cache->removeItem('user_share_invitation');
1231
 
1232
 
1233
 
1234
                                $data = [
1235
                                    'success'   => true,
1236
                                    'data'      => $this->url()->fromRoute('home'),
1237
                                ];
1238
 
1239
 
1240
                                $this->logger->info('Registro con Exito ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1241
 
1242
                                return new JsonModel($data);
1243
                            }
1244
                        }
1245
                    }
1246
 
1247
 
1248
 
1249
 
1250
                    $timestamp = time();
1251
                    $activation_key = sha1($dataPost['email'] . uniqid() . $timestamp);
1252
 
1253
                    $password_hash = password_hash($dataPost['password'], PASSWORD_DEFAULT);
1254
 
1255
                    $user = new User();
1256
                    $user->network_id           = $currentNetwork->id;
1257
                    $user->email                = $dataPost['email'];
1258
                    $user->first_name           = $dataPost['first_name'];
1259
                    $user->last_name            = $dataPost['last_name'];
1260
                    $user->usertype_id          = UserType::USER;
1261
                    $user->password             = $password_hash;
1262
                    $user->password_updated_on  = date('Y-m-d H:i:s');
1263
                    $user->activation_key       = $activation_key;
1264
                    $user->status               = User::STATUS_INACTIVE;
1265
                    $user->blocked              = User::BLOCKED_NO;
1266
                    $user->email_verified       = User::EMAIL_VERIFIED_NO;
1267
                    $user->login_attempt        = 0;
1268
 
1269
                    if ($currentNetwork->default == Network::DEFAULT_YES) {
1270
                        $user->request_access = User::REQUEST_ACCESS_APPROVED;
1271
                    } else {
1272
                        $user->request_access = User::REQUEST_ACCESS_PENDING;
1273
                    }
1274
 
1275
 
1276
 
1277
                    if ($userMapper->insert($user)) {
1278
 
1279
                        $userPassword = new UserPassword();
1280
                        $userPassword->user_id = $user->id;
1281
                        $userPassword->password = $password_hash;
1282
 
1283
                        $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
1284
                        $userPasswordMapper->insert($userPassword);
1285
 
1286
                        $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1287
                        $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_USER_REGISTER, $currentNetwork->id);
1288
                        if ($emailTemplate) {
1289
                            $arrayCont = [
1290
                                'firstname'             => $user->first_name,
1291
                                'lastname'              => $user->last_name,
1292
                                'other_user_firstname'  => '',
1293
                                'other_user_lastname'   => '',
1294
                                'company_name'          => '',
1295
                                'group_name'            => '',
1296
                                'content'               => '',
1297
                                'code'                  => '',
1298
                                'link'                  => $this->url()->fromRoute('activate-account', ['code' => $user->activation_key], ['force_canonical' => true])
1299
                            ];
1300
 
1301
                            $email = new QueueEmail($this->adapter);
1302
                            $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1303
                        }
1304
 
1305
                        $this->logger->info('Registro con Exito ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1306
 
1307
                        return new JsonModel([
1308
                            'success' => true,
180 efrain 1309
                            'data' => 'LABEL_REGISTRATION_DONE'
1 efrain 1310
                        ]);
1311
                    } else {
1312
                        $this->logger->err('Registro ' . $email . '- Ha ocurrido un error ', ['ip' => Functions::getUserIP()]);
1313
 
1314
                        return new JsonModel([
1315
                            'success' => false,
1316
                            'data' => 'ERROR_THERE_WAS_AN_ERROR'
1317
                        ]);
1318
                    }
1319
                }
1320
            } else {
1321
 
1322
                $form_messages =  $form->getMessages('captcha');
1323
                if (!empty($form_messages)) {
1324
                    return new JsonModel([
1325
                        'success'   => false,
1326
                        'data'      => 'ERROR_RECAPTCHA_EMPTY'
1327
                    ]);
1328
                }
1329
 
1330
                $messages = [];
1331
 
1332
                $form_messages = (array) $form->getMessages();
1333
                foreach ($form_messages  as $fieldname => $field_messages) {
1334
                    $messages[$fieldname] = array_values($field_messages);
1335
                }
1336
 
1337
                return new JsonModel([
1338
                    'success'   => false,
1339
                    'data'   => $messages
1340
                ]);
1341
            }
1342
        } else if ($request->isGet()) {
1343
 
1344
            if (empty($_SESSION['aes'])) {
1345
                $_SESSION['aes'] = Functions::generatePassword(16);
1346
            }
1347
 
1348
            if ($this->config['leaderslinked.runmode.sandbox']) {
1349
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
1350
            } else {
1351
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
1352
            }
1353
 
1354
            $email      = isset($_COOKIE['email']) ? $_COOKIE['email'] : '';
1355
 
1356
            return new JsonModel([
1357
                'site_key'  => $site_key,
1358
                'aes'       => $_SESSION['aes'],
1359
                'defaultNetwork' => $currentNetwork->default,
1360
            ]);
1361
        }
1362
 
1363
        return new JsonModel([
1364
            'success' => false,
1365
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1366
        ]);
1367
    }
1368
 
1369
    public function activateAccountAction()
1370
    {
1371
 
1372
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1373
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1374
 
1375
 
1376
 
1377
        $request = $this->getRequest();
1378
        if ($request->isGet()) {
1379
            $code   =  Functions::sanitizeFilterString($this->params()->fromRoute('code'));
1380
            $userMapper = UserMapper::getInstance($this->adapter);
1381
            $user = $userMapper->fetchOneByActivationKeyAndNetworkId($code, $currentNetwork->id);
1382
 
1383
 
180 efrain 1384
 
1 efrain 1385
            if ($user) {
1386
                if (User::EMAIL_VERIFIED_YES == $user->email_verified) {
180 efrain 1387
 
1 efrain 1388
                    $this->logger->err('Verificación email - El código ya habia sido verificao ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
180 efrain 1389
 
1390
                    $response = [
1391
                        'success' => false,
1392
                        'data' => 'ERROR_EMAIL_HAS_BEEN_PREVIOUSLY_VERIFIED'
1393
                    ];
1394
 
1395
                    return new JsonModel($response);
1 efrain 1396
                } else {
1397
 
1398
                    if ($userMapper->activateAccount((int) $user->id)) {
1399
 
1400
                        $this->logger->info('Verificación email realizada ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
1401
 
1402
 
1403
 
1404
                        $user_share_invitation = $this->cache->getItem('user_share_invitation');
1405
 
1406
                        if ($user_share_invitation) {
1407
                            $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
1408
                            if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
1409
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1410
                                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
1411
 
1412
                                if ($connection) {
1413
 
1414
                                    if ($connection->status != Connection::STATUS_ACCEPTED) {
1415
                                        $connectionMapper->approve($connection);
1416
                                    }
1417
                                } else {
1418
                                    $connection = new Connection();
1419
                                    $connection->request_from = $user->id;
1420
                                    $connection->request_to = $userRedirect->id;
1421
                                    $connection->status = Connection::STATUS_ACCEPTED;
1422
 
1423
                                    $connectionMapper->insert($connection);
1424
                                }
1425
                            }
1426
                        }
1427
 
1428
 
1429
 
1430
                        $this->cache->removeItem('user_share_invitation');
1431
 
1432
 
1433
                        if ($currentNetwork->default == Network::DEFAULT_YES) {
180 efrain 1434
 
1435
                            $response = [
1436
                                'success' => true,
1437
                                'data' => 'LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED'
1438
                            ];
1439
 
1440
                            return new JsonModel($response);
1441
 
1442
 
1 efrain 1443
                        } else {
1444
 
1445
                            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1446
                            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_REQUEST_ACCESS_PENDING, $currentNetwork->id);
1447
 
1448
                            if ($emailTemplate) {
1449
                                $arrayCont = [
1450
                                    'firstname'             => $user->first_name,
1451
                                    'lastname'              => $user->last_name,
1452
                                    'other_user_firstname'  => '',
1453
                                    'other_user_lastname'   => '',
1454
                                    'company_name'          => '',
1455
                                    'group_name'            => '',
1456
                                    'content'               => '',
1457
                                    'code'                  => '',
1458
                                    'link'                  => '',
1459
                                ];
1460
 
1461
                                $email = new QueueEmail($this->adapter);
1462
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1463
                            }
180 efrain 1464
 
1465
                            $response = [
1466
                                'success' => true,
1467
                                'data' => 'LABEL_YOUR_EMAIL_HAS_BEEN_VERIFIED_WE_ARE_VERIFYING_YOUR_INFORMATION'
1468
                            ];
1469
 
1470
                            return new JsonModel($response);
1 efrain 1471
 
1472
 
1473
                        }
1474
                    } else {
1475
                        $this->logger->err('Verificación email - Ha ocurrido un error ', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
180 efrain 1476
 
1477
                        $response = [
1478
                            'success' => false,
1479
                            'data' => 'ERROR_THERE_WAS_AN_ERROR'
1480
                        ];
1481
 
1482
                        return new JsonModel($response);
1 efrain 1483
 
1484
                    }
1485
                }
1486
            } else {
180 efrain 1487
 
1488
 
1 efrain 1489
                $this->logger->err('Verificación email - El código no existe ', ['ip' => Functions::getUserIP()]);
1490
 
180 efrain 1491
                $response = [
1492
                    'success' => false,
1493
                    'data' =>'ERROR_ACTIVATION_CODE_IS_NOT_VALID'
1494
                ];
1495
 
1496
                return new JsonModel($response);
1497
 
1498
 
1499
 
1 efrain 1500
            }
1501
 
180 efrain 1502
 
1 efrain 1503
        } else {
1504
            $response = [
1505
                'success' => false,
1506
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1507
            ];
1508
        }
1509
 
1510
        return new JsonModel($response);
1511
    }
1512
 
1513
 
1514
 
1515
    public function onroomAction()
1516
    {
1517
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1518
        $currentNetwork  = $currentNetworkPlugin->getNetwork();
1519
 
1520
 
1521
 
1522
        $request = $this->getRequest();
1523
 
1524
        if ($request->isPost()) {
1525
 
1526
            $dataPost = $request->getPost()->toArray();
1527
 
1528
 
1529
            $form = new  MoodleForm();
1530
            $form->setData($dataPost);
1531
            if ($form->isValid()) {
1532
 
1533
                $dataPost   = (array) $form->getData();
1534
                $username   = $dataPost['username'];
1535
                $password   = $dataPost['password'];
1536
                $timestamp  = $dataPost['timestamp'];
1537
                $rand       = $dataPost['rand'];
1538
                $data       = $dataPost['data'];
1539
 
1540
                $config_username    = $this->config['leaderslinked.moodle.username'];
1541
                $config_password    = $this->config['leaderslinked.moodle.password'];
1542
                $config_rsa_n       = $this->config['leaderslinked.moodle.rsa_n'];
1543
                $config_rsa_d       = $this->config['leaderslinked.moodle.rsa_d'];
1544
                $config_rsa_e       = $this->config['leaderslinked.moodle.rsa_e'];
1545
 
1546
 
1547
 
1548
 
1549
                if (empty($username) || empty($password) || empty($timestamp) || empty($rand) || !is_integer($rand)) {
1550
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY1']);
1551
                    exit;
1552
                }
1553
 
1554
                if ($username != $config_username) {
1555
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY2']);
1556
                    exit;
1557
                }
1558
 
1559
                $dt = \DateTime::createFromFormat('Y-m-d\TH:i:s', $timestamp);
1560
                if (!$dt) {
1561
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY3']);
1562
                    exit;
1563
                }
1564
 
1565
                $t0 = $dt->getTimestamp();
1566
                $t1 = strtotime('-5 minutes');
1567
                $t2 = strtotime('+5 minutes');
1568
 
1569
                if ($t0 < $t1 || $t0 > $t2) {
1570
                    //echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
1571
                    //exit;
1572
                }
1573
 
1574
                if (!password_verify($username . '-' . $config_password . '-' . $rand . '-' . $timestamp, $password)) {
1575
                    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY5']);
1576
                    exit;
1577
                }
1578
 
1579
                if (empty($data)) {
1580
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS1']);
1581
                    exit;
1582
                }
1583
 
1584
                $data = base64_decode($data);
1585
                if (empty($data)) {
1586
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS2']);
1587
                    exit;
1588
                }
1589
 
1590
 
1591
                try {
1592
                    $rsa = Rsa::getInstance();
1593
                    $data = $rsa->decrypt($data,  $config_rsa_d,  $config_rsa_n);
1594
                } catch (\Throwable $e) {
1595
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS3']);
1596
                    exit;
1597
                }
1598
 
1599
                $data = (array) json_decode($data);
1600
                if (empty($data)) {
1601
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS4']);
1602
                    exit;
1603
                }
1604
 
1605
                $email      = isset($data['email']) ? Functions::sanitizeFilterString($data['email']) : '';
1606
                $first_name = isset($data['first_name']) ? Functions::sanitizeFilterString($data['first_name']) : '';
1607
                $last_name  = isset($data['last_name']) ? Functions::sanitizeFilterString($data['last_name']) : '';
1608
 
1609
                if (!filter_var($email, FILTER_VALIDATE_EMAIL) || empty($first_name) || empty($last_name)) {
1610
                    echo json_encode(['success' => false, 'data' => 'ERROR_PARAMETERS5']);
1611
                    exit;
1612
                }
1613
 
1614
                $userMapper = UserMapper::getInstance($this->adapter);
1615
                $user = $userMapper->fetchOneByEmail($email);
1616
                if (!$user) {
1617
 
1618
 
1619
                    $user = new User();
1620
                    $user->network_id = $currentNetwork->id;
1621
                    $user->blocked = User::BLOCKED_NO;
1622
                    $user->email = $email;
1623
                    $user->email_verified = User::EMAIL_VERIFIED_YES;
1624
                    $user->first_name = $first_name;
1625
                    $user->last_name = $last_name;
1626
                    $user->login_attempt = 0;
1627
                    $user->password = '-NO-PASSWORD-';
1628
                    $user->usertype_id = UserType::USER;
1629
                    $user->status = User::STATUS_ACTIVE;
1630
                    $user->show_in_search = User::SHOW_IN_SEARCH_YES;
1631
 
1632
                    if ($userMapper->insert($user)) {
1633
                        echo json_encode(['success' => false, 'data' => $userMapper->getError()]);
1634
                        exit;
1635
                    }
1636
 
1637
 
1638
 
1639
 
1640
                    $filename   = trim(isset($data['avatar_filename']) ? filter_var($data['avatar_filename'], FILTER_SANITIZE_EMAIL) : '');
1641
                    $content    = isset($data['avatar_content']) ? Functions::sanitizeFilterString($data['avatar_content']) : '';
1642
 
1643
                    if ($filename && $content) {
1644
                        $source = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
1645
                        try {
1646
                            file_put_contents($source, base64_decode($content));
1647
                            if (file_exists($source)) {
1648
                                $target_path = $this->config['leaderslinked.fullpath.user'] . $user->uuid;
1649
                                list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1650
 
1651
                                $target_filename    = 'user-' . uniqid() . '.png';
1652
                                $crop_to_dimensions = true;
1653
 
1654
                                if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1655
                                    return new JsonModel([
1656
                                        'success'   => false,
1657
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1658
                                    ]);
1659
                                }
1660
 
1661
                                $user->image = $target_filename;
1662
                                $userMapper->updateImage($user);
1663
                            }
1664
                        } catch (\Throwable $e) {
1665
                        } finally {
1666
                            if (file_exists($source)) {
1667
                                unlink($source);
1668
                            }
1669
                        }
1670
                    }
1671
                }
1672
 
1673
                $auth = new AuthEmailAdapter($this->adapter);
1674
                $auth->setData($email);
1675
 
1676
                $result = $auth->authenticate();
1677
                if ($result->getCode() == AuthResult::SUCCESS) {
1678
                    return $this->redirect()->toRoute('dashboard');
1679
                } else {
1680
                    $message = $result->getMessages()[0];
1681
                    if (!in_array($message, [
1682
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
1683
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
1684
                        'ERROR_ENTERED_PASS_INCORRECT_1'
1685
                    ])) {
1686
                    }
1687
 
1688
                    switch ($message) {
1689
                        case 'ERROR_USER_NOT_FOUND':
1690
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
1691
                            break;
1692
 
1693
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
1694
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
1695
                            break;
1696
 
1697
                        case 'ERROR_USER_IS_BLOCKED':
1698
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1699
                            break;
1700
 
1701
                        case 'ERROR_USER_IS_INACTIVE':
1702
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
1703
                            break;
1704
 
1705
 
1706
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
1707
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
1708
                            break;
1709
 
1710
 
1711
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
1712
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
1713
                            break;
1714
 
1715
 
1716
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
1717
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
1718
                            break;
1719
 
1720
 
1721
                        default:
1722
                            $message = 'ERROR_UNKNOWN';
1723
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
1724
                            break;
1725
                    }
1726
 
1727
 
1728
 
1729
 
1730
                    return new JsonModel([
1731
                        'success'   => false,
1732
                        'data'   => $message
1733
                    ]);
1734
                }
1735
            } else {
1736
                $messages = [];
1737
 
1738
 
1739
 
1740
                $form_messages = (array) $form->getMessages();
1741
                foreach ($form_messages  as $fieldname => $field_messages) {
1742
 
1743
                    $messages[$fieldname] = array_values($field_messages);
1744
                }
1745
 
1746
                return new JsonModel([
1747
                    'success'   => false,
1748
                    'data'   => $messages
1749
                ]);
1750
            }
1751
        } else {
1752
            $data = [
1753
                'success' => false,
1754
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1755
            ];
1756
 
1757
            return new JsonModel($data);
1758
        }
1759
 
1760
        return new JsonModel($data);
1761
    }
1762
 
1763
    public function csrfAction()
1764
    {
1765
        $request = $this->getRequest();
1766
        if ($request->isGet()) {
95 efrain 1767
 
1768
            $jwtToken = null;
1769
            $headers = getallheaders();
1770
 
1771
 
1772
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
1773
 
1774
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
1775
 
1776
 
1777
                if (substr($token, 0, 6 ) == 'Bearer') {
1778
 
1779
                    $token = trim(substr($token, 7));
1780
 
1781
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
1782
                        $key = $this->config['leaderslinked.jwt.key'];
1783
 
1784
 
1785
                        try {
1786
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
1787
 
1788
 
1789
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
1790
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
1791
                            }
1792
 
1793
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
1794
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
1795
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
1796
                            if(!$jwtToken) {
1797
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
1798
                            }
1799
 
1800
                        } catch(\Exception $e) {
1801
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
1802
                        }
1803
                    } else {
1804
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
1805
                    }
1806
                } else {
1807
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
1808
                }
1809
            } else {
1810
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
1811
            }
1812
 
1813
            $jwtToken->csrf = md5(uniqid('CSFR-' . mt_rand(), true));
1814
            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
1815
            $jwtTokenMapper->update($jwtToken);
100 efrain 1816
 
1817
 
106 efrain 1818
           // error_log('token id = ' . $jwtToken->id . ' csrf = ' . $jwtToken->csrf);
1 efrain 1819
 
1820
 
1821
            return new JsonModel([
1822
                'success' => true,
99 efrain 1823
                'data' => $jwtToken->csrf
1 efrain 1824
            ]);
1825
        } else {
1826
            return new JsonModel([
1827
                'success' => false,
1828
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1829
            ]);
1830
        }
1831
    }
1832
 
1833
    public function impersonateAction()
1834
    {
1835
        $request = $this->getRequest();
1836
        if ($request->isGet()) {
1837
            $user_uuid  = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));
1838
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
1839
            $timestamp  = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_NUMBER_INT);
1840
            $password   = Functions::sanitizeFilterString($this->params()->fromQuery('password'));
1841
 
1842
 
1843
            if (!$user_uuid || !$rand || !$timestamp || !$password) {
1844
                throw new \Exception('ERROR_PARAMETERS_ARE_INVALID');
1845
            }
1846
 
1847
 
1848
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1849
            $currentUserPlugin->clearIdentity();
1850
 
1851
 
1852
            $authAdapter = new AuthImpersonateAdapter($this->adapter, $this->config);
1853
            $authAdapter->setDataAdmin($user_uuid, $password, $timestamp, $rand);
1854
 
1855
            $authService = new AuthenticationService();
1856
            $result = $authService->authenticate($authAdapter);
1857
 
1858
 
1859
            if ($result->getCode() == AuthResult::SUCCESS) {
1860
                return $this->redirect()->toRoute('dashboard');
1861
            } else {
1862
                throw new \Exception($result->getMessages()[0]);
1863
            }
1864
        }
1865
 
1866
        return new JsonModel([
1867
            'success' => false,
1868
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1869
        ]);
1870
    }
119 efrain 1871
 
177 efrain 1872
    public function debugAction()
119 efrain 1873
    {
177 efrain 1874
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1875
        $currentNetwork = $currentNetworkPlugin->getNetwork();
119 efrain 1876
 
177 efrain 1877
        $request = $this->getRequest();
119 efrain 1878
 
177 efrain 1879
        if ($request->isPost()) {
1880
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1881
            $currentNetwork = $currentNetworkPlugin->getNetwork();
1882
 
1883
            $jwtToken = null;
1884
            $headers = getallheaders();
1885
 
1886
 
1887
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
1888
 
1889
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
1890
 
1891
 
1892
                if (substr($token, 0, 6 ) == 'Bearer') {
1893
 
1894
                    $token = trim(substr($token, 7));
1895
 
1896
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
1897
                        $key = $this->config['leaderslinked.jwt.key'];
1898
 
1899
 
1900
                        try {
1901
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
1902
 
1903
 
1904
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
1905
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
1906
                            }
1907
 
1908
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
1909
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
1910
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
1911
                            if(!$jwtToken) {
1912
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
1913
                            }
1914
 
1915
                        } catch(\Exception $e) {
1916
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
1917
                        }
1918
                    } else {
1919
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
1920
                    }
1921
                } else {
1922
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
1923
                }
1924
            } else {
1925
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
1926
            }
1927
 
1928
 
211 efrain 1929
            $form = new  SigninDebugForm($this->config);
177 efrain 1930
            $dataPost = $request->getPost()->toArray();
1931
 
1932
 
1933
            $form->setData($dataPost);
1934
 
1935
            if ($form->isValid()) {
1936
 
1937
                $dataPost = (array) $form->getData();
1938
 
1939
                $email      = $dataPost['email'];
1940
                $password   = $dataPost['password'];
1941
 
1942
 
1943
 
1944
 
1945
 
1946
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
1947
                $authAdapter->setData($email, $password, $currentNetwork->id);
1948
                $authService = new AuthenticationService();
1949
 
1950
                $result = $authService->authenticate($authAdapter);
1951
 
1952
                if ($result->getCode() == AuthResult::SUCCESS) {
1953
 
1954
                    $identity = $result->getIdentity();
1955
 
1956
 
1957
                    $userMapper = UserMapper::getInstance($this->adapter);
1958
                    $user = $userMapper->fetchOne($identity['user_id']);
1959
 
1960
 
1961
                    if($token) {
1962
                        $jwtToken->user_id = $user->id;
1963
                        $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
1964
                        $jwtTokenMapper->update($jwtToken);
1965
                    }
1966
 
1967
 
1968
                    $navigator = get_browser(null, true);
1969
                    $device_type    =  isset($navigator['device_type']) ? $navigator['device_type'] : '';
1970
                    $platform       =  isset($navigator['platform']) ? $navigator['platform'] : '';
1971
                    $browser        =  isset($navigator['browser']) ? $navigator['browser'] : '';
1972
 
1973
 
1974
                    $istablet = isset($navigator['istablet']) ?  intval($navigator['istablet']) : 0;
1975
                    $ismobiledevice = isset($navigator['ismobiledevice']) ? intval($navigator['ismobiledevice']) : 0;
1976
                    $version = isset($navigator['version']) ? $navigator['version'] : '';
1977
 
1978
 
1979
                    $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
1980
                    $userBrowser = $userBrowserMapper->fetch($user->id, $device_type, $platform, $browser);
1981
                    if ($userBrowser) {
1982
                        $userBrowserMapper->update($userBrowser);
1983
                    } else {
1984
                        $userBrowser = new UserBrowser();
1985
                        $userBrowser->user_id           = $user->id;
1986
                        $userBrowser->browser           = $browser;
1987
                        $userBrowser->platform          = $platform;
1988
                        $userBrowser->device_type       = $device_type;
1989
                        $userBrowser->is_tablet         = $istablet;
1990
                        $userBrowser->is_mobile_device  = $ismobiledevice;
1991
                        $userBrowser->version           = $version;
1992
 
1993
                        $userBrowserMapper->insert($userBrowser);
1994
                    }
1995
                    //
1996
 
1997
                    $ip = Functions::getUserIP();
1998
                    $ip = $ip == '127.0.0.1' ? '148.240.211.148' : $ip;
1999
 
2000
                    $userIpMapper = UserIpMapper::getInstance($this->adapter);
2001
                    $userIp = $userIpMapper->fetch($user->id, $ip);
2002
                    if (empty($userIp)) {
2003
 
2004
                        if ($this->config['leaderslinked.runmode.sandbox']) {
2005
                            $filename = $this->config['leaderslinked.geoip2.production_database'];
2006
                        } else {
2007
                            $filename = $this->config['leaderslinked.geoip2.sandbox_database'];
2008
                        }
2009
 
2010
                        $reader = new GeoIp2Reader($filename); //GeoIP2-City.mmdb');
2011
                        $record = $reader->city($ip);
2012
                        if ($record) {
2013
                            $userIp = new UserIp();
2014
                            $userIp->user_id = $user->id;
2015
                            $userIp->city = !empty($record->city->name) ? Functions::utf8_decode($record->city->name) : '';
2016
                            $userIp->state_code = !empty($record->mostSpecificSubdivision->isoCode) ? Functions::utf8_decode($record->mostSpecificSubdivision->isoCode) : '';
2017
                            $userIp->state_name = !empty($record->mostSpecificSubdivision->name) ? Functions::utf8_decode($record->mostSpecificSubdivision->name) : '';
2018
                            $userIp->country_code = !empty($record->country->isoCode) ? Functions::utf8_decode($record->country->isoCode) : '';
2019
                            $userIp->country_name = !empty($record->country->name) ? Functions::utf8_decode($record->country->name) : '';
2020
                            $userIp->ip = $ip;
2021
                            $userIp->latitude = !empty($record->location->latitude) ? $record->location->latitude : 0;
2022
                            $userIp->longitude = !empty($record->location->longitude) ? $record->location->longitude : 0;
2023
                            $userIp->postal_code = !empty($record->postal->code) ? $record->postal->code : '';
2024
 
2025
                            $userIpMapper->insert($userIp);
2026
                        }
2027
                    } else {
2028
                        $userIpMapper->update($userIp);
2029
                    }
2030
 
2031
                    /*
2032
                     if ($remember) {
2033
                     $expired = time() + 365 * 24 * 60 * 60;
2034
 
2035
                     $cookieEmail = new SetCookie('email', $email, $expired);
2036
                     } else {
2037
                     $expired = time() - 7200;
2038
                     $cookieEmail = new SetCookie('email', '', $expired);
2039
                     }
2040
 
2041
 
2042
                     $response = $this->getResponse();
2043
                     $response->getHeaders()->addHeader($cookieEmail);
2044
                     */
2045
 
2046
 
2047
 
2048
 
2049
 
2050
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
2051
 
2052
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
2053
 
2054
                    if ($user_share_invitation) {
2055
                        $userRedirect = $userMapper->fetchOneByUuid($user_share_invitation);
2056
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
2057
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
2058
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
2059
 
2060
                            if ($connection) {
2061
 
2062
                                if ($connection->status != Connection::STATUS_ACCEPTED) {
2063
                                    $connectionMapper->approve($connection);
2064
                                }
2065
                            } else {
2066
                                $connection = new Connection();
2067
                                $connection->request_from = $user->id;
2068
                                $connection->request_to = $userRedirect->id;
2069
                                $connection->status = Connection::STATUS_ACCEPTED;
2070
 
2071
                                $connectionMapper->insert($connection);
2072
                            }
2073
                        }
2074
                    }
2075
 
2076
 
2077
 
2078
                    $data = [
2079
                        'success'   => true,
2080
                        'data'      => $this->url()->fromRoute('dashboard'),
2081
                    ];
2082
 
2083
                    $this->cache->removeItem('user_share_invitation');
2084
                } else {
2085
 
2086
                    $message = $result->getMessages()[0];
2087
                    if (!in_array($message, [
2088
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
2089
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
2090
                        'ERROR_ENTERED_PASS_INCORRECT_1', 'ERROR_USER_REQUEST_ACCESS_IS_PENDING', 'ERROR_USER_REQUEST_ACCESS_IS_REJECTED'
2091
 
2092
 
2093
                    ])) {
2094
                    }
2095
 
2096
                    switch ($message) {
2097
                        case 'ERROR_USER_NOT_FOUND':
2098
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
2099
                            break;
2100
 
2101
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
2102
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
2103
                            break;
2104
 
2105
                        case 'ERROR_USER_IS_BLOCKED':
2106
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
2107
                            break;
2108
 
2109
                        case 'ERROR_USER_IS_INACTIVE':
2110
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
2111
                            break;
2112
 
2113
 
2114
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
2115
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
2116
                            break;
2117
 
2118
 
2119
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
2120
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
2121
                            break;
2122
 
2123
 
2124
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
2125
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
2126
                            break;
2127
 
2128
 
2129
                        case 'ERROR_USER_REQUEST_ACCESS_IS_PENDING':
2130
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Falta verificar que pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
2131
                            break;
2132
 
2133
                        case  'ERROR_USER_REQUEST_ACCESS_IS_REJECTED':
2134
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Rechazado por no pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
2135
                            break;
2136
 
2137
 
2138
                        default:
2139
                            $message = 'ERROR_UNKNOWN';
2140
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
2141
                            break;
2142
                    }
2143
 
2144
 
2145
 
2146
 
2147
                    $data = [
2148
                        'success'   => false,
2149
                        'data'   => $message
2150
                    ];
2151
                }
2152
 
2153
                return new JsonModel($data);
2154
            } else {
2155
                $messages = [];
2156
 
2157
 
2158
 
2159
                $form_messages = (array) $form->getMessages();
2160
                foreach ($form_messages  as $fieldname => $field_messages) {
2161
 
2162
                    $messages[$fieldname] = array_values($field_messages);
2163
                }
2164
 
2165
                return new JsonModel([
2166
                    'success'   => false,
2167
                    'data'   => $messages
2168
                ]);
2169
            }
2170
        } else if ($request->isGet()) {
2171
 
2172
            $aes = '';
2173
            $jwtToken = null;
2174
            $headers = getallheaders();
2175
 
2176
 
2177
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
2178
 
2179
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
2180
 
2181
 
2182
                if (substr($token, 0, 6 ) == 'Bearer') {
2183
 
2184
                    $token = trim(substr($token, 7));
2185
 
2186
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
2187
                        $key = $this->config['leaderslinked.jwt.key'];
2188
 
2189
 
2190
                        try {
2191
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
2192
 
2193
 
2194
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
2195
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
2196
                            }
2197
 
2198
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
2199
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2200
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
2201
                        } catch(\Exception $e) {
2202
                            //Token invalido
2203
                        }
2204
                    }
2205
                }
2206
            }
2207
 
2208
            if(!$jwtToken) {
2209
 
2210
                $aes = Functions::generatePassword(16);
2211
 
2212
                $jwtToken = new JwtToken();
2213
                $jwtToken->aes = $aes;
2214
 
2215
                $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
2216
                if($jwtTokenMapper->insert($jwtToken)) {
2217
                    $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
2218
                }
2219
 
2220
                $token = '';
2221
 
2222
                if(!empty($this->config['leaderslinked.jwt.key'])) {
2223
                    $issuedAt   = new \DateTimeImmutable();
2224
                    $expire     = $issuedAt->modify('+24 hours')->getTimestamp();
2225
                    $serverName = $_SERVER['HTTP_HOST'];
2226
                    $payload = [
2227
                        'iat'  => $issuedAt->getTimestamp(),
2228
                        'iss'  => $serverName,
2229
                        'nbf'  => $issuedAt->getTimestamp(),
2230
                        'exp'  => $expire,
2231
                        'uuid' => $jwtToken->uuid,
2232
                    ];
2233
 
2234
 
2235
                    $key = $this->config['leaderslinked.jwt.key'];
2236
                    $token = JWT::encode($payload, $key, 'HS256');
2237
                }
2238
            }
2239
 
2240
 
2241
 
2242
 
2243
 
2244
 
2245
 
2246
            if ($this->config['leaderslinked.runmode.sandbox']) {
2247
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
2248
            } else {
2249
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
2250
            }
2251
 
2252
 
2253
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
2254
 
2255
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
2256
            if ($sandbox) {
2257
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
2258
            } else {
2259
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
2260
            }
2261
 
2262
 
2263
 
2264
 
2265
            $logo_url = $this->url()->fromRoute('storage-network', ['type' => 'logo'],['force_canonical' => true]);
2266
            $logo_url = str_replace($currentNetwork->main_hostname, $currentNetwork->service_hostname, $logo_url);
2267
            if($currentNetwork->alternative_hostname) {
2268
                $logo_url = str_replace($currentNetwork->alternative_hostname, $currentNetwork->service_hostname, $logo_url);
2269
 
2270
            }
2271
 
2272
 
2273
            $navbar_url = $this->url()->fromRoute('storage-network', ['type' => 'navbar'],['force_canonical' => true]);
2274
            $navbar_url = str_replace($currentNetwork->main_hostname, $currentNetwork->service_hostname, $navbar_url);
2275
            if($currentNetwork->alternative_hostname) {
2276
                $navbar_url = str_replace($currentNetwork->alternative_hostname, $currentNetwork->service_hostname, $navbar_url);
2277
 
2278
            }
2279
 
2280
 
2281
            $favico_url= $this->url()->fromRoute('storage-network', ['type' => 'favico'],['force_canonical' => true]);
2282
            $favico_url = str_replace($currentNetwork->main_hostname, $currentNetwork->service_hostname, $favico_url);
2283
            if($currentNetwork->alternative_hostname) {
2284
                $favico_url = str_replace($currentNetwork->alternative_hostname, $currentNetwork->service_hostname, $favico_url);
2285
 
2286
            }
2287
 
2288
 
2289
 
2290
            $data = [
2291
                'google_map_key'                => $google_map_key,
2292
                'email'                         => '',
2293
                'remember'                      => false,
2294
                'site_key'                      => $site_key,
2295
                'theme_id'                      => $currentNetwork->theme_id,
2296
                'aes'                           => $aes,
2297
                'jwt'                           => $token,
2298
                'defaultNetwork'                => $currentNetwork->default,
2299
                'access_usign_social_networks'  => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
2300
                'logo_url'                      => $logo_url,
2301
                'navbar_url'                    => $navbar_url,
2302
                'favico_url'                    => $favico_url,
2303
                'intro'                         => $currentNetwork->intro ? $currentNetwork->intro : '',
2304
                'is_logged_in'                  => $jwtToken->user_id ? true : false,
2305
 
2306
            ];
2307
 
2308
            $data = [
2309
                'success' => true,
2310
                'data' =>  $data
2311
            ];
2312
 
119 efrain 2313
        } else {
177 efrain 2314
            $data = [
2315
                'success' => false,
2316
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2317
            ];
2318
 
2319
            return new JsonModel($data);
119 efrain 2320
        }
2321
 
177 efrain 2322
        return new JsonModel($data);
119 efrain 2323
 
177 efrain 2324
 
119 efrain 2325
    }
1 efrain 2326
}