Add session maxAge
This commit is contained in:
+3
-1
@@ -74,7 +74,7 @@ export var server: Server;
|
||||
|
||||
import moment from 'moment-timezone'
|
||||
import { Server } from "http";
|
||||
import session from "express-session";
|
||||
import session, { MemoryStore, Store } from "express-session";
|
||||
|
||||
var accessLogStream = fs.createWriteStream('./pvfiles/interactions.log', { flags: 'a' });
|
||||
|
||||
@@ -93,10 +93,12 @@ try {
|
||||
app.use(
|
||||
session({
|
||||
name: "session",
|
||||
store: new MemoryStore(),
|
||||
secret: process.env.session_secret,
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
cookie: {
|
||||
maxAge: Date.now() + (30 * 24 * 3600 * 1000),
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: dev
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ export async function Main(app: Express) {
|
||||
username: user.username
|
||||
};
|
||||
|
||||
res.redirect("/");
|
||||
res.redirect(req.query?.next?.toString() ?? "/");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
+2
-2
@@ -185,7 +185,7 @@ export async function Main(app: Express) {
|
||||
<form action="/posts/new" method="GET">
|
||||
<button class="tonly">New Post</button>
|
||||
</form>
|
||||
` : `<p><a href="/login">Log in</a> to create posts.</p>`}
|
||||
` : `<p><a href="/login?next=/posts/new">Log in</a> to create posts.</p>`}
|
||||
<hr>
|
||||
<br>
|
||||
<div class="postlist_r">
|
||||
@@ -202,7 +202,7 @@ export async function Main(app: Express) {
|
||||
<p>You must be logged in to create a post.</p>
|
||||
</div>
|
||||
`, `
|
||||
<a href="/login">Log in</a> | <a href="/register">Register</a><br><br>
|
||||
<a href="/login?next=/posts/new">Log in</a> | <a href="/register?next=/posts/new">Register</a><br><br>
|
||||
`))
|
||||
else {
|
||||
return res.send(newpost_string());
|
||||
|
||||
+1
-75
@@ -91,81 +91,7 @@ export async function Main(app: Express) {
|
||||
if (isnameerror)
|
||||
res.send(register_string(`The username ${username} is already taken!`))
|
||||
else
|
||||
res.send(`
|
||||
<!DOCTYPE html>
|
||||
|
||||
<body>
|
||||
<style>
|
||||
h1 {
|
||||
font-size: 50
|
||||
}
|
||||
|
||||
body {
|
||||
margin-right: 10%;
|
||||
margin-left: 10%;
|
||||
margin-bottom: 10%;
|
||||
text-align: left;
|
||||
color: black;
|
||||
font-family: Verdana, sans-serif;
|
||||
}
|
||||
|
||||
a:link {
|
||||
color: #3c72a3
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #2a567d
|
||||
}
|
||||
|
||||
@media screen and (prefers-color-scheme: dark) {
|
||||
body {
|
||||
background-color: #383737;
|
||||
color: #b0acac;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (prefers-color-scheme: light) {
|
||||
body {
|
||||
background-color: #e3e3e3;
|
||||
color: black;
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 32px
|
||||
}
|
||||
|
||||
.details {
|
||||
font-size: 20px
|
||||
}
|
||||
|
||||
.extra {
|
||||
font-size: 24px
|
||||
}
|
||||
|
||||
</style>
|
||||
<h1>${process.env.servicename || "File Server"}</h1>
|
||||
<div class="details">
|
||||
<p>Server region: ${'(alternate) ' + process.env.altregion}</p>
|
||||
</div><hr><br>
|
||||
<div class="description">
|
||||
${process.env.description || "A simple file server built with Express."}
|
||||
</div>
|
||||
<div class="extra">
|
||||
Account created successfully!<br>
|
||||
${req.session.user ? `
|
||||
<p>Logged in as ${req.session.user.username}<br>
|
||||
<a href=/api/logout>log out</a></p>
|
||||
` : `
|
||||
<a href=/login>Log in</a> | <a href=/register>Register</a><br>
|
||||
`}
|
||||
<br><br>
|
||||
Pages<br>
|
||||
) <a href=/staticfiles>/staticfiles</a><br>
|
||||
) <a href="/">Home</a>
|
||||
</div>
|
||||
</body>
|
||||
`);
|
||||
res.redirect(req.query?.next?.toString() ?? "/");
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ export async function Main(app: Express) {
|
||||
|
||||
app.get("/upload", async (req: Request, res: Response) => {
|
||||
if (!req.session.user)
|
||||
return res.status(401).send(upload_string("", "You must be <a href=/login>logged in</a> to use this feature."))
|
||||
return res.status(401).send(upload_string("", "You must be <a href=/login?next=/upload>logged in</a> to use this feature."))
|
||||
else {
|
||||
const user = req.session.user;
|
||||
return res.send(await upload_string_home(null, null, user))
|
||||
|
||||
Reference in New Issue
Block a user