Skip to content

Commit

Permalink
merged branch urlParams with templateParams and redirectParmas as opt…
Browse files Browse the repository at this point in the history
…ional parameters to allow personalized tempalates and redirects
  • Loading branch information
silkroadnomad committed Jan 14, 2019
2 parents 4aaedfd + c1a420f commit 3ea960a
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 48 deletions.
176 changes: 139 additions & 37 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 36 additions & 3 deletions imports/modules/server/dapps/get_doi-mail-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getOptInKey from '../dns/get_opt-in-key.js';
import verifySignature from '../doichain/verify_signature.js';
import { getHttpGET } from '../../../../server/api/http.js';
import { DOI_MAIL_FETCH_URL } from '../../../startup/server/email-configuration.js';
import { logSend } from "../../../startup/server/log-configuration";
import { logSend, testLogging } from "../../../startup/server/log-configuration";
import { Accounts } from 'meteor/accounts-base'

const GetDoiMailDataSchema = new SimpleSchema({
Expand Down Expand Up @@ -97,12 +97,45 @@ const getDoiMailData = (data) => {
try{
let owner = Accounts.users.findOne({_id: optIn.ownerId});
let mailTemplate = owner.profile.mailTemplate;
let redirParamString=null;
let templParamString=null;
try{
let optinData = JSON.parse(optIn.data);
let redirParam = optinData.redirectParam ? optinData.redirectParam:null;
let templParam = optinData.templateParam ? optinData.templateParam:null;

//parse template params
let str = [];
for (let tParam in templParam){
if (templParam.hasOwnProperty(tParam)) {
str.push(encodeURIComponent(tParam) + "=" + encodeURIComponent(templParam[tParam]));
logSend("tmplParam added:",tParam+"="+templParam[tParam]);
}
templParamString=str.join("&");
}
//parse redirect params
str = [];
for (let rParam in redirParam){
if (redirParam.hasOwnProperty(rParam)) {
str.push(encodeURIComponent(rParam) + "=" + encodeURIComponent(redirParam[rParam]));
logSend("redirParam added:",rParam+"="+redirParam[rParam]);
}
redirParamString=str.join("&");
}
}
catch(e){
logSend("Couldn't retrieve parameters")
}
userProfileSchema.validate(mailTemplate);

returnData["redirect"] = mailTemplate["redirect"] || defaultReturnData["redirect"];
//Appends parameter to redirect-url
let tmpRedirect = mailTemplate["redirect"] ? (redirParamString === null ? mailTemplate["redirect"] : (mailTemplate["redirect"].indexOf("?")==-1 ? mailTemplate["redirect"]+"?"+redirParamString : mailTemplate["redirect"]+"&"+redirParamString)):null;
let tmpTemplate = mailTemplate["templateURL"] ? (templParamString === null ? mailTemplate["templateURL"] : (mailTemplate["templateURL"].indexOf("?")==-1 ? mailTemplate["templateURL"]+"?"+templParamString : mailTemplate["templateURL"]+"&"+templParamString)):null;

returnData["redirect"] = tmpRedirect || defaultReturnData["redirect"];
returnData["subject"] = mailTemplate["subject"] || defaultReturnData["subject"];
returnData["returnPath"] = mailTemplate["returnPath"] || defaultReturnData["returnPath"];
returnData["content"] = mailTemplate["templateURL"] ? (getHttpGET(mailTemplate["templateURL"], "").content || defaultReturnData["content"]) : defaultReturnData["content"];
returnData["content"] = tmpTemplate ? (getHttpGET(tmpTemplate, "").content || defaultReturnData["content"]) : defaultReturnData["content"];

}
catch(error) {
Expand Down
6 changes: 3 additions & 3 deletions private/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"timestamp": "09-01-2019 21:42",
"version": "",
"commit": "93b3bfe3e9067fd9a18dca38b9e8a0c6e6016bc6"
"timestamp": "14-01-2019 18:22",
"version": "v0.0.7.9",
"commit": "4aaedfd6ce4e22e32f1f9cb2311eb3744b721522"
}
16 changes: 14 additions & 2 deletions server/api/http.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { Meteor } from 'meteor/meteor';
import { HTTP } from 'meteor/http'

//Wrapping the HTTP.get method is not neccessary, it calls the function syncronous if there is no callback function anyway.
//wrapping instead caused problems when calling php-files
//TODO: remove unneccessary wrapping


//Don't use this!
//export function getHttpGETerror(url, query) {
// const syncFunc = Meteor.wrapAsync(_get);
// return syncFunc(url, query);
//}


//This is only a temporary fix
export function getHttpGET(url, query) {
const syncFunc = Meteor.wrapAsync(_get);
return syncFunc(url, query);
return HTTP.get(url, {query: query});
}

export function getHttpGETdata(url, data) {
Expand Down
2 changes: 1 addition & 1 deletion server/api/rest/imports/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Api.addRoute(DOI_FETCH_ROUTE, {authRequired: false}, {
try {
logSend('rest api - DOI_FETCH_ROUTE called by bob to request email template',JSON.stringify(params));
const data = getDoiMailData(params);
logSend('got doi-mail-data (including templalte) returning to bob',{subject:data.subject, recipient:data.recipient});
logSend('got doi-mail-data (including template) returning to bob',{subject:data.subject, recipient:data.recipient, redirect:data.redirect});
return {status: 'success', data};
} catch(error) {
logError('error while getting DoiMailData',error);
Expand Down
13 changes: 13 additions & 0 deletions server/test/1-basic-doi-test.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ if(Meteor.isAppTest) {
logBlockchain("removing OptIns,Recipients,Senders");
deleteOptInsFromAliceAndBob();
deleteAllEmailsFromPop3("mail", 110, recipient_pop3username, recipient_pop3password, true);
const adLog = login(dappUrlAlice, dAppLogin, false);
updateUser(dappUrlAlice, adLog, adLog.userId, {"subject":"Testsubject"});
});

it('should test if basic Doichain workflow is working with optional data', function (done) {
Expand Down Expand Up @@ -138,11 +140,22 @@ if(Meteor.isAppTest) {
done();
});

it('should use URL params', function (done) {
const recipient_mail = "bob@ci-doichain.org"; //please use this as standard to not confuse people!
const sender_mail = "alice-param@ci-doichain.org";
const adLog = login(dappUrlAlice, dAppLogin, false);
updateUser(dappUrlAlice, adLog, adLog.userId, {"subject": "paramTest", "redirect": "https://www.doichain.org", "templateURL": templateUrlA},true);
requestConfirmVerifyBasicDoi(node_url_alice, rpcAuthAlice, dappUrlAlice, adLog, dappUrlBob, recipient_mail, sender_mail, {'redirectParam': {'p':1},'templateParam':{'token':'abcdfgh'}}, "bob@ci-doichain.org", "bob", true);
updateUser(dappUrlAlice, adLog, adLog.userId,{"subject":"paramTest"},false);
done();
});

it('should redirect if confirmation-link is clicked again',function(){
for (let index = 0; index < 3; index++) {
const recipient_mail = "bob@ci-doichain.org"; //please use this as standard to not confuse people!
const sender_mail = "alice_"+index+"@ci-doichain.org";
const dataLoginAlice = login(dappUrlAlice, dAppLogin, false); //log into dApp
updateUser(dappUrlAlice, dataLoginAlice, dataLoginAlice.userId,{"subject":"multiclickTest"},true);
let returnedData = requestConfirmVerifyBasicDoi(node_url_alice, rpcAuthAlice, dappUrlAlice, dataLoginAlice, dappUrlBob, recipient_mail, sender_mail, {'city': 'Ekaterinburg'}, "bob@ci-doichain.org", "bob", true);
chai.assert.equal(true,confirmLink(returnedData.confirmLink));
}
Expand Down
Loading

0 comments on commit 3ea960a

Please sign in to comment.