From d2b54f431b13bbb7141f61637e6510c9ee478567 Mon Sep 17 00:00:00 2001 From: Guillaume FAUVET Date: Fri, 8 Dec 2017 02:26:40 +0100 Subject: [PATCH] add: build.router.controller.loader upd: build.router.controller.api upd: build.router.controller.page --- build/router/controller/api.php | 6 ++-- build/router/controller/loader.php | 57 ++++++++++++++++++++++++++++++ build/router/controller/page.php | 40 +-------------------- 3 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 build/router/controller/loader.php diff --git a/build/router/controller/api.php b/build/router/controller/api.php index 6cf1106..989b9b4 100755 --- a/build/router/controller/api.php +++ b/build/router/controller/api.php @@ -32,11 +32,13 @@ * */ public function call(){ + /* (1) Authentication */ + \router\controller\loader::start(); - /* (1) Process response */ + /* (2) Process response */ $this->response = $this->request->dispatch(); - /* (2) Manages result */ + /* (3) Manages result */ if( $this->response instanceof Response ) echo $this->response->serialize(); diff --git a/build/router/controller/loader.php b/build/router/controller/loader.php new file mode 100644 index 0000000..186a1dc --- /dev/null +++ b/build/router/controller/loader.php @@ -0,0 +1,57 @@ + 0 ){ + + // get/send name to web socket + $wsi->send(['operation' => "Connect",'type' => 'user', 'name' => $_SESSION['USER']['username']]); + $check = $wsi->receive(); + + if( $check['error'] == false ) + $_SESSION['NAME'] = $check['name']; + + }elseif( count($_SESSION['ADMIN']) > 0 ){ + + // get/send name to web socket + $wsi->send(['operation' => "Connect",'type' => 'admin', 'name' => $_SESSION['ADMIN']['username']]); + $check = $wsi->receive(); + + if( $check['error'] == false ) + $_SESSION['NAME'] = $check['name']; + + }else{ + + // get/send name to web socket + $wsi->send(['operation' => "Connect",'type' => 'guest', 'name' => null]); + $check = $wsi->receive(); + + if( $check['error'] == false ) + $_SESSION['NAME'] = $check['name']; + } + + $wsi->close(); + $wsi = null; + + $_SESSION['WS'] = false; + } + } + +} \ No newline at end of file diff --git a/build/router/controller/page.php b/build/router/controller/page.php index d27051e..3765dd1 100755 --- a/build/router/controller/page.php +++ b/build/router/controller/page.php @@ -26,46 +26,8 @@ * */ public function load(){ + loader::start(); - if( $_SESSION['WS'] || strlen($_SESSION['NAME']) == 0 ){ - - // ask with websocketInterop - $wsi = new wsinterop('localhost', 9998); - - if( count($_SESSION['USER']) > 0 ){ - - // get/send name to web socket - $wsi->send(['operation' => "Connect",'type' => 'user', 'name' => $_SESSION['USER']['username']]); - $check = $wsi->receive(); - - if( $check['error'] == false ) - $_SESSION['NAME'] = $check['name']; - - }elseif( count($_SESSION['ADMIN']) > 0 ){ - - // get/send name to web socket - $wsi->send(['operation' => "Connect",'type' => 'admin', 'name' => $_SESSION['ADMIN']['username']]); - $check = $wsi->receive(); - - if( $check['error'] == false ) - $_SESSION['NAME'] = $check['name']; - - }else{ - - // get/send name to web socket - $wsi->send(['operation' => "Connect",'type' => 'guest', 'name' => null]); - $check = $wsi->receive(); - - if( $check['error'] == false ) - $_SESSION['NAME'] = $check['name']; - } - - $wsi->close(); - $wsi = null; - - $_SESSION['WS'] = false; - - } if( file_exists(__ROOT__."/view/home.php") ) include __ROOT__."/view/home.php"; else