Add chat to Hall, clickable FEN, fix contact form
[vchess.git] / server / routes / messages.js
1 // Router for contact form sending
2
3 let router = require("express").Router();
4 const mailer = require(__dirname.replace("/routes", "/utils/mailer"));
5 const params = require(__dirname.replace("/routes", "/config/parameters"));
6
7 // Send a message through contact form
8 router.post("/messages", (req,res,next) => {
9 if (!req.xhr)
10 return res.json({errmsg: "Unauthorized access"});
11 console.log(req.body);
12 const from = req.body["email"];
13 const subject = req.body["subject"];
14 const body = req.body["content"];
15
16 // TODO: sanitize ?
17 mailer(from, params.mail.contact, subject, body, err => {
18 if (!!err)
19 return res.json({errmsg:err});
20 // OK, everything fine
21 res.json({}); //ignored
22 });
23 });
24
25 module.exports = router;