Browse Source

Added logout functionality.

pull/6/head
jrtechs 5 years ago
parent
commit
81f4a5e5a5
4 changed files with 36 additions and 9 deletions
  1. +3
    -0
      html/header.html
  2. +19
    -1
      html/home.html
  3. +0
    -3
      html/login.html
  4. +14
    -5
      server.js

+ 3
- 0
html/header.html View File

@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="/users">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/videos">Videos</a>
</li>
</ul>
</div>

+ 19
- 1
html/home.html View File

@ -1 +1,19 @@
welcome
<div class="row">
<div class="col-4">
<div class="card">
<div class="card-header">
<h3>Profile</h3>
</div>
<div class="card-body">
<p>Welcome {username}.</p>
<br>
<form action="/logout" method ="post" class="p-2">
<div class="text-center">
<button class="btn btn-lg btn-secondary">LogOut</button>
</div>
<br>
</form>
</div>
</div>
</div>
</div>

+ 0
- 3
html/login.html View File

@ -18,9 +18,6 @@
</div>
<br>
</form>
{if invalidAttempt}
<p>Invalid Login attempt</p>
{/if}
</div>
</div>
</div>

+ 14
- 5
server.js View File

@ -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}!`));

Loading…
Cancel
Save