Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit b02f5a1

Browse files
Make cookie never clear, add password auth for unlocking
1 parent ead9b65 commit b02f5a1

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

.env.docker

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
PORT=8080
2-
URL=
2+
URL=
3+
KEY=
4+
USERNAME=
5+
PASSWORD=
6+
# See github repository for .env.example with more documentation

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
PORT=8080 # YOUR PORT HERE (default: 8080)
22
URL= # THE URL YOU ARE HOSTING THIS ON (leave blank to disable)
3+
KEY= # The key in which unlocks the website (leave blank for default)
4+
USERNAME= # The username you wish to add for unlocking the website (besides ?unlock leave blank for default)
5+
PASSWORD= # The password you wish to add for unlocking the website (besides ?unlock leave blank for default)

education/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ <h1>Welcome to Ruby Education</h1>
181181
</p>
182182
<div class="section">
183183
<h2>Sign Up/Log In</h2>
184-
<form>
184+
<form action="/login-form" method="post">
185185
<label for="username">Username:</label><br />
186186
<input type="text" id="username" name="username" /><br />
187187
<label for="password">Password:</label><br />
@@ -287,7 +287,7 @@ <h2>Physical Education</h2>
287287
</p>
288288
</div>
289289
<footer>
290-
<p>© Copyright 2023 Ruby Network, All Rights Reserved</p>
290+
<p>&copy; Copyright 2023 Ruby Network, All Rights Reserved</p>
291291
</footer>
292292
</body>
293293
</head>

index.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ if (cluster.isPrimary) {
4747
app.use(express.static(join(__dirname, 'dist/client')));
4848
//Server side render middleware for astro
4949
app.use(ssrHandler);
50+
//express middleware for body
51+
app.use(express.json());
52+
app.use(express.urlencoded({ extended: false }));
53+
//uv config
5054
app.use('/uv/', express.static(uvPath));
5155
//env vars for the unlock feature
5256
let key = process.env.KEY || '';
@@ -81,7 +85,7 @@ if (cluster.isPrimary) {
8185
) {
8286
res.writeHead(302, {
8387
Location: '/',
84-
'Set-Cookie': `key=${key}; Path=/`,
88+
'Set-Cookie': `key=${key}; Path=/; expires=Thu, 31 Dec 2099 23:59:59 GMT;`,
8589
});
8690
res.end();
8791
return;
@@ -157,6 +161,26 @@ if (cluster.isPrimary) {
157161
app.get('/loading', (req, res) => {
158162
return res.sendFile(join(__dirname, 'education/load.html'));
159163
});
164+
app.post('/login-form', (req, res) => {
165+
let body = req.body;
166+
let user = process.env.USERNAME || 'ruby';
167+
let pass = process.env.PASSWORD || 'ruby';
168+
body = JSON.stringify(body);
169+
body = JSON.parse(body);
170+
if (body.username === user && body.password === pass) {
171+
res.writeHead(302, {
172+
location: '/',
173+
'Set-Cookie': `key=${key}; Path=/; expires=Thu, 31 Dec 2099 23:59:59 GMT;`,
174+
})
175+
res.end();
176+
return;
177+
}
178+
else {
179+
res.writeHead(401)
180+
res.end(educationWebsite);
181+
return;
182+
}
183+
})
160184
app.use((req, res) => {
161185
res.writeHead(302, {
162186
Location: '/404',

0 commit comments

Comments
 (0)