From 6fecbd8898b8fab053ff90a100dd4d421ebea204 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Sat, 29 Aug 2015 16:33:58 +0200 Subject: [PATCH] Name in mail --- posts/feedback-target/index.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/posts/feedback-target/index.js b/posts/feedback-target/index.js index dd346fb..53a573d 100644 --- a/posts/feedback-target/index.js +++ b/posts/feedback-target/index.js @@ -1,3 +1,5 @@ +var pg = require('pg'); +var pgc = require('../../private.js'); var mail = require('../../lib/mail.js'); var Log = require('../../lib/NodeLog.js'); @@ -9,15 +11,27 @@ module.exports.index = function(req, res) { text += i + ' : ' + req.body[i] + '\n'; } - mail.send({ - from: req.session.user_id + " <" + req.session.user_id + "@toto.tata>", - to: "Thomas ", - subject: "By " + req.session.user_id, - text: text - }, function(err, message) { - if (err !== null) { - Log.mailerror(err); - } + pg.connect(pgc.url, function(err, client, release) { + + client.query( + 'SELECT Users.worker_id AS name FROM Users WHERE Users.id = $1;', + [req.session.userId], + + function(err, result) { + mail.send({ + from: result.rows[0].name + " <" + req.session.userId + "@toto.tata>", + to: "Thomas ", + subject: "By " + result.rows[0].name, + text: text + }, function(err, message) { + if (err !== null) { + Log.mailerror(err); + } + }); + + } + ); + }); res.redirect('/thankyou');