From a73da0d736a50b7fb10f010b9ae4cc3e551c59e7 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Tue, 16 Jul 2019 18:42:28 -0400 Subject: Add email form --- src/css/styles.css | 4 ++-- src/html/email.html | 38 ++++++++++++++++++++++++++++++++++++++ src/html/index.html | 3 ++- src/index.js | 4 ++++ src/server.js | 11 +++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/html/email.html (limited to 'src') diff --git a/src/css/styles.css b/src/css/styles.css index e9677ed..f0f90d2 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -103,7 +103,7 @@ p { .card img { width: 400px; } - form input[type=text], input[type=password] { + form input[type=text], input[type=password], input[type=email] { max-width: 600px; } form textarea { @@ -176,7 +176,7 @@ form { width: 85%; } -input[type=text], input[type=password] { +input[type=text], input[type=password], input[type=email] { height:1.5em; width: 100%; display: block; diff --git a/src/html/email.html b/src/html/email.html new file mode 100644 index 0000000..dfd9b51 --- /dev/null +++ b/src/html/email.html @@ -0,0 +1,38 @@ + + + + + Mark's Kitchen - Email + + + + + + + + + +
+

Email

+

Sign up to receive Mark's email newsletter

+

Success, thank you!

+
+
+ + + +
+
+
+ + + \ No newline at end of file diff --git a/src/html/index.html b/src/html/index.html index f004784..1d57609 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -31,7 +31,8 @@
diff --git a/src/index.js b/src/index.js index 3a0573e..1214038 100644 --- a/src/index.js +++ b/src/index.js @@ -73,6 +73,10 @@ function setUpModels(){ session: Sequelize.STRING, method: Sequelize.STRING, url: Sequelize.STRING, + }), + "emails": database.define('email', { + address: Sequelize.STRING, + name: Sequelize.STRING }) } models.pictures.belongsTo(models.posts); diff --git a/src/server.js b/src/server.js index eae99e4..9899736 100644 --- a/src/server.js +++ b/src/server.js @@ -84,6 +84,7 @@ function setUpRoutes(models, jwtFunctions, database) { server.get('/index', (req, res) => res.sendFile(__dirname + "/html/index.html")) server.get('/admin', (req, res) => res.sendFile(__dirname + "/html/admin.html")); server.get('/login', (req, res) => res.sendFile(__dirname + "/html/login.html")) + server.get('/email', (req, res) => res.sendFile(__dirname + "/html/email.html")) server.get('/bread', (req, res) => res.sendFile(__dirname + "/html/bread.html")); server.get('/blog', (req, res) => res.sendFile(__dirname + "/html/blog.html")); server.get('/tags', (req, res) => res.sendFile(__dirname + "/html/tags.html")); @@ -175,6 +176,16 @@ function setUpRoutes(models, jwtFunctions, database) { res.redirect('/login'); } }) + server.post('/email', async (req, res, next) => { + const name = req.body.name; + const email = req.body.email; + if (name && email) { + models.emails.create({"name": name, "address": email}) + res.redirect('/email#success'); + } else { + console.debug("Error with email submission") + } + }) server.get('/favicon.ico', (req, res) => res.sendFile(__dirname + "/icon/favicon.ico")) -- cgit v1.2.3