automatically generate example inbox url

This commit is contained in:
ClaraCrazy 2025-12-07 15:19:23 +01:00
parent e158fac414
commit 9d991486ae
No known key found for this signature in database
GPG key ID: EBBC896ACB497011
3 changed files with 36 additions and 36 deletions

View file

@ -1,6 +1,6 @@
const express = require('express')
const router = new express.Router()
const {check, validationResult} = require('express-validator')
const { check, validationResult } = require('express-validator')
const randomWord = require('random-word')
const config = require('../../../application/config')
@ -10,49 +10,49 @@ const helper = new(Helper)
const purgeTime = helper.purgeTimeElemetBuilder()
router.get('/', (req, res, _next) => {
res.render('login', {
title: `${config.http.branding[0]} | Your temporary Inbox`,
username: randomWord(),
purgeTime: purgeTime,
domains: helper.getDomains(),
branding: config.http.branding,
})
res.render('login', {
title: `${config.http.branding[0]} | Your temporary Inbox`,
username: randomWord(),
purgeTime: purgeTime,
domains: helper.getDomains(),
branding: config.http.branding,
example: config.email.examples.account,
})
})
router.get('/inbox/random', (req, res, _next) => {
res.redirect(`/inbox/${randomWord()}@${config.email.domains[Math.floor(Math.random() * config.email.domains.length)]}`)
res.redirect(`/inbox/${randomWord()}@${config.email.domains[Math.floor(Math.random() * config.email.domains.length)]}`)
})
router.get('/logout', (req, res, _next) => {
/**
* If we ever need a logout sequence, now we can have one!
*/
/**
* If we ever need a logout sequence, now we can have one!
*/
res.redirect('/')
res.redirect('/')
})
router.post(
'/',
[
check('username').isLength({min: 1}),
check('domain').isIn(config.email.domains)
],
(req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.render('login', {
userInputError: true,
title: `${config.http.branding[0]} | Your temporary Inbox`,
purgeTime: purgeTime,
username: randomWord(),
domains: helper.getDomains(),
branding: config.http.branding,
})
}
'/', [
check('username').isLength({ min: 1 }),
check('domain').isIn(config.email.domains)
],
(req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.render('login', {
userInputError: true,
title: `${config.http.branding[0]} | Your temporary Inbox`,
purgeTime: purgeTime,
username: randomWord(),
domains: helper.getDomains(),
branding: config.http.branding,
})
}
res.redirect(`/inbox/${req.body.username}@${req.body.domain}`)
}
res.redirect(`/inbox/${req.body.username}@${req.body.domain}`)
}
)
module.exports = router
module.exports = router

View file

@ -3,7 +3,7 @@
{% block body %}
<div style="float: right; text-align: end;">
<a href="/inbox/example@48hr.email">Example Inbox</a>
<a href="/inbox/{{ example }}">Example Inbox</a>
</div>
<div id="login">
<h1>Welcome!</h1>

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "48hr.email",
"version": "1.5.4",
"version": "1.6.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "48hr.email",
"version": "1.5.4",
"version": "1.6.1",
"license": "GPL-3.0",
"dependencies": {
"array.prototype.flatmap": "^1.3.2",