From 20deceae4de9779b3bfafa9c8b8811c403bfbc6e Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Tue, 20 Oct 2020 12:17:57 -0500 Subject: Add me page --- src/server.js | 21 ++++++++++++++++++++- src/static/styles.css | 7 ++++++- src/templates.js | 2 ++ src/templates/expected.html | 2 +- src/templates/goals.html | 2 +- src/templates/ledger-edit.html | 2 +- src/templates/ledger.html | 2 +- src/templates/login.html | 2 +- src/templates/me.html | 27 +++++++++++++++++++++++++++ src/templates/message.html | 5 +++++ src/templates/navigation.html | 1 + src/templates/summary.html | 2 +- 12 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 src/templates/me.html create mode 100644 src/templates/message.html (limited to 'src') diff --git a/src/server.js b/src/server.js index 17d5372..e0214ba 100644 --- a/src/server.js +++ b/src/server.js @@ -23,6 +23,19 @@ function hashWithSalt(password, salt) { return hash.digest("base64"); }; +let messages = {} +function putMessage(message, res){ + message[res.locals.username] = message; +} +function consumeMessage(res){ + if(messages[res.locals.username]){ + let t = messages[res.locals.username] + delete messages[res.locals.username] + return t + } + return undefined +} + function setUpRoutes(models, jwtFunctions, database, templates) { // Authentication routine server.use(async function (req, res, next) { @@ -60,7 +73,13 @@ function setUpRoutes(models, jwtFunctions, database, templates) { server.use('/static', express.static(path.join(__dirname, '/static'))) server.get('/', (req, res) => res.redirect("/ledger")) server.get('/about', (req, res) => { - let body = templates["about"]({}); + let name = res.locals.user.username + let body = templates["about"]({name}); + res.status(200).send(body) + }) + server.get('/me', (req, res) => { + let name = res.locals.user.username + let body = templates["me"]({name, message: consumeMessage(res)}); res.status(200).send(body) }) server.get('/login', (req, res) => { diff --git a/src/static/styles.css b/src/static/styles.css index fb91d3b..984a43d 100644 --- a/src/static/styles.css +++ b/src/static/styles.css @@ -69,13 +69,18 @@ body { .main { flex-grow: 3; max-width: 1000px; + margin: auto; } p, li { max-width: 70ch; } -@media only screen and (max-width: 600px) { +a, a:visited { + color: black; +} + +@media (max-width: 600px) { .newItem td { display:block; } diff --git a/src/templates.js b/src/templates.js index a9e3305..d355a5f 100644 --- a/src/templates.js +++ b/src/templates.js @@ -13,8 +13,10 @@ function loadPartial(name, filepath){ function setUpTemplates(){ loadPartial("navigation", path.join(__dirname, "templates/navigation.html")) + loadPartial("message", path.join(__dirname, "templates/message.html")) let templates = {}; + loadTemplate(templates, "me", path.join(__dirname, 'templates/me.html')) loadTemplate(templates, "about", path.join(__dirname, 'templates/about.html')) loadTemplate(templates, "login", path.join(__dirname, 'templates/login.html')) loadTemplate(templates, "signup", path.join(__dirname, 'templates/sign-up.html')) diff --git a/src/templates/expected.html b/src/templates/expected.html index 9554896..3657151 100644 --- a/src/templates/expected.html +++ b/src/templates/expected.html @@ -9,7 +9,7 @@
-

{{name}}'s Budget

+

Expected

diff --git a/src/templates/goals.html b/src/templates/goals.html index e30aa62..9c106bd 100644 --- a/src/templates/goals.html +++ b/src/templates/goals.html @@ -9,7 +9,7 @@
-

{{name}}'s Budget

+

Goals

diff --git a/src/templates/ledger-edit.html b/src/templates/ledger-edit.html index e939b6d..b5539f1 100644 --- a/src/templates/ledger-edit.html +++ b/src/templates/ledger-edit.html @@ -9,7 +9,7 @@
-

{{name}}'s Budget

+

Ledger - Edit

diff --git a/src/templates/ledger.html b/src/templates/ledger.html index e2b7625..031108e 100644 --- a/src/templates/ledger.html +++ b/src/templates/ledger.html @@ -10,7 +10,7 @@
-

{{name}}'s Budget

+

Ledger

diff --git a/src/templates/login.html b/src/templates/login.html index dcf8f8e..a8cc98c 100644 --- a/src/templates/login.html +++ b/src/templates/login.html @@ -14,7 +14,7 @@ - +
diff --git a/src/templates/me.html b/src/templates/me.html new file mode 100644 index 0000000..77b5ed4 --- /dev/null +++ b/src/templates/me.html @@ -0,0 +1,27 @@ + + + + + About + + + + + + +
+

{{name}}

+ + {{message}} +

Reset Password

+ + + + + + +
+ {{> navigation}} + + + \ No newline at end of file diff --git a/src/templates/message.html b/src/templates/message.html new file mode 100644 index 0000000..9ee9fd8 --- /dev/null +++ b/src/templates/message.html @@ -0,0 +1,5 @@ +{{#if message}} +
+ {{message}} +
+{{/if}} \ No newline at end of file diff --git a/src/templates/navigation.html b/src/templates/navigation.html index c20ccbf..2b7717b 100644 --- a/src/templates/navigation.html +++ b/src/templates/navigation.html @@ -1,4 +1,5 @@