add port changing via env, organize admin routes, fix bug + improve page for request checking
This commit is contained in:
parent
20eeac2ac0
commit
5ce5bb165f
@ -5,4 +5,5 @@ DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
SESSION_SECRET=secretkeyhere
|
||||
ADMIN_USERNAME=admin
|
||||
ADMIN_PASSWORD=admin
|
||||
ADMIN_PASSWORD=admin
|
||||
INTERNAL_PORT=3000
|
24
app.js
24
app.js
@ -20,8 +20,8 @@ app.use(session({
|
||||
}));
|
||||
|
||||
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
|
||||
host: process.env.DB_HOST || '127.0.0.1',
|
||||
port: process.env.DB_PORT || 3306,
|
||||
host: process.env.DB_HOST || '127.0.0.1', // pulls from .env or defaults to localhost
|
||||
port: process.env.DB_PORT || 3306, // pulls from .env or defaults to 3306
|
||||
dialect: 'mysql'
|
||||
});
|
||||
|
||||
@ -40,10 +40,9 @@ const Request = sequelize.define('Request', {
|
||||
}
|
||||
});
|
||||
|
||||
// Sync models
|
||||
// Sync DB models
|
||||
sequelize.sync();
|
||||
|
||||
// Routes
|
||||
app.get('/', (req, res) => {
|
||||
res.render('index', { currentPage: 'home' });
|
||||
});
|
||||
@ -70,6 +69,9 @@ app.get('/privacy', (req, res) => {
|
||||
res.render('privacy', { currentPage: 'privacy' });
|
||||
});
|
||||
|
||||
// Guide routes
|
||||
// TODO: Improve how guides are routed to be simpler
|
||||
|
||||
app.get('/guides', (req, res) => {
|
||||
res.render('guides', { currentPage: 'guides' });
|
||||
});
|
||||
@ -135,11 +137,13 @@ function checkAdminAuth(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
// Admin routes
|
||||
|
||||
app.get('/admin', (req, res) => {
|
||||
if (req.session.admin) {
|
||||
return res.redirect('/admin/dashboard');
|
||||
}
|
||||
res.render('admin-login', { currentPage: 'admin', error: null });
|
||||
res.render('admin/login', { currentPage: 'admin', error: null });
|
||||
});
|
||||
|
||||
app.post('/admin', (req, res) => {
|
||||
@ -148,13 +152,13 @@ app.post('/admin', (req, res) => {
|
||||
req.session.admin = true;
|
||||
res.redirect('/admin/dashboard');
|
||||
} else {
|
||||
res.render('admin-login', { error: 'An error occurred.' });
|
||||
res.render('admin/login', { error: 'An error occurred.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/admin/dashboard', checkAdminAuth, async (req, res) => {
|
||||
const requests = await Request.findAll();
|
||||
res.render('admin-dash', { requests, currentPage: 'admin' });
|
||||
res.render('admin/dash', { requests, currentPage: 'admin' });
|
||||
});
|
||||
|
||||
app.post('/admin/update-status', checkAdminAuth, async (req, res) => {
|
||||
@ -169,7 +173,7 @@ app.post('/admin/delete-request', checkAdminAuth, async (req, res) => {
|
||||
res.redirect('/admin/dashboard');
|
||||
});
|
||||
|
||||
// Start server on 3000
|
||||
app.listen(3000, () => {
|
||||
console.log('Server started on port 3000');
|
||||
// Start server on internal port defined in .env
|
||||
app.listen(process.env.INTERNAL_PORT, () => {
|
||||
console.log(`Server started on port ${process.env.INTERNAL_PORT}`);
|
||||
});
|
@ -1,9 +0,0 @@
|
||||
function validateEmail() {
|
||||
const email = document.getElementById('email').value;
|
||||
const regex = /^[a-zA-Z0-9.-]+$/;
|
||||
if (!regex.test(email)) {
|
||||
alert('An invalid email has been entered. You may only include letters, numbers, periods, and dashes. Make sure you do not include @p0ntus.com');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
@ -3,10 +3,15 @@
|
||||
<i class="il mt-2">We need your email</i>
|
||||
<hr>
|
||||
<p class="mt-4 mb-4">We need an email to check your request. Please enter your p0ntus mail email address below:</p>
|
||||
<form action="/request" method="get">
|
||||
<form action="/request" method="get" onsubmit="return validateEmail()">
|
||||
<div class="form-group">
|
||||
<label class="mb-2" for="email">p0ntus mail email address:</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="email" name="email" pattern="^[a-zA-Z0-9.\-]+$" required oninput="this.value = this.value.toLowerCase().replace(/\s/g, '')">
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">@p0ntus.com</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mt-3">Submit</button>
|
||||
</form>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<i class="il mt-5">If you haven't filled out a registration request</i>
|
||||
<hr>
|
||||
<p class="mt-3"><b>Do not use this service for spam. It is a waste of your time.</b> I have added protections to prevent spam, including sending quotas per hour. I will catch you before you can send a good enough amount.</p>
|
||||
<form action="/register" method="POST" onsubmit="return validateEmail()">
|
||||
<form action="/register" method="POST">
|
||||
<div class="form-group mb-3">
|
||||
<label for="fullName" class="mb-2">Name that goes in email header (full name/username/alias)</label>
|
||||
<input type="text" class="form-control" id="fullName" name="fullName" required>
|
||||
@ -38,5 +38,4 @@
|
||||
<button type="submit" class="btn btn-dark mt-3"><i class="fa-solid fa-user-plus ico-sm"></i> Register</button>
|
||||
</form>
|
||||
</div>
|
||||
<script src="/js/register.js"></script>
|
||||
<%- include('shards/footer') %>
|
@ -1,4 +1,4 @@
|
||||
<%- include('shards/header', { title: 'Request Status - p0ntus mail' }) %>
|
||||
<%- include('shards/header', { title: 'Request Status - p0ntus mail', currentPage: 'request' }) %>
|
||||
<div class="container">
|
||||
<%- include('shards/nav', { currentPage: 'request' }) %>
|
||||
<i class="il mt-5">Request Status</i>
|
Reference in New Issue
Block a user