From 92fd8a62be24b898ac3797a70285d8dcd800dd72 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Wed, 12 Jun 2019 12:34:06 +0530 Subject: [PATCH] change 401 redirection in APPM store Ui --- .../react-app/public/conf/config.json | 1 + .../components/apps/release/ReleaseView.js | 4 ++-- .../apps/release/install/UserInstall.js | 4 ++-- .../apps/release/review/AddReview.js | 4 ++-- .../components/apps/release/review/Reviews.js | 14 ++++++------- .../react-app/src/js/actions/index.js | 20 +++++++++---------- .../react-app/src/pages/Login.js | 2 +- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/public/conf/config.json b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/public/conf/config.json index c2e66dda14..6f469f5e02 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/public/conf/config.json +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/public/conf/config.json @@ -4,6 +4,7 @@ "value": "lightBaseTheme" }, "serverConfig": { + "protocol": "https", "hostname": "localhost", "httpsPort": "9443", "invokerUri": "/api/application-mgt-handler/v1.0/invoke", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js index 4731d1eb82..d95377e1c9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js @@ -36,7 +36,7 @@ class ReleaseView extends React.Component { loading: true, }); - axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 201) { this.setState({ @@ -61,7 +61,7 @@ class ReleaseView extends React.Component { }).catch((error) => { if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/store/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; } else { this.setState({ loading: false, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js index f8e90f1864..3b6f45e534 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js @@ -38,7 +38,7 @@ class UserInstall extends React.Component { const request = Object.keys(parameters).map(key => key + '=' + parameters[key]).join('&'); console.log(request); - axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 200) { if (fetchId !== this.lastFetchId) { @@ -59,7 +59,7 @@ class UserInstall extends React.Component { }).catch((error) => { if (error.response.hasOwnProperty(status) && error.response.status === 401) { message.error('You are not logged in'); - window.location.href = 'https://localhost:9443/publisher/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; } else { message.error('Something went wrong... :('); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js index fa3af4c680..41f2a1b067 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js @@ -54,7 +54,7 @@ class AddReview extends React.Component { const request = "method=post&content-type=application/json&payload="+JSON.stringify(payload)+"&api-endpoint=/application-mgt-store/v1.0/reviews/"+uuid; - axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 201) { this.setState({ @@ -84,7 +84,7 @@ class AddReview extends React.Component { }).catch((error) =>{ if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/store/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; } else{ this.setState({ loading: false, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js index 6cc4442894..dadce12a04 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js @@ -27,8 +27,8 @@ class Reviews extends React.Component { } fetchData = (offset, limit, callback) => { - const request = "method=get&content-type=application/json&payload={}&api-endpoint=/application-mgt-store/v1.0/reviews/" + this.props.uuid+"?offset="+offset+"%26limit="+limit; - axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + const request = "method=get&content-type=application/json&payload={}&api-endpoint=/application-mgt-store/v1.0/reviews/" + this.props.uuid + "?offset=" + offset + "%26limit=" + limit; + axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 200) { let reviews = res.data.data.data; @@ -37,8 +37,8 @@ class Reviews extends React.Component { }).catch(function (error) { if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/store/login'; - }else{ + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/store/login'; + } else { message.warning('Something went wrong'); } @@ -46,7 +46,7 @@ class Reviews extends React.Component { }; handleInfiniteOnLoad = (count) => { - const offset = count*limit; + const offset = count * limit; let data = this.state.data; this.setState({ loading: true, @@ -59,13 +59,13 @@ class Reviews extends React.Component { return; } this.fetchData(offset, limit, res => { - if(res.length>0){ + if (res.length > 0) { data = data.concat(res); this.setState({ data, loading: false, }); - }else { + } else { this.setState({ hasMore: false, loading: false diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/actions/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/actions/index.js index 4fdcd14c1b..aad30831b3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/actions/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/actions/index.js @@ -6,7 +6,7 @@ export const getApps = () => dispatch => { const request = "method=post&content-type=application/json&payload={}&api-endpoint=/application-mgt-store/v1.0/applications"; - return axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + return axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 200) { let apps = []; @@ -19,7 +19,7 @@ export const getApps = () => dispatch => { }).catch(function (error) { if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/store/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; } }); @@ -29,7 +29,7 @@ export const getRelease = (uuid) => dispatch => { const request = "method=get&content-type=application/json&payload={}&api-endpoint=/application-mgt-store/v1.0/applications/" + uuid; - return axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + return axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 200) { let release = res.data.data.applicationReleases[0]; @@ -43,7 +43,7 @@ export const getRelease = (uuid) => dispatch => { } }).catch(function (error) { if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/store/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; }else if(error.response.status===404){ dispatch({ type: ActionTypes.GET_RELEASE, @@ -94,7 +94,7 @@ export const setLoading = (stateToLoad) => dispatch => { export const getLifecycle = () => dispatch => { const request = "method=get&content-type=application/json&payload={}&api-endpoint=/application-mgt-store/v1.0/applications/lifecycle-config"; - return axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + return axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 200) { let lifecycle = res.data.data; @@ -103,7 +103,7 @@ export const getLifecycle = () => dispatch => { }).catch(function (error) { if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/store/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; } }); }; @@ -118,7 +118,7 @@ export const updateLifecycleState = (uuid, nextState, reason) => dispatch => { const request = "method=post&content-type=application/json&payload=" + JSON.stringify(payload) + "&api-endpoint=/application-mgt-store/v1.0/applications/life-cycle/" + uuid; - return axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + return axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 201) { let release = res.data.data; @@ -132,7 +132,7 @@ export const updateLifecycleState = (uuid, nextState, reason) => dispatch => { }).catch(function (error) { if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/store/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; } else if (error.response.status === 500) { alert("error"); dispatch({ @@ -147,7 +147,7 @@ export const updateLifecycleState = (uuid, nextState, reason) => dispatch => { export const getDetailedRating = (uuid) => dispatch => { const request = "method=get&content-type=application/json&payload={}&api-endpoint=/application-mgt-store/v1.0/reviews/"+uuid+"/rating"; - return axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + return axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 200) { let detailedRating = res.data.data; @@ -156,7 +156,7 @@ export const getDetailedRating = (uuid) => dispatch => { }).catch(function (error) { if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/store/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; } else{ dispatch({ type: ActionTypes.GET_DETAILED_RATING, payload: null diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/Login.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/Login.js index 3e91317e0f..863d02aae9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/Login.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/Login.js @@ -58,7 +58,7 @@ class NormalLoginForm extends React.Component { loading: true }); let data = "username=" + values.username + "&password=" + values.password + "&platform=store"; - axios.post('https://'+config.serverConfig.hostname+':'+config.serverConfig.httpsPort+config.serverConfig.loginUri, data + axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname+':'+config.serverConfig.httpsPort+config.serverConfig.loginUri, data ).then(res => { if (res.status === 200) { window.location = res.data.url;