2014-01-22 15:46:44 -05:00
|
|
|
config = require '../../server_config'
|
2014-02-04 17:08:20 -05:00
|
|
|
log = require 'winston'
|
2014-01-24 14:47:14 -05:00
|
|
|
mail = require '../commons/mail'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-04 16:29:13 -05:00
|
|
|
module.exports.setup = (app) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
app.post '/contact', (req, res) ->
|
2014-02-04 17:08:20 -05:00
|
|
|
log.info "Sending mail from #{req.body.email} saying #{req.body.message}"
|
2014-01-03 17:28:26 -05:00
|
|
|
if config.isProduction
|
2014-01-03 13:32:13 -05:00
|
|
|
options = createMailOptions req.body.email, req.body.message, req.user
|
2014-01-24 14:47:14 -05:00
|
|
|
mail.transport.sendMail options, (error, response) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
if error
|
2014-02-04 17:08:20 -05:00
|
|
|
log.error "Error sending mail: #{error.message or error}"
|
2014-01-03 13:32:13 -05:00
|
|
|
else
|
2014-02-04 17:08:20 -05:00
|
|
|
log.info "Mail sent successfully. Response: #{response.message}"
|
2014-01-03 13:32:13 -05:00
|
|
|
return res.end()
|
|
|
|
|
|
|
|
createMailOptions = (sender, message, user) ->
|
|
|
|
# TODO: use email templates here
|
|
|
|
options =
|
|
|
|
from: config.mail.username
|
|
|
|
to: config.mail.username
|
|
|
|
replyTo: sender
|
|
|
|
subject: "[CodeCombat] Feedback - #{sender}"
|
|
|
|
text: "#{message}\n\nUsername: #{user.get('name') or 'Anonymous'}\nID: #{user._id}"
|
2014-01-24 14:47:14 -05:00
|
|
|
#html: message.replace '\n', '<br>\n'
|