From 55f0e55bbd2ebbf25e5658fc7fe56456840cb125 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 19 May 2017 18:17:32 +0200 Subject: [PATCH] Implemented getUserInfos for current user --- README.md | 2 +- README.md.bak | 3 -- assets/js/common/api.js | 9 ++++-- assets/js/user/userInfos.js | 50 ++++++++++++++++++++++++++++++- corePage/config/dev.config.php | 1 + corePage/config/global.config.php | 6 ++-- 6 files changed, 60 insertions(+), 11 deletions(-) delete mode 100644 README.md.bak diff --git a/README.md b/README.md index 47f7ef0c..16dba466 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # WEB-WebComunicApp -WebComunic RestClient +WebComunic RestClient (Javascript WebApplication) diff --git a/README.md.bak b/README.md.bak deleted file mode 100644 index 90d7b3e8..00000000 --- a/README.md.bak +++ /dev/null @@ -1,3 +0,0 @@ -# WEB-WebComunicApp - -WebComunic RestClient \ No newline at end of file diff --git a/assets/js/common/api.js b/assets/js/common/api.js index 7ca22be9..bd47c97c 100644 --- a/assets/js/common/api.js +++ b/assets/js/common/api.js @@ -21,9 +21,12 @@ ComunicWeb.common.api.makeAPIrequest = function(apiURI, params, requireLoginToke //Get login tokens tokens = ComunicWeb.user.loginTokens.getLoginTokens(); - //Add tokens - params.token1 = tokens.token1; - params.token2 = tokens.token2; + if(tokens){ + //Add tokens + params.userToken1 = tokens.token1; + params.userToken2 = tokens.token2; + } + } //Prepare data to send in request diff --git a/assets/js/user/userInfos.js b/assets/js/user/userInfos.js index 2ec01583..a987f67b 100644 --- a/assets/js/user/userInfos.js +++ b/assets/js/user/userInfos.js @@ -9,11 +9,59 @@ ComunicWeb.user.getUserInfos = { /** * @var {String} User infos cache */ + usersInfos: {}, /** * Get user informations * * @param {String} userID User on which to make request (current to get connected user) + * @param {function} afterGetUserInfos What to do once user informations are available + * @return {Boolean} False if it fails */ - //getUserInfos + getUserInfos: function(userID, afterGetUserInfos){ + //First, check if informations are already available in the cache + if(this.usersInfos[userID]) + afterGetUserInfos(this.usersInfos[userID]); //Then return these informations now + + //Else we have to perform an API request + if(userID == "current" || userID == ComunicWeb.user.userLogin.__userID){ + var apiURI = "user/getCurrentUserInfos"; + var params = {}; + } + else{ + ComunicWeb.debug.logMessage("ERROR : getUserInfos not implemented for other user than the current one !"); + } + + //Specify what to do next + var onceGetUserInfos = function(result){ + if(result.error){ + ComunicWeb.debug.logMessage("ERROR : couldn't get infos about user ID : "+userID+" !"); + return false; + } + + //Save result + ComunicWeb.user.getUserInfos.usersInfos[""+userID] = result[0]; + + //Return result + afterGetUserInfos(result[0]); + } + + //Perform request + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, onceGetUserInfos); + + //Everything is OK + return true; + + }, + + /** + * Empty user informations cache + * Remove all entries from user informations cache + * + * @return {Boolean} False if it fails + */ + emptyUserInfosCache: function(){ + this.userInfos = undefined; //Mark user info cache as undefined + this.userInfos = {}; //Create a new variable + }, } \ No newline at end of file diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index a16f3da9..fa633f11 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -51,6 +51,7 @@ $config['JSfiles'] = array( //User scripts "%PATH_ASSETS%js/user/loginTokens.js", "%PATH_ASSETS%js/user/userLogin.js", + "%PATH_ASSETS%js/user/userInfos.js", //Pages scripts "%PATH_ASSETS%js/pages/home/home.js", diff --git a/corePage/config/global.config.php b/corePage/config/global.config.php index 8081ea4b..90686af2 100644 --- a/corePage/config/global.config.php +++ b/corePage/config/global.config.php @@ -12,6 +12,6 @@ $config['siteMode'] = "dev"; $config['siteURL'] = "http://devweb.local/comunic/v2/"; //API config -$config['API_URL'] = "http://devweb.local/comunic/current/api.php/"; -$config['API_SERVICE_NAME'] = ""; -$config['API_SERVICE_TOKEN'] = ""; \ No newline at end of file +$config['API_URL'] = "http://devweb.local/comunic/api/"; +$config['API_SERVICE_NAME'] = "testService"; +$config['API_SERVICE_TOKEN'] = "testPasswd"; \ No newline at end of file