Skip to content

Commit

Permalink
Added subscription confirmation email
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Mar 12, 2019
1 parent a0bb5f7 commit a38771e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
48 changes: 38 additions & 10 deletions app/brochure/routes/news.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,32 +12,60 @@ news.get("/", loadDone, loadToDo, function(req, res) {
res.render("news"); res.render("news");
}); });



news.get("/archive", loadDone, loadToDo, function(req, res) { news.get("/archive", loadDone, loadToDo, function(req, res) {
res.locals.title = "Blot / News"; res.locals.title = "Blot / News";
res.render("news/archive"); res.render("news/archive");
}); });


news.post('/sign-up', parse, function(req, res){ news.get("/sign-up", function(req ,res){
console.log(req.body);
res.render("news/sign-up"); res.render("news/sign-up");
}); });


news.post("/sign-up", parse, function(req, res) {
var err;

if (!req.body || !req.body.email) {
err = new Error();
err.code = "ENOENT";
}

var confirm = "https://blot.development/news/confirm";

helper.email.SUBSCRIBE_CONFIRMATION(
null,
{ email: req.body.email.trim().toLowerCase(), confirm: confirm },
function(err) {
if (err) {
err = new Error();
err.code = "EINVAL";
}

req.message("/news/sign-up");
}
);
});

function loadToDo(req, res, next) { function loadToDo(req, res, next) {
fs.readFile(__dirname + "/../../../todo.txt", "utf-8", function(err, todo) { fs.readFile(__dirname + "/../../../todo.txt", "utf-8", function(err, todo) {
if (err) return next(err); if (err) return next(err);
res.locals.todo = marked(todo); res.locals.todo = marked(todo);


var html = res.locals.todo; var html = res.locals.todo;
var $ = require('cheerio').load(html); var $ = require("cheerio").load(html);


$('ul').each(function(){ $("ul").each(function() {
var ul = $(this).html(); var ul = $(this).html();
var p = $(this).prev().html(); var p = $(this)

.prev()
$(this).prev().remove(); .html();
$(this).replaceWith("<details><summary>" + p + "</summary><ul>" + ul + "</ul></details>");
}); $(this)
.prev()
.remove();
$(this).replaceWith(
"<details><summary>" + p + "</summary><ul>" + ul + "</ul></details>"
);
});


res.locals.todo = $.html(); res.locals.todo = $.html();
return next(); return next();
Expand Down
1 change: 1 addition & 0 deletions app/helper/email/index.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var MESSAGES = [
"RESTART", "RESTART",
"REVOKED", "REVOKED",
"SET_PASSWORD", "SET_PASSWORD",
"SUBSCRIBE_CONFIRMATION",
"SYNC_DOWN", "SYNC_DOWN",
"SYNC_EXCEPTION", "SYNC_EXCEPTION",
"UPCOMING_RENEWAL", "UPCOMING_RENEWAL",
Expand Down
3 changes: 3 additions & 0 deletions app/helper/email/user/SUBSCRIBE_CONFIRMATION.txt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
Do you want to subscribe?

[Confirm subscription]({{{confirm}}})

0 comments on commit a38771e

Please sign in to comment.