mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Implemented getUserInfos for current user
This commit is contained in:
		@@ -1,3 +1,3 @@
 | 
				
			|||||||
# WEB-WebComunicApp
 | 
					# WEB-WebComunicApp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WebComunic RestClient
 | 
					WebComunic RestClient (Javascript WebApplication)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +0,0 @@
 | 
				
			|||||||
# WEB-WebComunicApp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
WebComunic RestClient
 | 
					 | 
				
			||||||
@@ -21,9 +21,12 @@ ComunicWeb.common.api.makeAPIrequest = function(apiURI, params, requireLoginToke
 | 
				
			|||||||
        //Get login tokens
 | 
					        //Get login tokens
 | 
				
			||||||
        tokens = ComunicWeb.user.loginTokens.getLoginTokens();
 | 
					        tokens = ComunicWeb.user.loginTokens.getLoginTokens();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(tokens){
 | 
				
			||||||
            //Add tokens
 | 
					            //Add tokens
 | 
				
			||||||
        params.token1 = tokens.token1;
 | 
					            params.userToken1 = tokens.token1;
 | 
				
			||||||
        params.token2 = tokens.token2;
 | 
					            params.userToken2 = tokens.token2;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Prepare data to send in request
 | 
					    //Prepare data to send in request
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,11 +9,59 @@ ComunicWeb.user.getUserInfos = {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @var {String} User infos cache
 | 
					     * @var {String} User infos cache
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
					    usersInfos: {},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Get user informations
 | 
					     * Get user informations
 | 
				
			||||||
     * 
 | 
					     * 
 | 
				
			||||||
     * @param {String} userID User on which to make request (current to get connected user)
 | 
					     * @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
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -51,6 +51,7 @@ $config['JSfiles'] = array(
 | 
				
			|||||||
    //User scripts
 | 
					    //User scripts
 | 
				
			||||||
    "%PATH_ASSETS%js/user/loginTokens.js",
 | 
					    "%PATH_ASSETS%js/user/loginTokens.js",
 | 
				
			||||||
    "%PATH_ASSETS%js/user/userLogin.js",
 | 
					    "%PATH_ASSETS%js/user/userLogin.js",
 | 
				
			||||||
 | 
					    "%PATH_ASSETS%js/user/userInfos.js",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Pages scripts
 | 
					    //Pages scripts
 | 
				
			||||||
    "%PATH_ASSETS%js/pages/home/home.js",
 | 
					    "%PATH_ASSETS%js/pages/home/home.js",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,6 @@ $config['siteMode'] = "dev";
 | 
				
			|||||||
$config['siteURL'] = "http://devweb.local/comunic/v2/";
 | 
					$config['siteURL'] = "http://devweb.local/comunic/v2/";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//API config
 | 
					//API config
 | 
				
			||||||
$config['API_URL'] = "http://devweb.local/comunic/current/api.php/";
 | 
					$config['API_URL'] = "http://devweb.local/comunic/api/";
 | 
				
			||||||
$config['API_SERVICE_NAME'] = "";
 | 
					$config['API_SERVICE_NAME'] = "testService";
 | 
				
			||||||
$config['API_SERVICE_TOKEN'] = "";
 | 
					$config['API_SERVICE_TOKEN'] = "testPasswd";
 | 
				
			||||||
		Reference in New Issue
	
	Block a user