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