Proyectos de Subversion LeadersLinked - Services

Rev

Rev 334 | Rev 341 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 334 Rev 340
Línea 2167... Línea 2167...
2167
            'success' => false,
2167
            'success' => false,
2168
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2168
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2169
        ]);
2169
        ]);
2170
    }
2170
    }
Línea -... Línea 2171...
-
 
2171
    
-
 
2172
    
-
 
2173
    
-
 
2174
    public function debugAction()
-
 
2175
    {
-
 
2176
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
-
 
2177
        $currentNetwork = $currentNetworkPlugin->getNetwork();
-
 
2178
        
-
 
2179
        $request = $this->getRequest();
-
 
2180
        
-
 
2181
        if ($request->isPost()) {
-
 
2182
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
-
 
2183
            $currentNetwork = $currentNetworkPlugin->getNetwork();
-
 
2184
            
-
 
2185
            $jwtToken = null;
-
 
2186
            $headers = getallheaders();
-
 
2187
            
-
 
2188
            
-
 
2189
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
-
 
2190
                
-
 
2191
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
-
 
2192
                
-
 
2193
                
-
 
2194
                if (substr($token, 0, 6 ) == 'Bearer') {
-
 
2195
                    
-
 
2196
                    $token = trim(substr($token, 7));
-
 
2197
                    
-
 
2198
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
-
 
2199
                        $key = $this->config['leaderslinked.jwt.key'];
-
 
2200
                        
-
 
2201
                        
-
 
2202
                        try {
-
 
2203
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
-
 
2204
                            
-
 
2205
                            
-
 
2206
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
-
 
2207
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
-
 
2208
                            }
-
 
2209
                            
-
 
2210
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
-
 
2211
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
-
 
2212
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
-
 
2213
                            if(!$jwtToken) {
-
 
2214
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Expired',  'fatal'  => true]);
-
 
2215
                            }
-
 
2216
                            
-
 
2217
                        } catch(\Exception $e) {
-
 
2218
                            return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong key',  'fatal'  => true]);
-
 
2219
                        }
-
 
2220
                    } else {
-
 
2221
                        return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - SecreteKey required',  'fatal'  => true]);
-
 
2222
                    }
-
 
2223
                } else {
-
 
2224
                    return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Bearer required',  'fatal'  => true]);
-
 
2225
                }
-
 
2226
            } else {
-
 
2227
                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Required',  'fatal'  => true]);
-
 
2228
            }
-
 
2229
            
-
 
2230
            
-
 
2231
            
-
 
2232
            $form = new  SigninDebugForm($this->config);
-
 
2233
            $dataPost = $request->getPost()->toArray();
-
 
2234
            
-
 
2235
            if (empty($_SESSION['aes'])) {
-
 
2236
                return new JsonModel([
-
 
2237
                    'success'   => false,
-
 
2238
                    'data'      => 'ERROR_WEBSERVICE_ENCRYPTION_KEYS_NOT_FOUND'
-
 
2239
                ]);
-
 
2240
            }
-
 
2241
            
-
 
2242
            error_log(print_r($dataPost, true));
-
 
2243
            
-
 
2244
            $aes = $_SESSION['aes'];
-
 
2245
            error_log('aes : ' . $aes);
-
 
2246
            
-
 
2247
            
-
 
2248
            unset( $_SESSION['aes'] );
-
 
2249
            
-
 
2250
            if (!empty($dataPost['email'])) {
-
 
2251
                $dataPost['email'] = CryptoJsAes::decrypt($dataPost['email'], $aes);
-
 
2252
            }
-
 
2253
            
-
 
2254
            
-
 
2255
            if (!empty($dataPost['password'])) {
-
 
2256
                $dataPost['password'] = CryptoJsAes::decrypt($dataPost['password'], $aes);
-
 
2257
            }
-
 
2258
            
-
 
2259
            error_log(print_r($dataPost, true));
-
 
2260
            
-
 
2261
            $form->setData($dataPost);
-
 
2262
            
-
 
2263
            if ($form->isValid()) {
-
 
2264
                
-
 
2265
                $dataPost = (array) $form->getData();
-
 
2266
                
-
 
2267
                
-
 
2268
                $email      = $dataPost['email'];
-
 
2269
                $password   = $dataPost['password'];
-
 
2270
                
-
 
2271
                
-
 
2272
                
-
 
2273
                
-
 
2274
                
-
 
2275
                $authAdapter = new AuthAdapter($this->adapter, $this->logger);
-
 
2276
                $authAdapter->setData($email, $password, $currentNetwork->id);
-
 
2277
                $authService = new AuthenticationService();
-
 
2278
                
-
 
2279
                $result = $authService->authenticate($authAdapter);
-
 
2280
                
-
 
2281
                if ($result->getCode() == AuthResult::SUCCESS) {
-
 
2282
                    
-
 
2283
                    $identity = $result->getIdentity();
-
 
2284
                    
-
 
2285
                    
-
 
2286
                    $userMapper = UserMapper::getInstance($this->adapter);
-
 
2287
                    $user = $userMapper->fetchOne($identity['user_id']);
-
 
2288
                    
-
 
2289
                    
-
 
2290
                    if($token) {
-
 
2291
                        $jwtToken->user_id = $user->id;
-
 
2292
                        $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
-
 
2293
                        $jwtTokenMapper->update($jwtToken);
-
 
2294
                    }
-
 
2295
                    
-
 
2296
                    
-
 
2297
                    $navigator = get_browser(null, true);
-
 
2298
                    $device_type    =  isset($navigator['device_type']) ? $navigator['device_type'] : '';
-
 
2299
                    $platform       =  isset($navigator['platform']) ? $navigator['platform'] : '';
-
 
2300
                    $browser        =  isset($navigator['browser']) ? $navigator['browser'] : '';
-
 
2301
                    
-
 
2302
                    
-
 
2303
                    $istablet = isset($navigator['istablet']) ?  intval($navigator['istablet']) : 0;
-
 
2304
                    $ismobiledevice = isset($navigator['ismobiledevice']) ? intval($navigator['ismobiledevice']) : 0;
-
 
2305
                    $version = isset($navigator['version']) ? $navigator['version'] : '';
-
 
2306
                    
-
 
2307
                    
-
 
2308
                    $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
-
 
2309
                    $userBrowser = $userBrowserMapper->fetch($user->id, $device_type, $platform, $browser);
-
 
2310
                    if ($userBrowser) {
-
 
2311
                        $userBrowserMapper->update($userBrowser);
-
 
2312
                    } else {
-
 
2313
                        $userBrowser = new UserBrowser();
-
 
2314
                        $userBrowser->user_id           = $user->id;
-
 
2315
                        $userBrowser->browser           = $browser;
-
 
2316
                        $userBrowser->platform          = $platform;
-
 
2317
                        $userBrowser->device_type       = $device_type;
-
 
2318
                        $userBrowser->is_tablet         = $istablet;
-
 
2319
                        $userBrowser->is_mobile_device  = $ismobiledevice;
-
 
2320
                        $userBrowser->version           = $version;
-
 
2321
                        
-
 
2322
                        $userBrowserMapper->insert($userBrowser);
-
 
2323
                    }
-
 
2324
                    //
-
 
2325
                    
-
 
2326
                    $ip = Functions::getUserIP();
-
 
2327
                    $ip = $ip == '127.0.0.1' ? '148.240.211.148' : $ip;
-
 
2328
                    
-
 
2329
                    $userIpMapper = UserIpMapper::getInstance($this->adapter);
-
 
2330
                    $userIp = $userIpMapper->fetch($user->id, $ip);
-
 
2331
                    if (empty($userIp)) {
-
 
2332
                        
-
 
2333
                        if ($this->config['leaderslinked.runmode.sandbox']) {
-
 
2334
                            $filename = $this->config['leaderslinked.geoip2.production_database'];
-
 
2335
                        } else {
-
 
2336
                            $filename = $this->config['leaderslinked.geoip2.sandbox_database'];
-
 
2337
                        }
-
 
2338
                        
-
 
2339
                        $reader = new GeoIp2Reader($filename); //GeoIP2-City.mmdb');
-
 
2340
                        $record = $reader->city($ip);
-
 
2341
                        if ($record) {
-
 
2342
                            $userIp = new UserIp();
-
 
2343
                            $userIp->user_id = $user->id;
-
 
2344
                            $userIp->city = !empty($record->city->name) ? Functions::utf8_decode($record->city->name) : '';
-
 
2345
                            $userIp->state_code = !empty($record->mostSpecificSubdivision->isoCode) ? Functions::utf8_decode($record->mostSpecificSubdivision->isoCode) : '';
-
 
2346
                            $userIp->state_name = !empty($record->mostSpecificSubdivision->name) ? Functions::utf8_decode($record->mostSpecificSubdivision->name) : '';
-
 
2347
                            $userIp->country_code = !empty($record->country->isoCode) ? Functions::utf8_decode($record->country->isoCode) : '';
-
 
2348
                            $userIp->country_name = !empty($record->country->name) ? Functions::utf8_decode($record->country->name) : '';
-
 
2349
                            $userIp->ip = $ip;
-
 
2350
                            $userIp->latitude = !empty($record->location->latitude) ? $record->location->latitude : 0;
-
 
2351
                            $userIp->longitude = !empty($record->location->longitude) ? $record->location->longitude : 0;
-
 
2352
                            $userIp->postal_code = !empty($record->postal->code) ? $record->postal->code : '';
-
 
2353
                            
-
 
2354
                            $userIpMapper->insert($userIp);
-
 
2355
                        }
-
 
2356
                    } else {
-
 
2357
                        $userIpMapper->update($userIp);
-
 
2358
                    }
-
 
2359
                    
-
 
2360
                    /*
-
 
2361
                     if ($remember) {
-
 
2362
                     $expired = time() + 365 * 24 * 60 * 60;
-
 
2363
                     
-
 
2364
                     $cookieEmail = new SetCookie('email', $email, $expired);
-
 
2365
                     } else {
-
 
2366
                     $expired = time() - 7200;
-
 
2367
                     $cookieEmail = new SetCookie('email', '', $expired);
-
 
2368
                     }
-
 
2369
                     
-
 
2370
                     
-
 
2371
                     $response = $this->getResponse();
-
 
2372
                     $response->getHeaders()->addHeader($cookieEmail);
-
 
2373
                     */
-
 
2374
                    
-
 
2375
                    
-
 
2376
                    
-
 
2377
                    
-
 
2378
                    
-
 
2379
                    $this->logger->info('Ingreso a LeadersLiked', ['user_id' => $user->id, 'ip' => Functions::getUserIP()]);
-
 
2380
                    
-
 
2381
                    $user_share_invitation = $this->cache->getItem('user_share_invitation');
-
 
2382
                    
-
 
2383
                    $url =  $this->url()->fromRoute('dashboard');
-
 
2384
                    
-
 
2385
                    if ($user_share_invitation && is_array($user_share_invitation)) {
-
 
2386
                        
-
 
2387
                        $content_uuid = $user_share_invitation['code'];
-
 
2388
                        $content_type = $user_share_invitation['type'];
-
 
2389
                        $content_user = $user_share_invitation['user'];
-
 
2390
                        
-
 
2391
                        
-
 
2392
                        
-
 
2393
                        $userRedirect = $userMapper->fetchOneByUuid($content_user);
-
 
2394
                        if ($userRedirect && $userRedirect->status == User::STATUS_ACTIVE && $user->id != $userRedirect->id) {
-
 
2395
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
-
 
2396
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user->id, $userRedirect->id);
-
 
2397
                            
-
 
2398
                            if ($connection) {
-
 
2399
                                
-
 
2400
                                if ($connection->status != Connection::STATUS_ACCEPTED) {
-
 
2401
                                    $connectionMapper->approve($connection);
-
 
2402
                                }
-
 
2403
                            } else {
-
 
2404
                                $connection = new Connection();
-
 
2405
                                $connection->request_from = $user->id;
-
 
2406
                                $connection->request_to = $userRedirect->id;
-
 
2407
                                $connection->status = Connection::STATUS_ACCEPTED;
-
 
2408
                                
-
 
2409
                                $connectionMapper->insert($connection);
-
 
2410
                            }
-
 
2411
                        }
-
 
2412
                        
-
 
2413
                        if($content_type == 'feed') {
-
 
2414
                            $url = $this->url()->fromRoute('dashboard', ['feed' => $content_uuid ]);
-
 
2415
                            
-
 
2416
                        }
-
 
2417
                        else if($content_type == 'post') {
-
 
2418
                            $url = $this->url()->fromRoute('post', ['id' => $content_uuid ]);
-
 
2419
                        }
-
 
2420
                        else {
-
 
2421
                            $url = $this->url()->fromRoute('dashboard');
-
 
2422
                        }
-
 
2423
                        
-
 
2424
                    }
-
 
2425
                    
-
 
2426
                    
-
 
2427
                    $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
-
 
2428
                    
-
 
2429
                    $networkMapper = NetworkMapper::getInstance($this->adapter);
-
 
2430
                    $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
-
 
2431
                    
-
 
2432
                    if(!$network) {
-
 
2433
                        $network = $networkMapper->fetchOneByDefault();
-
 
2434
                    }
-
 
2435
                    
-
 
2436
                    $hostname = trim($network->main_hostname);
-
 
2437
                    $url = 'https://' . $hostname . $url;
-
 
2438
                    
-
 
2439
                    
-
 
2440
                    $data = [
-
 
2441
                        'redirect'  => $url,
-
 
2442
                        'uuid'      => $user->uuid,
-
 
2443
                    ];
-
 
2444
                    
-
 
2445
                    
-
 
2446
                    
-
 
2447
                    
-
 
2448
                    if($currentNetwork->xmpp_active) {
-
 
2449
                        $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
-
 
2450
                        $externalCredentials->getUserBy($user->id);
-
 
2451
                        
-
 
2452
                        
-
 
2453
                        $data['xmpp_domain'] = $currentNetwork->xmpp_domain;
-
 
2454
                        $data['xmpp_hostname'] = $currentNetwork->xmpp_hostname;
-
 
2455
                        $data['xmpp_port'] = $currentNetwork->xmpp_port;
-
 
2456
                        $data['xmpp_username'] = $externalCredentials->getUsernameXmpp();
-
 
2457
                        $data['xmpp_pasword'] = $externalCredentials->getPasswordXmpp();
-
 
2458
                        $data['inmail_username'] = $externalCredentials->getUsernameInmail();
-
 
2459
                        $data['inmail_pasword'] = $externalCredentials->getPasswordInmail();
-
 
2460
                        
-
 
2461
                    }
-
 
2462
                    
-
 
2463
                    $data = [
-
 
2464
                        'success'   => true,
-
 
2465
                        'data'      => $data
-
 
2466
                    ];
-
 
2467
                    
-
 
2468
                    
-
 
2469
                    $this->cache->removeItem('user_share_invitation');
-
 
2470
                } else {
-
 
2471
                    
-
 
2472
                    $message = $result->getMessages()[0];
-
 
2473
                    if (!in_array($message, [
-
 
2474
                        'ERROR_USER_NOT_FOUND', 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED', 'ERROR_USER_IS_BLOCKED',
-
 
2475
                        'ERROR_USER_IS_INACTIVE', 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED', 'ERROR_ENTERED_PASS_INCORRECT_2',
-
 
2476
                        'ERROR_ENTERED_PASS_INCORRECT_1', 'ERROR_USER_REQUEST_ACCESS_IS_PENDING', 'ERROR_USER_REQUEST_ACCESS_IS_REJECTED'
-
 
2477
                        
-
 
2478
                        
-
 
2479
                    ])) {
-
 
2480
                    }
-
 
2481
                    
-
 
2482
                    switch ($message) {
-
 
2483
                        case 'ERROR_USER_NOT_FOUND':
-
 
2484
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no existe', ['ip' => Functions::getUserIP()]);
-
 
2485
                            break;
-
 
2486
                            
-
 
2487
                        case 'ERROR_USER_EMAIL_HASNT_BEEN_VARIFIED':
-
 
2488
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Email no verificado', ['ip' => Functions::getUserIP()]);
-
 
2489
                            break;
-
 
2490
                            
-
 
2491
                        case 'ERROR_USER_IS_BLOCKED':
-
 
2492
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario bloqueado', ['ip' => Functions::getUserIP()]);
-
 
2493
                            break;
-
 
2494
                            
-
 
2495
                        case 'ERROR_USER_IS_INACTIVE':
-
 
2496
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Usuario inactivo', ['ip' => Functions::getUserIP()]);
-
 
2497
                            break;
-
 
2498
                            
-
 
2499
                            
-
 
2500
                        case 'ERROR_ENTERED_PASS_INCORRECT_USER_IS_BLOCKED':
-
 
2501
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 3er Intento Usuario bloqueado', ['ip' => Functions::getUserIP()]);
-
 
2502
                            break;
-
 
2503
                            
-
 
2504
                            
-
 
2505
                        case 'ERROR_ENTERED_PASS_INCORRECT_2':
-
 
2506
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 1er Intento', ['ip' => Functions::getUserIP()]);
-
 
2507
                            break;
-
 
2508
                            
-
 
2509
                            
-
 
2510
                        case 'ERROR_ENTERED_PASS_INCORRECT_1':
-
 
2511
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - 2do Intento', ['ip' => Functions::getUserIP()]);
-
 
2512
                            break;
-
 
2513
                            
-
 
2514
                            
-
 
2515
                        case 'ERROR_USER_REQUEST_ACCESS_IS_PENDING':
-
 
2516
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Falta verificar que pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
-
 
2517
                            break;
-
 
2518
                            
-
 
2519
                        case  'ERROR_USER_REQUEST_ACCESS_IS_REJECTED':
-
 
2520
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Rechazado por no pertence a la Red Privada', ['ip' => Functions::getUserIP()]);
-
 
2521
                            break;
-
 
2522
                            
-
 
2523
                            
-
 
2524
                        default:
-
 
2525
                            $message = 'ERROR_UNKNOWN';
-
 
2526
                            $this->logger->err('Error de ingreso a LeadersLinked de ' . $email . ' - Error desconocido', ['ip' => Functions::getUserIP()]);
-
 
2527
                            break;
-
 
2528
                    }
-
 
2529
                    
-
 
2530
                    
-
 
2531
                    
-
 
2532
                    
-
 
2533
                    $data = [
-
 
2534
                        'success'   => false,
-
 
2535
                        'data'   => $message
-
 
2536
                    ];
-
 
2537
                }
-
 
2538
                
-
 
2539
                return new JsonModel($data);
-
 
2540
            } else {
-
 
2541
                $messages = [];
-
 
2542
                
-
 
2543
                
-
 
2544
                
-
 
2545
                $form_messages = (array) $form->getMessages();
-
 
2546
                foreach ($form_messages  as $fieldname => $field_messages) {
-
 
2547
                    
-
 
2548
                    $messages[$fieldname] = array_values($field_messages);
-
 
2549
                }
-
 
2550
                
-
 
2551
                return new JsonModel([
-
 
2552
                    'success'   => false,
-
 
2553
                    'data'   => $messages
-
 
2554
                ]);
-
 
2555
            }
-
 
2556
        } else if ($request->isGet()) {
-
 
2557
            
-
 
2558
            $aes = '';
-
 
2559
            $jwtToken = null;
-
 
2560
            $headers = getallheaders();
-
 
2561
            
-
 
2562
            
-
 
2563
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
-
 
2564
                
-
 
2565
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
-
 
2566
                
-
 
2567
                
-
 
2568
                if (substr($token, 0, 6 ) == 'Bearer') {
-
 
2569
                    
-
 
2570
                    $token = trim(substr($token, 7));
-
 
2571
                    
-
 
2572
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
-
 
2573
                        $key = $this->config['leaderslinked.jwt.key'];
-
 
2574
                        
-
 
2575
                        
-
 
2576
                        try {
-
 
2577
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
-
 
2578
                            
-
 
2579
                            
-
 
2580
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
-
 
2581
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
-
 
2582
                            }
-
 
2583
                            
-
 
2584
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
-
 
2585
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
-
 
2586
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
-
 
2587
                        } catch(\Exception $e) {
-
 
2588
                            //Token invalido
-
 
2589
                        }
-
 
2590
                    }
-
 
2591
                }
-
 
2592
            }
-
 
2593
            
-
 
2594
            if(!$jwtToken) {
-
 
2595
                
-
 
2596
                $aes = Functions::generatePassword(16);
-
 
2597
                
-
 
2598
                $jwtToken = new JwtToken();
-
 
2599
                $jwtToken->aes = $aes;
-
 
2600
                
-
 
2601
                $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
-
 
2602
                if($jwtTokenMapper->insert($jwtToken)) {
-
 
2603
                    $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
-
 
2604
                }
-
 
2605
                
-
 
2606
                $token = '';
-
 
2607
                
-
 
2608
                if(!empty($this->config['leaderslinked.jwt.key'])) {
-
 
2609
                    $issuedAt   = new \DateTimeImmutable();
-
 
2610
                    $expire     = $issuedAt->modify('+365 days')->getTimestamp();
-
 
2611
                    $serverName = $_SERVER['HTTP_HOST'];
-
 
2612
                    $payload = [
-
 
2613
                        'iat'  => $issuedAt->getTimestamp(),
-
 
2614
                        'iss'  => $serverName,
-
 
2615
                        'nbf'  => $issuedAt->getTimestamp(),
-
 
2616
                        'exp'  => $expire,
-
 
2617
                        'uuid' => $jwtToken->uuid,
-
 
2618
                    ];
-
 
2619
                    
-
 
2620
                    
-
 
2621
                    $key = $this->config['leaderslinked.jwt.key'];
-
 
2622
                    $token = JWT::encode($payload, $key, 'HS256');
-
 
2623
                }
-
 
2624
            }
-
 
2625
            
-
 
2626
            
-
 
2627
            
-
 
2628
            
-
 
2629
            
-
 
2630
            
-
 
2631
            
-
 
2632
            if ($this->config['leaderslinked.runmode.sandbox']) {
-
 
2633
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
-
 
2634
            } else {
-
 
2635
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
-
 
2636
            }
-
 
2637
            
-
 
2638
            
-
 
2639
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
-
 
2640
            
-
 
2641
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
-
 
2642
            if ($sandbox) {
-
 
2643
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
-
 
2644
            } else {
-
 
2645
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
-
 
2646
            }
-
 
2647
            
-
 
2648
            
-
 
2649
            $parts = explode('.', $currentNetwork->main_hostname);
-
 
2650
            if($parts[1] === 'com') {
-
 
2651
                $replace_main = false;
-
 
2652
            } else {
-
 
2653
                $replace_main = true;
-
 
2654
            }
-
 
2655
            
-
 
2656
            
-
 
2657
            $storage = Storage::getInstance($this->config, $this->adapter);
-
 
2658
            $path = $storage->getPathNetwork();
-
 
2659
            
-
 
2660
            if($currentNetwork->logo) {
-
 
2661
                $logo_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->logo);
-
 
2662
            } else {
-
 
2663
                $logo_url = '';
-
 
2664
            }
-
 
2665
            
-
 
2666
            if($currentNetwork->navbar) {
-
 
2667
                $navbar_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->navbar);
-
 
2668
            } else {
-
 
2669
                $navbar_url = '';
-
 
2670
            }
-
 
2671
            
-
 
2672
            if($currentNetwork->favico) {
-
 
2673
                $favico_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->favico);
-
 
2674
            } else {
-
 
2675
                $favico_url = '';
-
 
2676
            }
-
 
2677
            
-
 
2678
            
-
 
2679
            
-
 
2680
            
-
 
2681
            $data = [
-
 
2682
                'google_map_key'                => $google_map_key,
-
 
2683
                'email'                         => '',
-
 
2684
                'remember'                      => false,
-
 
2685
                'site_key'                      => $site_key,
-
 
2686
                'theme_id'                      => $currentNetwork->theme_id,
-
 
2687
                'aes'                           => $aes,
-
 
2688
                'jwt'                           => $token,
-
 
2689
                'defaultNetwork'                => $currentNetwork->default,
-
 
2690
                'access_usign_social_networks'  => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
-
 
2691
                'logo_url'                      => $logo_url,
-
 
2692
                'navbar_url'                    => $navbar_url,
-
 
2693
                'favico_url'                    => $favico_url,
-
 
2694
                'intro'                         => $currentNetwork->intro ? $currentNetwork->intro : '',
-
 
2695
                'is_logged_in'                  => $jwtToken->user_id ? true : false,
-
 
2696
                
-
 
2697
            ];
-
 
2698
            
-
 
2699
            if($currentNetwork->default == Network::DEFAULT_YES) {
-
 
2700
                
-
 
2701
                
-
 
2702
                
-
 
2703
                $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
2704
                if ($currentUserPlugin->hasIdentity()) {
-
 
2705
                    
-
 
2706
                    
-
 
2707
                    $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
-
 
2708
                    $externalCredentials->getUserBy($currentUserPlugin->getUserId());
-
 
2709
                    
-
 
2710
                    
-
 
2711
                    if($currentNetwork->xmpp_active) {
-
 
2712
                        $data['xmpp_domain']      = $currentNetwork->xmpp_domain;
-
 
2713
                        $data['xmpp_hostname']    = $currentNetwork->xmpp_hostname;
-
 
2714
                        $data['xmpp_port']        = $currentNetwork->xmpp_port;
-
 
2715
                        $data['xmpp_username']    = $externalCredentials->getUsernameXmpp();
-
 
2716
                        $data['xmpp_password']    = $externalCredentials->getPasswordXmpp();
-
 
2717
                        $data['inmail_username']    = $externalCredentials->getUsernameInmail();
-
 
2718
                        $data['inmail_password']    = $externalCredentials->getPasswordInmail();
-
 
2719
                    }
-
 
2720
                }
-
 
2721
            }
-
 
2722
            
-
 
2723
            $data = [
-
 
2724
                'success' => true,
-
 
2725
                'data' =>  $data
-
 
2726
            ];
-
 
2727
            
-
 
2728
        } else {
-
 
2729
            $data = [
-
 
2730
                'success' => false,
-
 
2731
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
2732
            ];
-
 
2733
            
-
 
2734
            return new JsonModel($data);
-
 
2735
        }
-
 
2736
        
-
 
2737
        return new JsonModel($data);
Línea 2171... Línea 2738...
2171
    
2738
    }