Merge pull request #673 from Pythagora-io/example-project

improve example project
This commit is contained in:
LeonOstrez
2024-02-21 14:16:57 -08:00
committed by GitHub
5 changed files with 19 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import os
from typing import TYPE_CHECKING, Optional
from uuid import uuid4
from utils.style import color_green_bold
from logger.logger import logger
@@ -51,6 +52,7 @@ def apply_project_template(
{
"project_name": project_name,
"project_description": project_description,
"random_secret": uuid4().hex,
},
)

View File

@@ -0,0 +1,8 @@
# Port to listen on (example: 3000)
PORT=3000
# MongoDB database URL (example: mongodb://localhost/dbname)
DATABASE_URL=mongodb://localhost/myDb # INPUT_REQUIRED {insert your MongoDB url here}
# Session secret string (must be unique to your server)
SESSION_SECRET={{ random_secret }}

View File

@@ -36,7 +36,7 @@ mongoose
process.exit(1);
});
// Session configuration with connect-mongo
// Session configuration with connect-mongo
app.use(
session({
secret: process.env.SESSION_SECRET,
@@ -54,13 +54,15 @@ app.on("error", (error) => {
// Logging session creation and destruction
app.use((req, res, next) => {
const sess = req.session;
// Make session available to all views
res.locals.session = sess;
if (!sess.views) {
sess.views = 1;
console.log("Session created at: ", new Date().toISOString());
} else {
sess.views++;
console.log(
`Session accessed again at: ${new Date().toISOString()}, Views: ${sess.views}`,
`Session accessed again at: ${new Date().toISOString()}, Views: ${sess.views}, User ID: ${sess.userId || '(unauthenticated)'}`,
);
}
next();

View File

@@ -1,6 +1,6 @@
<head>
<meta charset="UTF-8">
<title>A3 Time Tracker</title>
<title>{{ project_name }}</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link rel="stylesheet" href="/css/style.css">
</head>

View File

@@ -9,9 +9,12 @@
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<% if (session && session.userId) { %>
<a class="nav-link" href="/auth/logout">Logout</a>
<% } else { %>
<a class="nav-link" href="/auth/login">Login</a>
<% } %>
</li>
</ul>
</div>
</nav>