Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 3357 Rev 3364
Línea 211... Línea 211...
211
    }
211
    }
Línea 212... Línea 212...
212
 
212
 
213
   
213
   
-
 
214
    public function postAction()
-
 
215
    {
-
 
216
        $request = $this->getRequest();
-
 
217
        if ($request->isGet()) {
-
 
218
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
219
            $currentUser = $currentUserPlugin->getUser();
214
    public function postAction()
220
            
215
    {
221
            
216
        $id = $this->params()->fromRoute('id');
222
            $id = $this->params()->fromRoute('id');
217
 
223
    
218
        $postMapper = PostMapper::getInstance($this->adapter);
224
            $postMapper = PostMapper::getInstance($this->adapter);
219
        $post = $postMapper->fetchOneByUuid($id);
225
            $post = $postMapper->fetchOneByUuid($id);
220
 
226
    
221
        if (!$post || $post->status != Post::STATUS_ACTIVE) {
227
            if (!$post || $post->status != Post::STATUS_ACTIVE) {
222
            $flashMessenger = $this->plugin('FlashMessenger');
228
                $flashMessenger = $this->plugin('FlashMessenger');
223
 
229
    
224
            if (!$id) {
230
                if (!$id) {
-
 
231
                    $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
225
                $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
232
                    return $this->redirect()->toRoute('dashboard');
-
 
233
                }
-
 
234
            }
-
 
235
            
-
 
236
            
-
 
237
            
-
 
238
            $timestamp = time();
-
 
239
      
-
 
240
            list($usec, $sec) = explode(' ', microtime());
226
                return $this->redirect()->toRoute('dashboard');
241
            $seed = intval($sec + ((float) $usec * 100000));
-
 
242
            mt_srand($seed, MT_RAND_MT19937);
227
            }
243
            $rand =  mt_rand();
Línea 228... Línea -...
228
        }
-
 
229
 
-
 
230
 
244
            
231
        $this->layout()->setTemplate('layout/layout.phtml');
-
 
-
 
245
            
-
 
246
 
232
        $viewModel = new ViewModel();
247
            $password  = password_hash('user-' . $currentUser->uuid . '-post-' . $post->uuid . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $currentUser->share_key) ;
233
        $viewModel->setTemplate('leaders-linked/home/post.phtml');
-
 
234
        $viewModel->setVariables([
248
            
235
            'post' => $post,
249
            
236
            'id' => $post->id,
-
 
237
            'uuid' => $post->uuid,
-
 
238
            'title' => $post->title,
250
            $query = [
239
            'description' => $post->description,
251
                'user' => $currentUser->uuid, 
240
            'url' => $post->url,
-
 
-
 
252
                'timestamp' => $timestamp, 
241
            'date' => $post->date,
253
                'rand' => $rand, 
242
            'status' => $post->status,
-
 
243
            'image' => $post->image,
-
 
Línea -... Línea 254...
-
 
254
                'password' => $password,
-
 
255
                
-
 
256
            ]; 
-
 
257
            
-
 
258
            $share_url = $this->url()->fromRoute('share',  ['type' => 'post', 'code' => $post->uuid], ['force_canonical' => true, 'query' => $query ]);
-
 
259
    
-
 
260
    
-
 
261
            $this->layout()->setTemplate('layout/layout.phtml');
-
 
262
            $viewModel = new ViewModel();
-
 
263
            $viewModel->setTemplate('leaders-linked/home/post.phtml');
-
 
264
            $viewModel->setVariables([
-
 
265
                'post' => $post,
-
 
266
                'id' => $post->id,
-
 
267
                'uuid' => $post->uuid,
-
 
268
                'title' => $post->title,
-
 
269
                'description' => $post->description,
-
 
270
                'url' => $post->url,
-
 
271
                'date' => $post->date,
-
 
272
                'status' => $post->status,
-
 
273
                'image' => $post->image,
244
            'file' => $post->file,
274
                'file' => $post->file,
245
            'added_on' => $post->added_on,
275
                'added_on' => $post->added_on,
-
 
276
                'share_external_url' => $share_url,
-
 
277
                
-
 
278
            ]);
-
 
279
            return $viewModel;
-
 
280
            
-
 
281
        } else {
-
 
282
            $response = [
-
 
283
                'success' => false,
-
 
284
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
246
            'share_external_url' => $this->url()->fromRoute('share',  ['type' => 'post', 'code' => $post->uuid]),
285
            ];
Línea 247... Línea 286...
247
            
286
            
248
        ]);
287
            return new JsonModel($response);
249
        return $viewModel;
288
        }
250
    }
289
    }
251
    
290
    
252
    public function shareAction()
291
    public function shareAction()
Línea 253... Línea 292...
253
    {
292
    {
254
        $request = $this->getRequest();
293
        $request = $this->getRequest();
255
        if ($request->isGet()) {
294
        if ($request->isGet()) {
-
 
295
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
296
            $currentUser = $currentUserPlugin->getUser();
-
 
297
            
-
 
298
            $code       = $this->params()->fromRoute('code');
-
 
299
            $type       = $this->params()->fromRoute('type');
-
 
300
            $user       = $this->params()->fromQuery('user');
-
 
301
            $timestamp  = intval($this->params()->fromQuery('timestamp'), 10);
-
 
302
            $rand       = intval($this->params()->fromQuery('rand'), 10);
-
 
303
            $password   = $this->params()->fromQuery('password');
-
 
304
            $checkpassword = '';
-
 
305
                 
-
 
306
            $userCheck = '';
-
 
307
            if($user && $timestamp > 0 && $rand > 0 && $password) {
Línea -... Línea 308...
-
 
308
                $userMapper = UserMapper::getInstance($this->adapter);
256
            $currentUserPlugin = $this->plugin('currentUserPlugin');
309
                $userCheck = $userMapper->fetchOneByUuid($user);
257
            $currentUser = $currentUserPlugin->getUser();
310
                if($userCheck) {
258
            
311
                    $checkpassword  = password_hash('user-' . $userCheck->uuid . '-'.$type.'-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key) ;
259
            $code = $this->params()->fromRoute('code');
312
                }
260
            $type = $this->params()->fromRoute('type');
313
            }
Línea 261... Línea 314...
261
            $user = $this->params()->fromQuery('user');
314
            
262
            
315
     
-
 
316
            if(empty($password) || $password != $checkpassword) {
263
            if(!$user) {
317
                $data = [
-
 
318
                    'success' => false,
-
 
319
                    'data' => 'ERROR_UNAUTHORIZED'
-
 
320
                ];
-
 
321
                
-
 
322
                return new JsonModel($data);
-
 
323
            }
Línea 264... Línea 324...
264
                $response = [
324
            
265
                    'success' => false,
325
            
Línea 282... Línea 342...
282
            
342
            
283
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
343
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
284
            $share_image        = $base_share . '/images/ll-logo.png';
344
            $share_image        = $base_share . '/images/ll-logo.png';
285
            $share_title        = '';
345
            $share_title        = '';
286
            $share_description  = '';
-
 
287
            /*
-
 
288
            [fullpath]
-
 
289
            chat=data/storage/chat/
-
 
290
            group=data/storage/group/
-
 
291
            user=data/storage/user/
-
 
292
            image=data/storage/image/
-
 
293
            job=data/storage/job/
-
 
294
            company=data/storage/company/
-
 
295
            feed=data/storage/feed/
-
 
296
            post=data/storage/post/
-
 
297
            /storage/type/feed/code/ef1038de-4f26-4253-a886-e125784ab604/filename/th-2400499377.png/
346
            $share_description  = '';
298
            *
-
 
Línea 299... Línea 347...
299
            */
347
 
300
            
348
            
301
            if($type == 'feed' && $code ) {
349
            if($type == 'feed' && $code ) {
Línea 413... Línea 461...
413
           
461
           
-
 
462
 
-
 
463
            
-
 
464
            
-
 
465
            if($currentUserPlugin->hasIdentity()) {
-
 
466
                $currentUser = $currentUserPlugin->getUser();
-
 
467
                if($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id ) {
-
 
468
 
-
 
469
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
-
 
470
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
-
 
471
                        
-
 
472
                    if($connection) {
-
 
473
                            
-
 
474
                        if($connection->status != Connection::STATUS_ACCEPTED) {
-
 
475
                            $connectionMapper->approve($connection);
-
 
476
                        }
-
 
477
                            
-
 
478
                    } else {
-
 
479
                        $connection = new Connection();
-
 
480
                        $connection->request_from = $currentUser->id;
-
 
481
                        $connection->request_to = $userCheck->id;
-
 
482
                        $connection->status = Connection::STATUS_ACCEPTED;
-
 
483
                            
-
 
484
                        $connectionMapper->insert($connection);
-
 
485
                    }
-
 
486
                }
414
 
487
                
415
            
488
                
-
 
489
 
-
 
490
                
416
            
491
                $this->layout()->setTemplate('layout/layout.phtml');
417
            if($currentUserPlugin->hasIdentity()) {
492
            } else {
418
                $this->layout()->setTemplate('layout/layout.phtml');
493
                $this->cache->addItem('user_share_invitation', $user);
419
            } else {
494
                
420
                $this->layout()->setTemplate('layout/share.phtml');
495
                $this->layout()->setTemplate('layout/share.phtml');
Línea 443... Línea 518...
443
        }
518
        }
Línea 444... Línea 519...
444
        
519
        
Línea 445... Línea -...
445
       
-
 
446
    }
-
 
447
    
-
 
448
    public function shareCallbackAction()
-
 
449
    {
-
 
450
        $request = $this->getRequest();
-
 
451
        if ($request->isGet()) {
-
 
452
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
453
           
-
 
454
            
-
 
455
            $code = $this->params()->fromRoute('code');
-
 
456
            $type = $this->params()->fromRoute('type');
-
 
457
            
-
 
458
            
-
 
459
            
-
 
460
            
-
 
461
            $url_redirect = '';
-
 
462
            $user_redirect = '';
-
 
463
            if($type == 'feed' && $code ) {
-
 
464
                $feedMapper =  FeedMapper::getInstance($this->adapter);
-
 
465
                $feed = $feedMapper->fetchOneByUuid($code);
-
 
466
                
-
 
467
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
-
 
468
                        
-
 
469
                    $url_redirect = $this->url()->fromRoute('dashboard', ['feed' => $feed->uuid]);
-
 
470
                }
-
 
471
                
-
 
472
                
-
 
473
            } else if ($type == 'post' && $code) {
-
 
474
                
-
 
475
                $postMapper = PostMapper::getInstance($this->adapter);
-
 
476
                $post = $postMapper->fetchOneByUuid($code);
-
 
477
                
-
 
478
                if($post && $post->status == Post::STATUS_ACTIVE) {
-
 
479
                    $url_redirect = $this->url()->fromRoute('post', ['id' => $post->uuid]);
-
 
480
                }
-
 
481
            }
-
 
482
            
-
 
483
            if($user) {
-
 
484
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
485
                $user = $userMapper->fetchOneByUuid($user);
-
 
486
                
-
 
487
                if($user && $user->status == User::STATUS_ACTIVE && $currentUserPlugin->hasIdentity()) {
-
 
488
                    $currentUser = $currentUserPlugin->getUser();
-
 
489
                    
-
 
490
                    if($user->id != $currentUser->id) {
-
 
491
                        
-
 
492
                        $connectionMapper = ConnectionMapper::getInstance($this->adapter);
-
 
493
                        $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
-
 
494
                        
-
 
495
                        if($connection) {
-
 
496
                            
-
 
497
                            if($connection->status != Connection::STATUS_ACCEPTED) {
-
 
498
                                $connectionMapper->approve($connection);
-
 
499
                            }
-
 
500
                            
-
 
501
                        } else {
-
 
502
                            $connection = new Connection();
-
 
503
                            $connection->request_from = $currentUser->id;
-
 
504
                            $connection->request_to = $user->id;
-
 
505
                            $connection->status = Connection::STATUS_ACCEPTED;
-
 
506
                            
-
 
507
                            $connectionMapper->insert($connection);
-
 
508
                        }
-
 
509
                    }
-
 
510
                }
-
 
511
            }
-
 
512
                
-
 
513
            
-
 
514
            if ($currentUserPlugin->hasIdentity()) {
-
 
515
                if($url_redirect) {
-
 
516
                    return $this->redirect()->toUrl($url_redirect);
-
 
517
                } else {
-
 
518
                    return $this->redirect()->toRoute('dashboard');
-
 
519
                }
-
 
520
            } else {
-
 
521
                $this->cache->addItem('url_redirect', $url_redirect);
-
 
522
                $this->cache->addItem('user_redirect', $user_redirect);
-
 
523
 
-
 
524
                return $this->redirect()->toRoute('signin');
-
 
525
            }
-
 
526
        } else {
-
 
527
            $response = [
-
 
528
                'success' => false,
-
 
529
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
520
       
530
            ];
-
 
531
        }
-
 
532
        
521
    }