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:
1
app.js
1
app.js
@@ -127,6 +127,7 @@ async function main() {
|
|||||||
'/register',
|
'/register',
|
||||||
'/password-reset',
|
'/password-reset',
|
||||||
'/change-password',
|
'/change-password',
|
||||||
|
'/contact',
|
||||||
'/'
|
'/'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user