add multiple domain support, better error page for not found requests
This commit is contained in:
parent
2aeae8a240
commit
c9f5bca124
60
app.js
60
app.js
@ -65,6 +65,17 @@ async function fetchDomainData() {
|
||||
}
|
||||
}
|
||||
|
||||
function getDomains() {
|
||||
const domainsPath = path.join(__dirname, 'domains.txt');
|
||||
try {
|
||||
const domains = fs.readFileSync(domainsPath, 'utf-8').split('\n').filter(Boolean);
|
||||
return domains;
|
||||
} catch (error) {
|
||||
console.error('Error reading domains.txt:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Sync DB models
|
||||
sequelize.sync();
|
||||
|
||||
@ -132,35 +143,70 @@ app.get('/guides/vaultwarden/firefox', (req, res) => {
|
||||
});
|
||||
|
||||
app.get('/register', (req, res) => {
|
||||
res.render('register', { currentPage: 'register' });
|
||||
const domains = getDomains();
|
||||
res.render('register', { domains });
|
||||
});
|
||||
|
||||
app.post('/register', async (req, res) => {
|
||||
const { fullName, email, reason, telegram } = req.body;
|
||||
const { fullName, email, domain, reason, telegram } = req.body;
|
||||
const crit = /^[a-zA-Z0-9.-]+$/; // regex (see also: public/js/register.js)
|
||||
|
||||
if (!crit.test(email) || /\s/.test(email) || email !== email.toLowerCase()) {
|
||||
return res.render('error/500');
|
||||
}
|
||||
await Request.create({ fullName, email, reason, telegram });
|
||||
|
||||
const fullEmail = `${email}@${domain}`;
|
||||
|
||||
try {
|
||||
await Request.create({ fullName, email: fullEmail, reason, telegram });
|
||||
res.render('reg-success', { currentPage: 'register' });
|
||||
} catch (error) {
|
||||
console.error('Error creating request:', error);
|
||||
res.render('error/500');
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/request', async (req, res) => {
|
||||
console.log("Found!");
|
||||
const { email } = req.query;
|
||||
const domains = getDomains();
|
||||
|
||||
if (!email) {
|
||||
return res.status(400).render('error/email');
|
||||
return res.render('error/email', { domains });
|
||||
}
|
||||
|
||||
try {
|
||||
const request = await Request.findOne({ where: { email } });
|
||||
if (!request) {
|
||||
return res.status(404).render('error/404');
|
||||
return res.status(404).render('error/notfoundemail', { email, domain });
|
||||
}
|
||||
res.render('request', { request });
|
||||
res.render('request', { request, domains });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).render('error/500');
|
||||
res.render('error/500');
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/request', async (req, res) => {
|
||||
console.log("Found!");
|
||||
const { email, domain } = req.body;
|
||||
const fullEmail = `${email}@${domain}`;
|
||||
const domains = getDomains();
|
||||
|
||||
if (!email || !domain) {
|
||||
return res.render('error/email', { domains });
|
||||
}
|
||||
|
||||
try {
|
||||
const request = await Request.findOne({ where: { email: fullEmail } });
|
||||
const domains = getDomains();
|
||||
if (!request) {
|
||||
return res.render('error/notfoundemail', { email, domain });
|
||||
}
|
||||
res.render('request', { request, domains });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.render('error/500');
|
||||
}
|
||||
});
|
||||
|
||||
|
3
domains.txt
Normal file
3
domains.txt
Normal file
@ -0,0 +1,3 @@
|
||||
p0ntus.com
|
||||
pontusmail.org
|
||||
ihate.college
|
@ -4,14 +4,19 @@
|
||||
<i class="il mt-5">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" onsubmit="return validateEmail()">
|
||||
<form action="/request" method="post" onsubmit="return validateEmail()">
|
||||
<div class="form-group">
|
||||
<label class="mb-2" for="email">p0ntus mail email address:</label>
|
||||
<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 class="input-group-prepend">
|
||||
<span class="input-group-text">@</span>
|
||||
</div>
|
||||
<select class="form-select" id="domain" name="domain" required>
|
||||
<% domains.forEach(domain => { %>
|
||||
<option value="<%= domain %>"><%= domain %></option>
|
||||
<% }); %>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-dark mt-3">Submit</button>
|
||||
|
7
src/error/notfoundemail.ejs
Normal file
7
src/error/notfoundemail.ejs
Normal file
@ -0,0 +1,7 @@
|
||||
<%- include('../shards/header', { title: "Couldn't find that email - p0ntus mail", currentPage: 'err' }) %>
|
||||
<div class="container">
|
||||
<i class="il mt-2">We couldn't find that email</i>
|
||||
<hr>
|
||||
<p>We couldn't find a request under <b><%= email %>@<%= domain %></b>. Please try again later or try and register again.</p>
|
||||
</div>
|
||||
<%- include('../shards/footer') %>
|
@ -1,4 +1,4 @@
|
||||
<%- include('shards/header', { title: 'Register - p0ntus mail' }) %>
|
||||
<%- include('shards/header', { title: 'Register - p0ntus mail', currentPage: 'register' }) %>
|
||||
<div class="container">
|
||||
<%- include('shards/nav', { currentPage: 'register' }) %>
|
||||
<h1 class="mt-5">Register</h1>
|
||||
@ -21,9 +21,14 @@
|
||||
<label for="email" class="mb-2">Desired email address (e.g., yourname@p0ntus.com) - <b>Do not enter your current email in this box</b></label>
|
||||
<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 class="input-group-prepend">
|
||||
<span class="input-group-text">@</span>
|
||||
</div>
|
||||
<select class="form-select" id="domain" name="domain" required>
|
||||
<% domains.forEach(domain => { %>
|
||||
<option value="<%= domain %>"><%= domain %></option>
|
||||
<% }); %>
|
||||
</select>
|
||||
</div>
|
||||
<small class="form-text text-muted">Only letters, numbers, periods, and dashes are allowed.</small>
|
||||
</div>
|
||||
|
@ -3,7 +3,28 @@
|
||||
<%- include('shards/nav', { currentPage: 'request' }) %>
|
||||
<i class="il mt-5">Request Status</i>
|
||||
<hr>
|
||||
<form action="/request" method="POST">
|
||||
<div class="form-group mb-3">
|
||||
<label for="email" class="mb-2">Email</label>
|
||||
<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-prepend">
|
||||
<span class="input-group-text">@</span>
|
||||
</div>
|
||||
<select class="form-select" id="domain" name="domain" required>
|
||||
<% domains.forEach(domain => { %>
|
||||
<option value="<%= domain %>"><%= domain %></option>
|
||||
<% }); %>
|
||||
</select>
|
||||
</div>
|
||||
<small class="form-text text-muted">Only letters, numbers, periods, and dashes are allowed.</small>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-dark mt-3"><i class="fa-solid fa-search ico-sm"></i> Check Status</button>
|
||||
</form>
|
||||
|
||||
<% if (request) { %>
|
||||
<hr class="mt-4" />
|
||||
<p>Email: <strong><%= request.email %></strong></p>
|
||||
<p>Request Status: <strong><%= request.status %></strong></p>
|
||||
<% if (request.status === 'Approved') { %>
|
||||
<div class="text-start">
|
||||
|
Reference in New Issue
Block a user