From 81f4a5e5a5ce983f2ddffd7ad0a235fa39d8a4ce Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 2 Feb 2019 16:29:56 -0500 Subject: [PATCH] Added logout functionality. --- html/header.html | 3 +++ html/home.html | 20 +++++++++++++++++++- html/login.html | 3 --- server.js | 19 ++++++++++++++----- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/html/header.html b/html/header.html index 38e5262..fc3e180 100644 --- a/html/header.html +++ b/html/header.html @@ -40,6 +40,9 @@ + diff --git a/html/home.html b/html/home.html index b6cbc2d..f135e93 100644 --- a/html/home.html +++ b/html/home.html @@ -1 +1,19 @@ -welcome \ No newline at end of file +
+
+
+
+

Profile

+
+
+

Welcome {username}.

+
+
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/html/login.html b/html/login.html index bc1dca4..a67984b 100644 --- a/html/login.html +++ b/html/login.html @@ -18,9 +18,6 @@
- {if invalidAttempt} -

Invalid Login attempt

- {/if} \ No newline at end of file diff --git a/server.js b/server.js index 5b29d39..28f02ab 100644 --- a/server.js +++ b/server.js @@ -41,7 +41,6 @@ function renderHTML(request, result, templateFile, templateDependencyFunction) var templateContext = Object(); var prom = []; - prom.push(fileIO.getFile("./html/mainTemplate.html")); prom.push(fetchInTemplate(templateContext, "header", "./html/header.html")); prom.push(fetchInTemplate(templateContext, "footer", "./html/footer.html")); @@ -49,8 +48,7 @@ function renderHTML(request, result, templateFile, templateDependencyFunction) { templateContext.loggedIn = true; if(templateDependencyFunction !== null) - prom.push(templateDependencyFunction(templateContext)); - + prom.push(templateDependencyFunction(templateContext, request)); prom.push(fetchInTemplate(templateContext, "main","./html/" + templateFile)); } else @@ -65,12 +63,17 @@ function renderHTML(request, result, templateFile, templateDependencyFunction) }); } -function getUserInformation(templateContext) +function getUserInformation(templateContext, request) { templateContext.users = config.users; } -app.get('/', (req, res) => renderHTML(req, res, "home.html", null)); +function getHomePageInformation(templateContext, request) +{ + templateContext.username = request.session.username; +} + +app.get('/', (req, res) => renderHTML(req, res, "home.html", getHomePageInformation)); app.get('/users', (req, res) => renderHTML(req, res, "users.html", getUserInformation)); app.use(express.static('css')); @@ -190,5 +193,11 @@ app.post('/removeuser', function(request, result) } }); +app.post('/logout', function(request, result) +{ + request.session.login = false; + result.redirect('/'); +}); + app.listen(config.port, () => console.log(`App listening on port ${config.port}!`)); \ No newline at end of file