From 4e906c71adc7a4eb857a78d07e0114bb9433fe75 Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Thu, 28 Sep 2017 21:23:15 -0500 Subject: [PATCH] code refactored --- controllers/api_routes.js | 197 ++++++++++++++++----------- controllers/html_routes.js | 270 +++++++++++++++++++++---------------- db/schema.sql | 16 +-- db/seeds.sql | 2 +- models/writers.js | 2 +- views/compose.hbs | 4 +- views/edit.hbs | 4 +- views/layouts/main.hbs | 12 +- views/meet-mai-team.hbs | 12 +- views/meet-mai.hbs | 2 +- views/profile.hbs | 4 +- views/upload-photos.hbs | 2 +- views/writers.hbs | 4 +- 13 files changed, 300 insertions(+), 231 deletions(-) diff --git a/controllers/api_routes.js b/controllers/api_routes.js index 1da23ed..e95fb88 100644 --- a/controllers/api_routes.js +++ b/controllers/api_routes.js @@ -33,13 +33,20 @@ const Photo = models.Photo; const Reader = models.Reader; // Default profile photos -const default_profiles = [ +const defaultPhotos = [ "https://goo.gl/7g6AwU", "https://goo.gl/dFcx11", "https://goo.gl/myorst", "https://goo.gl/cnQGa7" ]; +// Source: https://stackoverflow.com/questions/7905929/how-to-test-valid-uuid-guid +function isValidCookie(uuid) { + const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + + return (uuid && regex.test(uuid)); +} + /**************************************************************************** @@ -51,27 +58,29 @@ const default_profiles = [ *****************************************************************************/ router.post("/signup", (req, res) => { function callback(result) { + // Cookie will expire in 1 week const options = { "expires" : new Date(Date.now() + 604800000), "httpOnly": true // "secure" : true }; - res.cookie("mai-id", result.id, options); - res.cookie("mai-fullname", result.fullname, options); + res.cookie("maiId", result.id, options); + res.cookie("maiFullname", result.fullname, options); res.redirect("/"); } // Salt and hash the user's password bcrypt.hash(req.body.password, saltRounds, (error, hash) => { Writer.create({ - "fullname" : req.body.fullname, - "email" : req.body.email, - "username" : req.body.username, - "hash" : hash, - "profile_url": default_profiles[Math.floor(default_profiles.length * Math.random())] + "fullname" : req.body.fullname, + "email" : req.body.email, + "username" : req.body.username, + "hash" : hash, + "url_photo": defaultPhotos[Math.floor(defaultPhotos.length * Math.random())] }).then(callback); + }); }); @@ -93,40 +102,43 @@ router.post("/login", (req, res) => { // "secure" : true }; - // Create cookies (expire in a week) - res.cookie("mai-id", results[0].id, options); - res.cookie("mai-fullname", results[0].fullname, options); + res.cookie("maiId", results[0].id, options); + res.cookie("maiFullname", results[0].fullname, options); } - } - res.redirect("/"); + res.redirect("/"); - }); + // TODO: If the username or password does not match, display an error message + } else { + res.redirect("/"); + } + }); }); }); router.patch("/update-profile_:id", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + // Display homepage if the user is not logged in or does not have a valid cookie + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); // Only the user can edit their profile - } else if (req.cookies["mai-id"] !== req.params.id) { + } else if (req.params.id !== maiId) { res.redirect("/"); } else { function callback(result) { - - // TODO: Update cookie for fullname - res.cookie("mai-fullname", req.body.fullname); - - // TODO: Pass values + // Update the fullname cookie + res.cookie("maiFullname", req.body.fullname); res.redirect("/settings"); } @@ -145,21 +157,23 @@ router.patch("/update-profile_:id", (req, res) => { router.patch("/update-password_:id", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); // Only the user can edit their password - } else if (req.cookies["mai-id"] !== req.params.id) { + } else if (req.params.id !== maiId) { res.redirect("/"); } else { function callback(result) { - // TODO: Pass values res.redirect("/settings"); } @@ -174,34 +188,40 @@ router.patch("/update-password_:id", (req, res) => { if (isMatch) { // Salt and hash the new password bcrypt.hash(req.body.password_new, saltRounds, (error, hash) => { - Writer.update({hash}, {"where": {"id": req.params.id}}); + Writer.update({hash}, { + "where": {"id": req.params.id} + }); }); } }); }).then(callback); + } }); router.delete("/delete-account_:id", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); // Only the user can delete their stories - } else if (req.cookies["mai-id"] !== req.params.id) { + } else if (req.params.id !== maiId) { res.redirect("/"); } else { function callback(results) { - res.clearCookie("mai-id"); - res.clearCookie("mai-fullname"); + res.clearCookie("maiId"); + res.clearCookie("maiFullname"); res.redirect("/"); } @@ -222,6 +242,9 @@ router.delete("/delete-account_:id", (req, res) => { ***************************************************************************** *****************************************************************************/ +// TODO: Upload the photos to Amazon S3 +// TODO: Use Google Vision +// TODO: Redirect the user to create-story page router.post("/upload-photos", upload.single("file"), (req, res, next) => { if (!req.file.mimetype.startsWith("image/")) { return res.status(422).json({ @@ -246,44 +269,58 @@ router.post("/upload-photos", upload.single("file"), (req, res, next) => { router.post("/create-story", (req, res) => { - function callback(results) { - // TODO later: If storing was successful, call Google Vision next - - // Redirect to story page - res.redirect("/story_${results[0].dataValues.story_id}"); - } + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; - Story.create({ - "title" : req.body.title, - "writer_id": req.cookies["mai-id"] - - }).then(result => { - const photos = []; + if (!isValidCookie(maiId)) { + res.render("index", { + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] + }); - for (let i = 0; i < req.body.urls.length; i++) { - photos.push({ - "url" : req.body.urls[i], - "caption" : req.body.captions[i], - "story_id": result.dataValues.id - }); + } else { + function callback(results) { + res.redirect(`/story_${results[0].dataValues.story_id}`); } - Photo.bulkCreate(photos).then(callback); - }); + Story.create({ + "title" : req.body.title, + "writer_id": maiId + + }).then(result => { + const photos = []; + + for (let i = 0; i < req.body.urls.length; i++) { + photos.push({ + "url" : req.body.urls[i], + "caption" : req.body.captions[i], + "story_id": result.dataValues.id + }); + } + + Photo.bulkCreate(photos).then(callback); + }); + + } }); router.patch("/edit-story_:maiId&:storyId", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); // Only the user can edit their stories - } else if (req.cookies["mai-id"] !== req.params.maiId) { + } else if (req.params.maiId !== maiId) { res.redirect("/"); } else { @@ -298,13 +335,10 @@ router.patch("/edit-story_:maiId&:storyId", (req, res) => { }, { "where": {"id": req.params.storyId} - // Update the captions (TODO: test and fix this) + // Update the captions }).then(result => { function updateCaption(caption, i) { - return Photo.update({ - "caption": caption - - }, { + return Photo.update({caption}, { "where": {"id": req.body.ids[i]} }); @@ -321,16 +355,19 @@ router.patch("/edit-story_:maiId&:storyId", (req, res) => { router.delete("/delete-story_:maiId&:storyId", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); // Only the user can delete their stories - } else if (req.cookies["mai-id"] !== req.params.maiId) { + } else if (req.params.maiId !== maiId) { res.redirect("/"); } else { @@ -347,8 +384,8 @@ router.delete("/delete-story_:maiId&:storyId", (req, res) => { }); +// TODO: Change to POST router.get("/vision", (req, res) => { - // Source: https://github.com/comoc/node-cloud-vision-api const request = new vision.Request({ "image": new vision.Image({ "url": "http://www.ox.ac.uk/sites/files/oxford/styles/ow_medium_feature/public/field/field_image_main/friends_main.jpg?itok=Wmh9VQWO" @@ -363,7 +400,7 @@ router.get("/vision", (req, res) => { res.send(results.responses); }, error => { - console.log("error: " + error); + console.log(`error: ${error}`); }); }); diff --git a/controllers/html_routes.js b/controllers/html_routes.js index aa99821..79b25aa 100644 --- a/controllers/html_routes.js +++ b/controllers/html_routes.js @@ -20,32 +20,39 @@ const Photo = models.Photo; const Reader = models.Reader; // Mai team -const mai_team = [ +const maiTeam = [ { "fullname" : "John Absher", - "profile_url" : "assets/images/john_absher.jpg", - "linkedin_url": "https://www.linkedin.com/in/johnabsher/", + "url_photo" : "assets/images/john_absher.jpg", + "url_linkedin": "https://www.linkedin.com/in/johnabsher/", "biography" : "Hand-delivered a bottle of Salt Lick BBQ sauce to the king of Norway." }, { "fullname" : "David Gutierrez", - "profile_url" : "assets/images/david_gutierrez.jpg", - "linkedin_url": "https://www.linkedin.com/in/david-gutierrez-979a4a148/", + "url_photo" : "assets/images/david_gutierrez.jpg", + "url_linkedin": "https://www.linkedin.com/in/david-gutierrez-979a4a148/", "biography" : "Once while sailing around the world, he discovered a short cut." }, { "fullname" : "Jason Joachim", - "profile_url" : "assets/images/jason_joachim.jpg", - "linkedin_url": "https://www.linkedin.com/in/jasonjoachim/", + "url_photo" : "assets/images/jason_joachim.jpg", + "url_linkedin": "https://www.linkedin.com/in/jasonjoachim/", "biography" : "Heavy metal and experimental musician, now rocking web applications." }, { "fullname" : "Isaac Lee", - "profile_url" : "assets/images/isaac_lee.jpg", - "linkedin_url": "https://www.linkedin.com/in/ijlee2/", - "biography" : "Amateur boulderer and public speaker. Feed him coffee and music." + "url_photo" : "assets/images/isaac_lee.jpg", + "url_linkedin": "https://www.linkedin.com/in/ijlee2/", + "biography" : "Amateur boulderer and public speaker. Feed him music and coffee." } -] +]; + +// Source: https://stackoverflow.com/questions/7905929/how-to-test-valid-uuid-guid +function isValidCookie(uuid) { + const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + + return (uuid && regex.test(uuid)); +} @@ -57,16 +64,19 @@ const mai_team = [ ***************************************************************************** *****************************************************************************/ router.get("/", (req, res) => { - // Display the home page if the user is not logged in - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + // Display homepage if the user is not logged in or does not have a valid cookie + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); - // Display their profile page if logged in + // Display the profile page if the user is logged in } else { function callback(results) { const stories = []; @@ -82,28 +92,28 @@ router.get("/", (req, res) => { // TODO: Calculate the number of stories, writers, and readers based on queries const writer = { "fullname" : results[0].dataValues.fullname, - "profile_url" : results[0].dataValues.profile_url, - "numNewStories": Math.floor(3 * Math.random()) + 1, + "url_photo" : results[0].dataValues.url_photo, + "numNewStories": Math.floor(5 * Math.random()) + 1, "numStories" : 6, - "numWriters" : Math.floor(100 * Math.random()) + 1, - "numReaders" : Math.floor(100 * Math.random()) + 1, + "numWriters" : Math.floor(90 * Math.random()) + 10, + "numReaders" : Math.floor(90 * Math.random()) + 10, stories }; res.render("profile", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"], - "editable" : true, + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"], + "editable" : true, writer, }); } // Do a nested join Writer.findAll({ - "where" : {"id": req.cookies["mai-id"]}, - "attributes": ["fullname", "profile_url"], + "where" : {"id": maiId}, + "attributes": ["fullname", "url_photo"], "include" : [ { "model" : Story, @@ -121,12 +131,14 @@ router.get("/", (req, res) => { }); -router.get("/logout", function(req, res){ +router.get("/logout", (req, res) => { const cookie = req.cookies; - for (let prop in cookie) { - if (cookie.hasOwnProperty(prop)) { - res.cookie(prop, "", {"expires": new Date(0)}); + for (let value in cookie) { + // Ignore prototype (inherited properties) + if (cookie.hasOwnProperty(value)) { + // Empty the value and change the expiration date to now + res.cookie(value, "", {"expires": new Date(0)}); } } @@ -135,12 +147,15 @@ router.get("/logout", function(req, res){ router.get("/profile_:id", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); } else { @@ -155,29 +170,30 @@ router.get("/profile_:id", (req, res) => { }); } + // TODO: Calculate the number of stories, writers, and readers based on queries const writer = { "fullname" : results[0].dataValues.fullname, - "profile_url" : results[0].dataValues.profile_url, - "numNewStories": Math.floor(3 * Math.random()) + 1, + "url_photo" : results[0].dataValues.url_photo, + "numNewStories": Math.floor(5 * Math.random()) + 1, "numStories" : 6, - "numWriters" : Math.floor(100 * Math.random()) + 1, - "numReaders" : Math.floor(100 * Math.random()) + 1, + "numWriters" : Math.floor(90 * Math.random()) + 10, + "numReaders" : Math.floor(90 * Math.random()) + 10, stories }; res.render("profile", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"], - "editable" : (req.params.id === req.cookies["mai-id"]), + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["profile"], + "editable" : (req.params.id === maiId), writer }); } Writer.findAll({ "where" : {"id": req.params.id}, - "attributes": ["fullname", "profile_url"], + "attributes": ["fullname", "url_photo"], "include" : [ { "model" : Story, @@ -197,21 +213,24 @@ router.get("/profile_:id", (req, res) => { router.get("/upload-photos", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); } else { // Must include dropzone before calling upload-photos.js res.render("upload-photos", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["dropzone/dropzone", "style"], - "custom-javascript": ["dropzone/dropzone", "upload-photos"] + maiId, + maiFullname, + "customCSS" : ["dropzone/dropzone", "style"], + "customJavascript": ["dropzone/dropzone", "upload-photos"] }); } @@ -219,12 +238,15 @@ router.get("/upload-photos", (req, res) => { router.get("/create-story", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); } else { @@ -234,12 +256,11 @@ router.get("/create-story", (req, res) => { ]; res.render("compose", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["compose"], + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["compose"], photos - }); } @@ -247,12 +268,15 @@ router.get("/create-story", (req, res) => { router.get("/story_:id", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); } else { @@ -272,11 +296,11 @@ router.get("/story_:id", (req, res) => { } res.render("story", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["story"], - "title" : results[0].dataValues.title, + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["story"], + "title" : results[0].dataValues.title, writer, photos }); @@ -302,16 +326,19 @@ router.get("/story_:id", (req, res) => { router.get("/edit-story_:maiId&:storyId", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); // Only the user can edit their stories - } else if (req.cookies["mai-id"] !== req.params.maiId) { + } else if (req.params.maiId !== maiId) { res.redirect("/"); } else { @@ -333,10 +360,10 @@ router.get("/edit-story_:maiId&:storyId", (req, res) => { }; res.render("edit", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["edit"], + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["edit"], story }); } @@ -351,12 +378,15 @@ router.get("/edit-story_:maiId&:storyId", (req, res) => { router.get("/writers", (req, res) => { - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); } else { @@ -365,17 +395,17 @@ router.get("/writers", (req, res) => { for (let i = 0; i < results.length; i++) { writers.push({ - "id" : results[i].id, - "fullname" : results[i].dataValues.fullname, - "profile_url": results[i].dataValues.profile_url + "id" : results[i].id, + "fullname" : results[i].dataValues.fullname, + "url_photo": results[i].dataValues.url_photo }); } res.render("writers", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["writers"], + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["writers"], writers }); } @@ -386,13 +416,15 @@ router.get("/writers", (req, res) => { router.get("/settings", (req, res) => { - // Check that the user is logged in - if (!req.cookies["mai-id"]) { + const maiId = req.cookies["maiId"]; + const maiFullname = req.cookies["maiFullname"]; + + if (!isValidCookie(maiId)) { res.render("index", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["index"] + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["index"] }); } else { @@ -405,16 +437,16 @@ router.get("/settings", (req, res) => { }; res.render("settings", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["settings"], + maiId, + maiFullname, + "customCSS" : ["style"], + "customJavascript": ["settings"], writer }); } Writer.findAll({ - "where": {"id": req.cookies["mai-id"]} + "where": {"id": maiId} }).then(callback); } @@ -423,21 +455,21 @@ router.get("/settings", (req, res) => { router.get("/meet-mai", (req, res) => { res.render("meet-mai", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["meet-mai"] + "maiId" : req.cookies["maiId"], + "maiFullname" : req.cookies["maiFullname"], + "customCSS" : ["style"], + "customJavascript": ["meet-mai"] }); }); router.get("/meet-mai-team", (req, res) => { res.render("meet-mai-team", { - "mai-id" : req.cookies["mai-id"], - "mai-fullname" : req.cookies["mai-fullname"], - "custom-css" : ["style"], - "custom-javascript": ["meet-mai-team"], - mai_team + "maiId" : req.cookies["maiId"], + "maiFullname" : req.cookies["maiFullname"], + "customCSS" : ["style"], + "customJavascript": ["meet-mai-team"], + maiTeam }); }); diff --git a/db/schema.sql b/db/schema.sql index dc1cde7..0013889 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -4,14 +4,14 @@ CREATE DATABASE mai_db; USE mai_db; CREATE TABLE Writers ( - id INT NOT NULL AUTO_INCREMENT, - fullname VARCHAR(100) NOT NULL, - email VARCHAR(100) NOT NULL UNIQUE, - username VARCHAR(32) NOT NULL UNIQUE, - hash VARCHAR(60) NOT NULL, - - profile_url VARCHAR(256), - flagged BOOLEAN DEFAULT false, + id INT NOT NULL AUTO_INCREMENT, + fullname VARCHAR(100) NOT NULL, + email VARCHAR(100) NOT NULL UNIQUE, + username VARCHAR(32) NOT NULL UNIQUE, + hash VARCHAR(60) NOT NULL, + + url_photo VARCHAR(256), + flagged BOOLEAN DEFAULT false, PRIMARY KEY (id) ); diff --git a/db/seeds.sql b/db/seeds.sql index 0b2e1d0..c42fcc5 100644 --- a/db/seeds.sql +++ b/db/seeds.sql @@ -2,7 +2,7 @@ USE ocbusqsbzymg3amh; -INSERT INTO Writers (id, fullname, email, username, hash, profile_url, flagged, created_at, updated_at) VALUES +INSERT INTO Writers (id, fullname, email, username, hash, url_photo, flagged, created_at, updated_at) VALUES ("2c43aa1d-e8bf-44d1-bb10-cc28ccec0964", "John Absher" , "john.absher@example.com" , "john" , "$2a$12$5ZWQzoBvw7yP9HwPH4Dgu.MILNr6kn.U0Syp1QC6ksV.Qh5QW3EKi", "assets/images/john_absher.jpg" , false, "2017-09-25 04:15:06", "2017-09-25 04:15:06"), ("7592aa72-3832-4b2d-9b8e-658dc21b277d", "David Gutierrez", "david.gutierrez@example.com", "david", "$2a$12$5ZWQzoBvw7yP9HwPH4Dgu.MILNr6kn.U0Syp1QC6ksV.Qh5QW3EKi", "assets/images/david_gutierrez.jpg", false, "2017-09-25 15:05:57", "2017-09-25 15:05:57"), ("a5211e7d-8382-4221-b77a-824b051e2370", "Jason Joachim" , "jason.joachim@example.com" , "jason", "$2a$12$5ZWQzoBvw7yP9HwPH4Dgu.MILNr6kn.U0Syp1QC6ksV.Qh5QW3EKi", "assets/images/jason_joachim.jpg" , false, "2017-09-25 10:28:24", "2017-09-25 10:28:24"), diff --git a/models/writers.js b/models/writers.js index c1e3974..6129576 100644 --- a/models/writers.js +++ b/models/writers.js @@ -59,7 +59,7 @@ module.exports = function(sequelize, DataTypes) { "allowNull": false, }, - "profile_url": { + "url_photo": { "type" : DataTypes.STRING, "validate" : { "isURL" : { diff --git a/views/compose.hbs b/views/compose.hbs index a16a83b..cb96206 100644 --- a/views/compose.hbs +++ b/views/compose.hbs @@ -6,7 +6,7 @@ -
+
@@ -30,7 +30,7 @@
- +
diff --git a/views/edit.hbs b/views/edit.hbs index 7f21cab..f9a56c5 100644 --- a/views/edit.hbs +++ b/views/edit.hbs @@ -6,7 +6,7 @@
- +
@@ -45,7 +45,7 @@
-
+
diff --git a/views/layouts/main.hbs b/views/layouts/main.hbs index 750b5c4..0f5db75 100644 --- a/views/layouts/main.hbs +++ b/views/layouts/main.hbs @@ -19,7 +19,7 @@ - {{#each custom-css}} + {{#each customCSS}} {{/each}} @@ -28,7 +28,7 @@ - {{#if mai-id}} + {{#if maiId}}