1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 16:19:26 +00:00

Add contact form functionality

This commit is contained in:
2022-04-25 20:58:13 +00:00
parent c6dadd8c84
commit 5d543f002f
2 changed files with 35 additions and 0 deletions

1
app.js
View File

@@ -127,6 +127,7 @@ async function main() {
'/register', '/register',
'/password-reset', '/password-reset',
'/change-password', '/change-password',
'/contact',
'/' '/'
]; ];

View File

@@ -244,6 +244,40 @@ router.post('/change-password', async (req, res) => {
return res.redirect('/login'); return res.redirect('/login');
}); });
router.post('/contact', (req, res) => {
let fields;
try {
fields = validator.validate(req.body,
[
'fname',
'lname',
'email',
'body'
],
{
email: 'email'
}
).fields;
} catch (e) {
console.error(e);
return res.redirect('/');
}
const email = new EmailBuilder()
.setSubject('Stratos contact request')
.addTo([
`${fields.get('fname')} <${fields.get('email')}>`,
'Stratos <contact@stratos.com>'
])
.setBody(fields.get('body'));
const emailer = new Emailer();
emailer.sendEmail(email);
res.send('Thank you for your enquiry, someone will get back to you ' +
'shortly!');
});
module.exports = { module.exports = {
root: '/', root: '/',
router: router router: router