| 1 | // Router for contact form sending |
| 2 | |
| 3 | let router = require("express").Router(); |
| 4 | const mailer = require(__dirname.replace("/routes", "/utils/mailer")); |
| 5 | |
| 6 | // Send a message through contact form |
| 7 | router.post("/messages", (req,res,next) => { |
| 8 | if (!req.xhr) |
| 9 | return res.json({errmsg: "Unauthorized access"}); |
| 10 | const from = req.body["email"]; |
| 11 | const subject = req.body["subject"]; |
| 12 | const body = req.body["body"]; |
| 13 | // TODO: sanitize ? |
| 14 | mailer.send(from, mailer.contact, subject, body, err => { |
| 15 | if (!!err) |
| 16 | return res.json({errmsg:err}); |
| 17 | // OK, everything fine |
| 18 | res.json({}); //ignored |
| 19 | }); |
| 20 | }); |
| 21 | |
| 22 | module.exports = router; |