mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2025-06-30 22:17:09 +02:00
- New purgeTIme now allows to configure a purge to be every X minutes, hours or days. - Also remove a bit more trust by pulling footer deletion time from config. - TODO: implement 'convertUp' function, converting numbers up to the biggest possible value where `i > 2 (so 48hrs still works as per slogan and domain)`. I.e. 72hrs = 3 days, 360minutes = 6hrs, 1440minutes to 24hrs Co-authored-by: Johannes Bülow <kontakt@jmbit.de>
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
const express = require('express')
|
|
|
|
const router = new express.Router()
|
|
const randomWord = require('random-word')
|
|
const {check, validationResult} = require('express-validator')
|
|
const config = require('../../../application/config')
|
|
const Helper = require('../../../application/helper')
|
|
const helper = new(Helper)
|
|
|
|
const purgeTime = config.email.purgeTime.convert ? helper.convertUp(config.email.purgeTime.time, config.email.purgeTime.unit)
|
|
: config.email.purgeTime.time +` ${config.email.purgeTime.unit}`;
|
|
|
|
router.get('/', (req, res, _next) => {
|
|
res.render('login', {
|
|
title: `${config.http.branding[0]} | Your temporary Inbox`,
|
|
username: randomWord(),
|
|
purgeTime: purgeTime,
|
|
domains: config.email.domains,
|
|
branding: config.http.branding,
|
|
})
|
|
})
|
|
|
|
router.get('/inbox/random', (req, res, _next) => {
|
|
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!
|
|
*/
|
|
|
|
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(),
|
|
branding: config.http.branding,
|
|
})
|
|
}
|
|
|
|
res.redirect(`/inbox/${req.body.username}@${req.body.domain}`)
|
|
}
|
|
)
|
|
|
|
module.exports = router
|