super.init(); // Init the session variables initSession(); this.loginComponent = server.CommonSpot.api.getObject('Login'); // Init the API Config Settings initAPIConfig(); return this; // Check if the session space does NOT exist, then setup the variables if ( NOT StructKeyExists(session.ADF,"API") ) { session.ADF.API = StructNew(); // Init the API Config Settings initAPIConfig(); } // - Init the session variables if they don't exist if ( NOT StructKeyExists(session.ADF.API, "token") ) session.ADF.API.token = ""; if ( NOT StructKeyExists(session.ADF.API, "siteURL") ) session.ADF.API.siteURL = ""; if ( NOT StructKeyExists(session.ADF.API, "subsiteID") ) session.ADF.API.subsiteID = 1; if ( NOT StructKeyExists(session.ADF.API, "remote") ) session.ADF.API.remote = false; if ( NOT StructKeyExists(session.ADF.API, "csSession") ) session.ADF.API.csSession = StructNew(); if ( NOT StructKeyExists(session.ADF.API.csSession, "cfID") ) session.ADF.API.csSession.cfID = ""; if ( NOT StructKeyExists(session.ADF.API.csSession, "cfToken") ) session.ADF.API.csSession.cfToken = ""; if ( NOT StructKeyExists(session.ADF.API.csSession, "jSessionID") ) session.ADF.API.csSession.jSessionID = ""; // Get the user account from the CCAPI Config var apiConfig = getAPIConfig(); // Set the setSiteURL if ( isStruct(apiConfig) AND StructKeyExists(apiConfig, "wsVars") ) { setSiteURL(apiConfig.wsVars.siteURL); setSubsiteID(apiConfig.wsVars.subsiteID); } // Get the user account from the CCAPI Config var apiConfig = getAPIConfig(); var loginCmd = StructNew(); //var command = StructNew(); var command = ''; var retDataCmd = ""; var userName = ""; var password = ""; if ( LEN(TRIM(arguments.forceUsername)) ) userName = arguments.forceUsername; else userName = apiConfig.wsVars.csuserid; if ( LEN(TRIM(arguments.forcePassword)) ) password = arguments.forcePassword; else password = apiConfig.wsVars.cspassword; // Setup the Session space initSession(); // Clear the CS Session session.ADF.API.csSession = StructNew(); session.ADF.API.csSession.cfID = ""; session.ADF.API.csSession.cfToken = ""; session.ADF.API.csSession.jSessionID = ""; // Validate the config has the fields we need /* if( isStruct(apiConfig) AND structKeyExists(apiConfig, "wsVars") AND structKeyExists(apiConfig.wsVars, "csuserid") AND structKeyExists(apiConfig.wsVars, "cspassword") AND structKeyExists(apiConfig.wsVars, "siteURL") AND structKeyExists(apiConfig.wsVars, "subsiteID") ) { */ // Set the setSiteURL setSiteURL(apiConfig.wsVars.siteURL); // Set the subsiteID // Check if we want to force login to a specific subsite if ( arguments.forceSubsiteID GT 0 ) setSubsiteID(arguments.forceSubsiteID); else setSubsiteID(apiConfig.wsVars.subsiteID); // If forcing remote calls, then set the remote flag if ( arguments.remote ) setRemoteflag(arguments.remote); // Check if we want to remote login if ( getRemoteFlag() ) { command = StructNew(); command['Target'] = "Login"; command['Method'] = "doLogin"; command['Args'] = StructNew(); command['Args']['userName'] = userName; command['Args']['password'] = password; /* command = ' Login doLogin #userName# #password# '; */ // Run command and return Array retDataCmd = runRemote(commandStruct=command, authCommand=false); // Validate the return array and set the login data return if ( isArray(retDataCmd) AND ArrayLen(retDataCmd) AND StructKeyExists(retDataCmd[1], "data") ) loginCmd = retDataCmd[1].data; } else { // Login via ColdFusion loginCmd = this.loginComponent.doLogin(userName=userName, password=password); } if ( isStruct(loginCmd) AND StructKeyExists(loginCmd, "LoginResult") EQ 1 AND StructKeyExists(loginCmd, "SessionCookies") AND StructKeyExists(loginCmd.SessionCookies, "cfID") AND StructKeyExists(loginCmd.SessionCookies, "cfToken") ) { // Login Success session.ADF.API.csSession = loginCmd.SessionCookies; setAPIToken(); if( apiConfig.logging.enabled ) variables.utils.logAppend("#request.formattedTimestamp# - Success logging in to API. [LoginResult:#loginCmd.LoginResult#] [Token:#getAPIToken()#] [SubSiteID:#getSubsiteID()#]", "API_Login.log"); } else if ( isStruct(loginCmd) AND StructKeyExists(loginCmd, "LoginResult") EQ 2 ) { // Need Password Change clearAPIToken(); if( apiConfig.logging.enabled ) variables.utils.logAppend("#request.formattedTimestamp# - Error logging in to API. Password needs to be changed. [LoginResult:#loginCmd.LoginResult#]", "API_Login.log"); } else if ( isStruct(loginCmd) AND StructKeyExists(loginCmd, "LoginResult") EQ 0 ) { // Login Failed clearAPIToken(); if( apiConfig.logging.enabled ) variables.utils.logAppend("#request.formattedTimestamp# - Error logging in to API. Login Failed. [LoginResult:#loginCmd.LoginResult#]", "API_Login.log"); } else { // Error with Login clearAPIToken(); if( apiConfig.logging.enabled ) variables.utils.logAppend("#request.formattedTimestamp# - Error logging in to API.", "API_Login.log"); }
#cfcatch.Message#
//var command = StructNew(); var command = ''; var retDataCmd = ""; var loginStatus = false; // Setup the Session space initSession(); // Check if the session token is defined if ( LEN(getAPIToken()) ) { if ( getRemoteFlag() ) { // Login via ColdFusion command = StructNew(); command['Target'] = "Login"; command['Method'] = "isLoggedIn"; /* command = ' Login isLoggedIn '; */ // Run command and return Array retDataCmd = runRemote(commandStruct=command, authCommand=false); //application.ADF.utils.dodump(retDataCmd,"retDataCmd - isLoggedIn", false); // Validate the return array and set the login data return if ( isArray(retDataCmd) AND ArrayLen(retDataCmd) AND StructKeyExists(retDataCmd[1], "data") ) loginStatus = retDataCmd[1].data; } else { // Login via ColdFusion loginStatus = this.loginComponent.isLoggedIn(); } } return loginStatus; // Get the user account from the CCAPI Config var apiConfig = getAPIConfig(); var command = ''; var retDataCmd = ""; var logoutMsg = "Success:1"; var logoutStatus = true; try { // Setup the Session space initSession(); if ( getRemoteFlag() ){ // Login via ColdFusion command = StructNew(); command['Target'] = "Login"; command['Method'] = "doLogout"; /* command = ' Users doLogout '; */ // Run command and return Array retDataCmd = runRemote(commandStruct=command, authCommand=false); } else { // logout via ColdFusion this.loginComponent.doLogout(); // Returns VOID } // Clear the session variables session.ADF.API.csSession = StructNew(); session.ADF.API.csSession.cfID = ""; session.ADF.API.csSession.cfToken = ""; session.ADF.API.csSession.jSessionID = ""; clearAPIToken(); } catch (any e) { logoutMsg = "Error:" & e.message; logoutStatus = false; } if( apiConfig.logging.enabled ) { if ( logoutStatus ) variables.utils.logAppend("#request.formattedTimestamp# - API Logout Success.", "API_Login.log"); else variables.utils.logAppend("#request.formattedTimestamp# - API Logout Failed. #e.message#", "API_Login.log"); } return logoutMsg; var commandXML = ""; var command_collection = ''; var CFID = ""; var CFToken = ""; var httpSubsiteURL = ""; // Setup the Session space initSession(); // Make sure our session is flagged remote setRemoteFlag(remoteFlag=true); // Get the subsiteURL for the HTTP request httpSubsiteURL = buildSubsiteFullURL(session.ADF.API.subsiteID); // Psuedo overloading the arguments // Check if the commands collection is a structure if ( isStruct(arguments.commandStruct) AND StructCount(arguments.commandStruct) GT 0 ) { commandXML = server.CommonSpot.UDF.Util.serializeBean(commandStruct); // Trim off the surrounding "" tags commandXML = MID(commandXML,9,LEN(commandXML)-17); } else if ( LEN(arguments.commandArgsXML) ) { commandXML = arguments.commandArgsXML; } // Validate if the XML starts with "COMMAND" if ( MID(server.commonspot.UDF.HTML.escape(TRIM(commandXML)),5, 7) NEQ "Command" ) commandXML = '' & commandXML & ''; command_collection = '' & #commandXML# & ''; //application.ADF.utils.dodump(command_collection,"command_collection",false); // Check if session is logged in if ( arguments.authCommand AND NOT isLoggedIn() ) login(remote=true,forceSubsite=session.ADF.API.subsiteID); //application.ADF.utils.dodump(session.ADF.API,"session.ADF.API - runRemote",false); // Check if the command requires authentication // AND we are logged in. if ( arguments.authCommand AND NOT LEN(session.ADF.API.token) ) return ""; //application.ADF.utils.dodump(cfhttp,"cfhttp - runRemote",false); if ( isXML(cfhttp.fileContent) ) return server.Commonspot.UDF.util.deserialize(cfhttp.fileContent); var wsObj = ""; var result = StructNew(); // Init the return data structure result.status = false; result.msg = ""; result.data = StructNew(); // Setup the Session space initSession(); // Set the flag to make all CCAPI commands as remote //setRemoteFlag(true); // Check if we are not logged OR not logged into the correct subsite if ( NOT isLoggedIn() OR (getSubsiteID() NEQ sparams.subsiteID) ) { // Login with the Public API //login(remote=true, forceSubsiteID=sparams.subsiteID); //login(forceSubsiteID=sparams.subsiteID); // Login through the CCAPI if ( LEN(TRIM(arguments.forceUsername)) AND LEN(TRIM(arguments.forcePassword)) ) { ccapiLogin(forceUsername=arguments.forceUsername,forcePassword=arguments.forcePassword,forceSubsiteID=sparams.subsiteID); } else { //setSubsiteID(sparams.subsiteID); ccapiLogin(forceSubsiteID=sparams.subsiteID); } } wsObj = getWebService(); // If the web service is setup and the login token is valid if ( LEN(getAPIToken()) ) { try { switch (arguments.method) { // Populate Custom Element Record case "populateCustomElement": result.data = wsObj.populateCustomElement(ssid=getAPIToken(), sparams=arguments.sparams); //application.ADF.utils.dodump(result,"result",false); if ( IsSimpleValue(result.data) AND FindNoCase("success",result.data) ) result.status = true; //application.ADF.utils.dodump(result,"result",false); break; // Populate a Text Block case "populateTextBlock": break; } } catch (ANY e) { // Error caught, send back the error message result.status = false; result.msg = e.message; result.data = e; } } else { result.status = false; result.msg = "Error loading the Web Service."; } return result; // Get the user account from the CCAPI Config var apiConfig = getAPIConfig(); var wsObj = getWebService(); var error = ''; var loginResult = ''; var userName = ''; var password = ''; if ( LEN(TRIM(arguments.forceUsername)) ) userName = arguments.forceUsername; else userName = apiConfig.wsVars.csuserid; if ( LEN(TRIM(arguments.forcePassword)) ) password = arguments.forcePassword; else password = apiConfig.wsVars.cspassword; // Check if we want to force login to a specific subsite if ( arguments.forceSubsiteID GT 0 ) setSubsiteID(arguments.forceSubsiteID); else setSubsiteID(apiConfig.wsVars.subsiteID); loginResult = wsObj.csLogin(site = getSiteURL(), csUserID = userName, csPassword = password, subSiteID = getSubsiteID(), subSiteURL = ''); //application.ADF.utils.doDUMP(loginResult,"loginResult",1); // Verify that the login was successful and set the Token if ( ListFirst(loginResult, ":") is "Success" ) { // Process the SSID processSSID(ssid=ListRest(loginResult, ":")); //application.ADF.utils.doDUMP(session.ADF.api,"session.ADF.api",1); // Log Success if( apiConfig.logging.enabled ) variables.utils.logAppend("#request.formattedTimestamp# - Success logging in to CCAPI. [Token:#getAPIToken()#], [SubSiteID:#getSubsiteID()#]", "API_Login.log"); } else { // Clear the Token clearAPIToken(); error = ListRest(loginResult, ":"); // Log Error if( apiConfig.logging.enabled ) variables.utils.logAppend("#request.formattedTimestamp# - Error logging in to CCAPI: #error#", "API_Login.log"); } // Get the user account from the CCAPI Config var apiConfig = getAPIConfig(); var wsObj = getWebService(); var logoutResult = wsObj.csLogout(ssid=getAPIToken()); // Verify that the login was successful and set the Token if ( ListFirst(logoutResult, ":") is "Success" ) { // Clear the API token clearAPIToken(); // Log Success if ( apiConfig.logging.enabled ) variables.utils.logAppend("#request.formattedTimestamp# - CCAPI Logout Success.", "API_Login.log"); } else { // Log Error if ( apiConfig.logging.enabled ) variables.utils.logAppend("#request.formattedTimestamp# - Error Logout with the CCAPI: #logoutResult#", "API_Login.log"); } var result = StructNew(); var cookieInfo = ArrayNew(1); if ( Len(arguments.ssid) GT 0 ) { session.ADF.API.csSession.CFID = ListFirst(arguments.ssid, " "); if ( ListLen(arguments.ssid, " ") GTE 2 ) session.ADF.API.csSession.CFToken = ListGetAt(arguments.ssid, 2, " "); else session.ADF.API.csSession.CFToken = 0; if ( ListLen(arguments.ssid, " ") GT 3 ) session.ADF.API.csSession.JSessionID = ListGetAt(arguments.ssid, 3, " "); } setSiteURL(ListLast(arguments.ssid, " ")); setAPIToken(); var httpSubsiteURL = getSiteURL(); var subsiteData = application.ADF.csData.getSubsiteQueryByID(subsiteID=getSubsiteID()); // Remove the root subsite from the path httpSubsiteURL = Replace(httpSubsiteURL, request.site.CP_URL, ""); // Add the subsite path to the string httpSubsiteURL = httpSubsiteURL & subsiteData.SubSiteURL; return httpSubsiteURL; var apiConfig = getAPIConfig(); var wsURL = ""; var wsPath = "commonspot.webservice.cs_service"; // Set the wsURL from the apiConfig if( isStruct(apiConfig) AND structKeyExists(apiConfig, "wsVars") AND structKeyExists(apiConfig.wsVars,"webserviceURL") AND LEN(apiConfig.wsVars.webserviceURL) ) wsURL = apiConfig.wsVars.webserviceURL; if ( getRemoteFlag() AND LEN(TRIM(wsURL)) ) { // Call the remote Web Service return createObject("webService", wsURL); } else { // Use the config webservice URL value to determine the correct wsPath if ( FindNoCase("cs_remote",wsURL) ) wsPath = "commonspot.webservice.cs_remote"; // Create the local object directly on the server return createObject("component", wsPath); } // Check the length to see is defined if ( LEN(arguments.siteURL) ) { session.ADF.API.siteURL = arguments.siteURL; // Set the remote status //setRemoteFlag(true); } else { // If the config site URL is not undefined, then make commands against the current site URL session.ADF.API.siteURL = request.site.url; // Set the remote status //setRemoteFlag(false); } // Check if ends in "/" if ( RIGHT(session.ADF.API.siteURL, 1) NEQ "/" ) session.ADF.API.siteURL = session.ADF.API.siteURL & "/"; session.ADF.API.token = session.ADF.API.csSession.cfID & " " & session.ADF.API.csSession.cfToken; if ( LEN(session.ADF.API.csSession.JSessionID) ) session.ADF.API.token = session.ADF.API.token & " " & session.ADF.API.csSession.JSessionID; session.ADF.API.token = session.ADF.API.token & " " & getSiteURL(); var tempStruct = structNew(); // Build a init struct keys to pass back tempStruct.logging = StructNew(); tempStruct.logging.enabled = false; tempStruct.elements = StructNew(); tempStruct.wsVars = StructNew(); tempStruct.wsVars.webserviceURL = ""; tempStruct.wsVars.csuserid = ""; tempStruct.wsVars.cspassword = ""; tempStruct.wsVars.site = ""; tempStruct.wsVars.siteURL = ""; tempStruct.wsVars.subsiteID = 1; tempStruct.wsVars.cssites = ""; if ( NOT StructKeyExists(server.ADF.environment, request.site.id) ) { //return tempStruct; server.ADF.environment[request.site.id] = StructNew(); StructInsert(server.ADF.environment[request.site.id], "apiConfig", tempStruct); } // Build the temporary config if nothing is defined at the site config level else if ( NOT StructKeyExists(server.ADF.environment[request.site.id], "apiConfig") ) { // Insert into the Site Config StructInsert(server.ADF.environment[request.site.id], "apiConfig", tempStruct, true); } return server.ADF.environment[request.site.id].apiConfig;