From bfe68b2af65f4fd61eb94cd906489e161be9639a Mon Sep 17 00:00:00 2001 From: Ayman Habeb Date: Tue, 27 Sep 2016 02:05:23 +0300 Subject: [PATCH 1/2] update all angular $http request to use params not hardcoded in the url --- control/content/app.service.js | 47 ++++++++++++++++++++-------------- widget/app.service.js | 42 ++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/control/content/app.service.js b/control/content/app.service.js index 23dfd0f..101e734 100644 --- a/control/content/app.service.js +++ b/control/content/app.service.js @@ -22,7 +22,7 @@ postDataObject.params.externalAppId = appId; postDataObject.apiKey = API_KEY.value; var successCallback = function (response) { - console.log('Resolve in add application Api-------------------',response); + console.log('Resolve in add application Api-------------------', response); return deferred.resolve(response); }; var errorCallback = function (err) { @@ -30,7 +30,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link+'?data='+ JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -42,11 +43,11 @@ postDataObject.method = 'thread/getThread'; postDataObject.params = {}; postDataObject.params.appId = socialAppId; - postDataObject.params.uniqueLink = encodeURIComponent(context.appId + context.instanceId); + postDataObject.params.uniqueLink = encodeURIComponent(context.appId + context.instanceId); postDataObject.params.userToken = null; postDataObject.params.title = context.pluginTitle || null; postDataObject.params.title = encodeURIComponent(postDataObject.params.title); - postDataObject.userToken = null; + postDataObject.userToken = null; var successCallback = function (response) { console.log('thread/getThread in content callback recieved--------------', response); return deferred.resolve(response); @@ -57,7 +58,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -68,22 +70,23 @@ postDataObject.id = '1'; postDataObject.method = 'thread/findByPage'; postDataObject.params = {}; - postDataObject.params.appId = data.socialAppId; + postDataObject.params.appId = data.socialAppId; postDataObject.params.parentThreadId = data.parentThreadId; postDataObject.params.lastThreadId = data.lastThreadId; postDataObject.userToken = null; var successCallback = function (response) { - console.log('Get items---------------------------in content',response); + console.log('Get items---------------------------in content', response); return deferred.resolve(response); }; var errorCallback = function (err) { - console.log('Get items----------error-----------------in content',err); + console.log('Get items----------error-----------------in content', err); return deferred.reject(err); }; $http({ method: 'GET', - url: SERVER_URL.link+'?data='+ JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -104,12 +107,13 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data='+ JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; }, - deletePost: function (postId, socialAppId,secureToken) { + deletePost: function (postId, socialAppId, secureToken) { var deferred = $q.defer(); var postDeleteObject = {}; postDeleteObject.id = '1'; @@ -128,12 +132,13 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data='+ JSON.stringify(postDeleteObject), + url: SERVER_URL.link, + params: {data: postDeleteObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; }, - getCommentsOfAPost:function(data) { + getCommentsOfAPost: function (data) { var deferred = $q.defer(); var postDataObject = {}; postDataObject.id = '1'; @@ -153,7 +158,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -181,12 +187,13 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; }, - deleteComment: function (commentId, threadId, socialAppId,secureToken) { + deleteComment: function (commentId, threadId, socialAppId, secureToken) { var deferred = $q.defer(); var postDeleteObject = {}; postDeleteObject.id = '1'; @@ -206,13 +213,14 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data='+ JSON.stringify(postDeleteObject), + url: SERVER_URL.link, + params: {data: postDeleteObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; }, getThreadLikes: function (uniqueIds, socialAppId) { - console.log('Unique Ids------------------------',uniqueIds); + console.log('Unique Ids------------------------', uniqueIds); var deferred = $q.defer(); var postDataObject = {}; postDataObject.id = '1'; @@ -229,7 +237,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(success, error); return deferred.promise; diff --git a/widget/app.service.js b/widget/app.service.js index 10c9522..c649619 100644 --- a/widget/app.service.js +++ b/widget/app.service.js @@ -45,7 +45,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); /*$http.get('http://social.kaleoapps.com/src/server.js?data={"id":1,"method":"thread/add","params":{"appId":"551ae57f94ed199c3400002e","parentThreadId":"564f676cfbe10b9c240002ff","userToken":"ouOUQF7Sbx9m1pkqkfSUrmfiyRip2YptbcEcEcoX170=","text":"testThread","title":"","imageUrl":null,"secureToken":null},"userToken":null}').then(successCallback, errorCallback);*/ @@ -67,7 +68,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -96,7 +98,8 @@ console.log('Data----------------------------in add comment method--------', JSON.stringify(postDataObject)); $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -122,7 +125,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -147,7 +151,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -178,7 +183,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -229,7 +235,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -258,7 +265,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -281,7 +289,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(success, error); return deferred.promise; @@ -312,7 +321,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -359,7 +369,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDeleteObject), + url: SERVER_URL.link, + params: {data: postDeleteObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -384,7 +395,8 @@ }; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDeleteObject), + url: SERVER_URL.link, + params: {data: postDeleteObject}, headers: {'Content-Type': 'application/json'} }).then(successCallback, errorCallback); return deferred.promise; @@ -464,7 +476,8 @@ console.log('Post data in services-------------------', postDataObject); $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(function (data) { console.log('Get posts in service of SocialItems-------------------------', data); @@ -505,7 +518,8 @@ postDataObject.params.userToken = encodeURIComponent(_this.userDetails.userToken) || null; $http({ method: 'GET', - url: SERVER_URL.link + '?data=' + JSON.stringify(postDataObject), + url: SERVER_URL.link, + params: {data: postDataObject}, headers: {'Content-Type': 'application/json'} }).then(function (response) { console.log('inside getUser settings :::::::::::::', response); From 00099e6b73d41e36ff0cdf84c85acdf4426e8eb7 Mon Sep 17 00:00:00 2001 From: Ayman Habeb Date: Tue, 27 Sep 2016 21:23:17 +0300 Subject: [PATCH 2/2] remove encodeURIComponent and using the params in $http --- control/content/app.service.js | 4 ++-- widget/app.service.js | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/control/content/app.service.js b/control/content/app.service.js index 101e734..05b7f79 100644 --- a/control/content/app.service.js +++ b/control/content/app.service.js @@ -43,10 +43,10 @@ postDataObject.method = 'thread/getThread'; postDataObject.params = {}; postDataObject.params.appId = socialAppId; - postDataObject.params.uniqueLink = encodeURIComponent(context.appId + context.instanceId); + postDataObject.params.uniqueLink = context.appId + context.instanceId; postDataObject.params.userToken = null; postDataObject.params.title = context.pluginTitle || null; - postDataObject.params.title = encodeURIComponent(postDataObject.params.title); + postDataObject.params.title = postDataObject.params.title; postDataObject.userToken = null; var successCallback = function (response) { console.log('thread/getThread in content callback recieved--------------', response); diff --git a/widget/app.service.js b/widget/app.service.js index c649619..f05d646 100644 --- a/widget/app.service.js +++ b/widget/app.service.js @@ -31,9 +31,9 @@ postDataObject.params = postData || {}; //postDataObject.params.appId = "5672627b935839f42b000018"; postDataObject.params.secureToken = null; - postDataObject.params.userToken = encodeURIComponent(postData.userToken); + postDataObject.params.userToken = postData.userToken; // postDataObject.params.parentThreadId = "5672628a935839f42b00001a"; - postDataObject.userToken = encodeURIComponent(postData.userToken); + postDataObject.userToken = postData.userToken; console.log('Create post param ???????????????????????? ???????????????????? ', postDataObject); /*if (localStorage.getItem('user')) postData.params.userToken = localStorage.getItem('user').userToken;*/ @@ -85,8 +85,8 @@ postDataObject.params.threadId = data.threadId; postDataObject.params.comment = data.comment; postDataObject.params.attachedImage = data.imageUrl; - postDataObject.params.userToken = encodeURIComponent(data.userToken) || null; - postDataObject.userToken = encodeURIComponent(data.userToken) || null; + postDataObject.params.userToken = data.userToken || null; + postDataObject.userToken = data.userToken || null; var successCallback = function (response) { console.log('add Comment callback recieved--------------', response); return deferred.resolve(response); @@ -112,9 +112,9 @@ postDataObject.params = {}; postDataObject.params.appId = appId; postDataObject.params.uniqueLink = threadUniqueLink; - postDataObject.params.userToken = encodeURIComponent(userToken) || null; + postDataObject.params.userToken = userToken || null; postDataObject.params.title = null; - postDataObject.userToken = encodeURIComponent(userToken) || null; + postDataObject.userToken = userToken || null; var successCallback = function (response) { console.log('get Post callback recieved--------------', response); return deferred.resolve(response); @@ -166,7 +166,7 @@ postDataObject.params = {}; postDataObject.params.appId = appId; postDataObject.params.threadId = post._id; - postDataObject.params.userToken = encodeURIComponent(userToken); + postDataObject.params.userToken = userToken; postDataObject.params.parentThreadId = post.parentThreadId || post.threadId; postDataObject.params.additionalInfo = { type: type, @@ -224,7 +224,7 @@ postDataObject.params.appId = data.appId; postDataObject.params.threadId = data.threadId; postDataObject.params.userId = data.userId || null; - postDataObject.params.userToken = encodeURIComponent(data.userToken) || null; + postDataObject.params.userToken = data.userToken || null; var successCallback = function (response) { console.log('get Comment callback recieved--------------', response); return deferred.resolve(response); @@ -248,7 +248,7 @@ postDataObject.id = '1'; postDataObject.method = 'users/saveUserSettings'; postDataObject.params = {}; - postDataObject.params.userToken = encodeURIComponent(data.userToken) || null; + postDataObject.params.userToken = data.userToken || null; postDataObject.params.userSettings = {}; postDataObject.params.userSettings._id = data.settingsId; postDataObject.params.userSettings.appId = data.appId; @@ -303,7 +303,7 @@ postDataObject.params = {}; postDataObject.params.appId = appId; postDataObject.params.threadId = post._id; - postDataObject.params.userToken = encodeURIComponent(userToken) || null; + postDataObject.params.userToken = userToken || null; //postDataObject.params.parentThreadId = post.parentThreadId || post.threadId; postDataObject.params.additionalInfo = { type: type, @@ -358,7 +358,7 @@ postDeleteObject.params = {}; postDeleteObject.params.threadId = postId; postDeleteObject.params.appId = appId; - postDeleteObject.params.userToken = encodeURIComponent(userToken); + postDeleteObject.params.userToken = userToken; postDeleteObject.params.secureToken = null; postDeleteObject.userToken = null; var successCallback = function (response) { @@ -384,9 +384,9 @@ postDeleteObject.params.commentId = commentId; postDeleteObject.params.appId = appId; postDeleteObject.params.threadId = threadId; - postDeleteObject.params.userToken = encodeURIComponent(userToken) || null; + postDeleteObject.params.userToken = userToken || null; postDeleteObject.params.secureToken = null; - postDeleteObject.userToken = encodeURIComponent(userToken) || null; + postDeleteObject.userToken = userToken || null; var successCallback = function (response) { return deferred.resolve(response); }; @@ -515,7 +515,7 @@ postDataObject.params.appId = _this.socialAppId; postDataObject.params.threadId = _this.parentThreadId; postDataObject.params.userId = _this.userDetails.userId || null; - postDataObject.params.userToken = encodeURIComponent(_this.userDetails.userToken) || null; + postDataObject.params.userToken = _this.userDetails.userToken || null; $http({ method: 'GET', url: SERVER_URL.link,