mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2026-01-09 19:29:34 +01:00
Add support for locking specific inboxes with a password for X time, configurable via .env vars. This allows for users to bridge the gap between public free tempmail services and private personal mail services. Cheers!
38 lines
No EOL
1.2 KiB
JavaScript
38 lines
No EOL
1.2 KiB
JavaScript
function checkLockAccess(req, res, next) {
|
|
const inboxLock = req.app.get('inboxLock')
|
|
const address = req.params.address
|
|
|
|
if (!address || !inboxLock) {
|
|
return next()
|
|
}
|
|
|
|
const isLocked = inboxLock.isLocked(address)
|
|
const hasAccess = req.session && req.session.lockedInbox === address.toLowerCase()
|
|
|
|
// Block access to locked inbox without proper authentication
|
|
if (isLocked && !hasAccess) {
|
|
const count = req.app.get('mailProcessingService').getCount()
|
|
const unlockError = req.session ? req.session.unlockError : undefined
|
|
if (req.session) delete req.session.unlockError
|
|
|
|
return res.render('error', {
|
|
purgeTime: require('../../../application/helper').prototype.purgeTimeElemetBuilder(),
|
|
address: address,
|
|
count: count,
|
|
message: 'This inbox is locked. Please unlock it to access.',
|
|
branding: req.app.get('config').http.branding,
|
|
showUnlockButton: true,
|
|
unlockError: unlockError,
|
|
redirectTo: req.originalUrl
|
|
})
|
|
}
|
|
|
|
// Update last access if they have access
|
|
if (isLocked && hasAccess) {
|
|
inboxLock.updateAccess(address)
|
|
}
|
|
|
|
next()
|
|
}
|
|
|
|
module.exports = { checkLockAccess } |