diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/superadmin/TipGetTokenServiceAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/superadmin/TipGetTokenServiceAction.java index fd506765eb..2384e3c28e 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/superadmin/TipGetTokenServiceAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/superadmin/TipGetTokenServiceAction.java @@ -70,7 +70,9 @@ public String execute() throws Exception { connection.setRequestProperty("Accept", "application/json"); connection.setDoOutput(true); - String requestBody = "{private_key:" + privateKey + "}"; + String requestBody = "{\"private_key\":\"" + privateKey.replace("\"", "\\\"") + "\"}"; + + // String requestBody = "{private_key:" + privateKey + "}"; // Get the output stream to send data try (OutputStream os = connection.getOutputStream()) { diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/tip/TipDinamicUrlGenerationAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/tip/TipDinamicUrlGenerationAction.java index 032ae76347..77a4a6798f 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/tip/TipDinamicUrlGenerationAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/tip/TipDinamicUrlGenerationAction.java @@ -22,9 +22,12 @@ import org.cgiar.ccafs.marlo.utils.AESConvert; import java.util.List; +import java.util.Map; import javax.inject.Inject; +import org.apache.commons.lang3.StringUtils; +import org.apache.struts2.dispatcher.Parameter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,6 +38,7 @@ public class TipDinamicUrlGenerationAction extends BaseAction { // Front-end private String dinamicTipURL; + private String tokenParameter; @Inject private TipParametersManager tipParametersManager; @@ -50,6 +54,9 @@ public String createDinamicURL() { try { String userEmail = "", token = "", loginService = ""; + if (tokenParameter != null && !tokenParameter.isEmpty()) { + token = tokenParameter; + } if (this.getCurrentUser() != null && this.getCurrentUser().getEmail() != null) { userEmail = this.getCurrentUser().getEmail(); if (this.getCurrentUser().isCgiarUser() == true) { @@ -93,9 +100,15 @@ public String createDinamicURL() { @Override public String execute() throws Exception { + Map parameters = this.getParameters(); + try { + tokenParameter = StringUtils.trim(parameters.get(APConstants.FIELD_ID).getMultipleValues()[0]); + } catch (Exception e) { + LOG.error("Error reading token parameter: " + e); + } - if (this.createDinamicURL() != null) { - this.dinamicTipURL = this.createDinamicURL(); + this.dinamicTipURL = this.createDinamicURL(); + if (this.dinamicTipURL != null) { return SUCCESS; } return ERROR; diff --git a/marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js b/marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js index 0d49acec65..b34df58485 100644 --- a/marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js +++ b/marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js @@ -4,41 +4,58 @@ $(document).ready(function() { var iframeInitialWidth = '100%'; var iframeInitialHeight = '800px'; var fullscreenButton = null; + var token = null; - $.ajax({ - url: baseURL + '/tipGenerateUrlAction.do', - type: 'GET', - dataType: 'json', - success: function(response) { - - var embeddedPageUrl = response.dinamicTipURL; - console.log("embeddedPageUrl " + embeddedPageUrl); - iframe = document.createElement('iframe'); - iframe.src = embeddedPageUrl; - iframe.style.width = iframeInitialWidth; - iframe.style.height = iframeInitialHeight; - - /****************/ - iframe.setAttribute('allow', 'autoplay'); - iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-top-navigation'); + $.ajax({ + url: baseURL + '/tipTokenService.do', + type: 'POST', + dataType: 'json', + success: function(response) { + token = response.token; - // Add iframe to the element with ID 'embeddedPage' - document.getElementById('embeddedPage').appendChild(iframe); + $.ajax({ + url: baseURL + '/tipGenerateUrlAction.do', + data: { + fieldID: token + }, + type: 'GET', + dataType: 'json', + success: function(response) { + + var embeddedPageUrl = response.dinamicTipURL; + console.log("embeddedPageUrl " + embeddedPageUrl); + iframe = document.createElement('iframe'); + iframe.src = embeddedPageUrl; + iframe.style.width = iframeInitialWidth; + iframe.style.height = iframeInitialHeight; + + /****************/ + iframe.setAttribute('allow', 'autoplay'); + iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-top-navigation'); + + // Add iframe to the element with ID 'embeddedPage' + document.getElementById('embeddedPage').appendChild(iframe); + + // Create and add fullscreen button + fullscreenButton = document.createElement('button'); + fullscreenButton.classList.add('fullscreen-button'); + fullscreenButton.innerHTML = ' Fullscreen'; + + fullscreenButton.addEventListener('click', toggleFullscreen); + + // Add button to the 'embeddedPage' container + document.getElementById('embeddedPage').appendChild(fullscreenButton); + }, + error: function(xhr, status, error) { + console.error('Error getting embedded URL:', error); + } + }); - // Create and add fullscreen button - fullscreenButton = document.createElement('button'); - fullscreenButton.classList.add('fullscreen-button'); - fullscreenButton.innerHTML = ' Fullscreen'; - - fullscreenButton.addEventListener('click', toggleFullscreen); - - // Add button to the 'embeddedPage' container - document.getElementById('embeddedPage').appendChild(fullscreenButton); - }, - error: function(xhr, status, error) { - console.error('Error getting embedded URL:', error); - } - }); + }, + error: function(error) { + console.error('Error getting embedded URL:', error); + } + }); function toggleFullscreen() { var elem = document.getElementById('embeddedPage');