Commit | Line | Data |
---|---|---|
582df349 BA |
1 | // Router for contact form sending |
2 | ||
298c42e6 | 3 | let router = require("express").Router(); |
8d7e2786 | 4 | const mailer = require(__dirname.replace("/routes", "/utils/mailer")); |
603b8a8b | 5 | const params = require(__dirname.replace("/routes", "/config/parameters")); |
298c42e6 BA |
6 | |
7 | // Send a message through contact form | |
8 | router.post("/messages", (req,res,next) => { | |
dac39588 BA |
9 | if (!req.xhr) |
10 | return res.json({errmsg: "Unauthorized access"}); | |
603b8a8b | 11 | const from = req.body["email"]; |
99b7a14c BA |
12 | // Replace potential newline characters in subject |
13 | const subject = req.body["subject"].replace(/\r?\n|\r/g, " "); | |
14 | const body = req.body["content"]; //TODO: sanitize? Why? How? | |
603b8a8b | 15 | |
dac39588 BA |
16 | mailer(from, params.mail.contact, subject, body, err => { |
17 | if (!!err) | |
18 | return res.json({errmsg:err}); | |
19 | // OK, everything fine | |
20 | res.json({}); //ignored | |
21 | }); | |
298c42e6 BA |
22 | }); |
23 | ||
24 | module.exports = router; |