index.js
function sendContent(res, args, action, padId, padURL, resultDb) {
  console.debug("starting sendContent: args ->", action, " / ", padId, " / ", padURL, " / ", resultDb);

  if (action == 'subscribe') {
    var actionMsg = "Subscribing '" + resultDb.email + "' to pad " + padId;
  } else {
    var actionMsg = "Unsubscribing '" + resultDb.email + "' from pad " + padId;
  }
  var msgCause, resultMsg, classResult;

  if (resultDb.foundInDb == true && resultDb.timeDiffGood == true) {
    // Pending data were found un Db and updated -> good
    resultMsg = "Success";
    classResult = "validationGood";
    if (action == 'subscribe') {
      msgCause = "You will receive email when someone changes this pad.";
    } else {
      msgCause = "You won't receive anymore email when someone changes this pad.";
    }
  } else if (resultDb.foundInDb == true) {
    // Pending data were found but older than a day -> fail
    resultMsg = "Too late!";
    classResult = "validationBad";
    msgCause = "You have max 24h to click the link in your confirmation email.";
  } else {
    // Pending data weren't found in Db -> fail
    resultMsg = "Fail";
    classResult = "validationBad";
    msgCause = "We couldn't find any pending " + (action == 'subscribe'?'subscription':'unsubscription') + "<br />in our system with this Id.<br />Maybe you wait more than 24h before validating";
  }

  args.content = fs.readFileSync(__dirname + "/templates/response.ejs", 'utf-8');
  args.content = args.content
    .replace(/\<%action%\>/, actionMsg)
    .replace(/\<%classResult%\>/, classResult)
    .replace(/\<%result%\>/, resultMsg)
    .replace(/\<%explanation%\>/, msgCause)
    .replace(/\<%padUrl%\>/g, padURL);

  res.contentType("text/html; charset=utf-8");
  res.send(args.content); // Send it to the requester*/
}
function sendContent(res, args, action, padId, padURL, resultDb) {
  console.debug("starting sendContent: args ->", action, " / ", padId, " / ", padURL, " / ", resultDb);

  if (action == 'subscribe') {
    var actionMsg = "Subscribing '" + resultDb.email + "' to pad " + padId;
  } else {
    var actionMsg = "Unsubscribing '" + resultDb.email + "' from pad " + padId;
  }
  var msgCause, resultMsg, classResult;

  if (resultDb.foundInDb == true && resultDb.timeDiffGood == true) {
    // Pending data were found un Db and updated -> good
    resultMsg = "Success";
    classResult = "validationGood";
    if (action == 'subscribe') {
      msgCause = "You will receive email when someone changes this pad.";
    } else {
      msgCause = "You won't receive anymore email when someone changes this pad.";
    }
  } else if (resultDb.foundInDb == true) {
    // Pending data were found but older than a day -> fail
    resultMsg = "Too late!";
    classResult = "validationBad";
    msgCause = "You have max 24h to click the link in your confirmation email.";
  } else {
    // Pending data weren't found in Db -> fail
    resultMsg = "Fail";
    classResult = "validationBad";
    msgCause = "We couldn't find any pending " + (action == 'subscribe'?'subscription':'unsubscription') + "<br />in our system with this Id.<br />Maybe you wait more than 24h before validating";
  }

  args.content = fs.readFileSync(__dirname + "/templates/response.ejs", 'utf-8');
  args.content = args.content
    .replace(/\<%action%\>/, actionMsg)
    .replace(/\<%classResult%\>/, classResult)
    .replace(/\<%result%\>/, resultMsg)
    .replace(/\<%explanation%\>/, msgCause)
    .replace(/\<%padUrl%\>/g, padURL);

  res.contentType("text/html; charset=utf-8");
  res.send(args.content); // Send it to the requester*/
}
function sendContent ( res , args , action , padId , padURL , resultDb ) { console . debug ( "starting sendContent: args ->" , action , " / " , padId , " / " , padURL , " / " , resultDb ) ; if ( action == 'subscribe' ) { var actionMsg = "Subscribing '" + resultDb . email + "' to pad " + padId ; } else { var actionMsg = "Unsubscribing '" + resultDb . email + "' from pad " + padId ; } var msgCause , resultMsg , classResult ; if ( resultDb . foundInDb == true && resultDb . timeDiffGood == true ) { // Pending data were found un Db and updated -> good resultMsg = "Success" ; classResult = "validationGood" ; if ( action == 'subscribe' ) { msgCause = "You will receive email when someone changes this pad." ; } else { msgCause = "You won't receive anymore email when someone changes this pad." ; } } else if ( resultDb . foundInDb == true ) { // Pending data were found but older than a day -> fail resultMsg = "Too late!" ; classResult = "validationBad" ; msgCause = "You have max 24h to click the link in your confirmation email." ; } else { // Pending data weren't found in Db -> fail resultMsg = "Fail" ; classResult = "validationBad" ; msgCause = "We couldn't find any pending " + ( action == 'subscribe' ? 'subscription' : 'unsubscription' ) + "<br />in our system with this Id.<br />Maybe you wait more than 24h before validating" ; } args . content = fs . readFileSync ( __dirname + "/templates/response.ejs" , 'utf-8' ) ; args . content = args . content . replace ( / \<%action%\> / , actionMsg ) . replace ( / \<%classResult%\> / , classResult ) . replace ( / \<%result%\> / , resultMsg ) . replace ( / \<%explanation%\> / , msgCause ) . replace ( / \<%padUrl%\> / g , padURL ) ; res . contentType ( "text/html; charset=utf-8" ) ; res . send ( args . content ) ; // Send it to the requester*/ }
Create html output with the status of the process
Create html output with the status of the process