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