diff --git a/.gitignore b/.gitignore index 49074af..f4cddf4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- -node_modules \ No newline at end of file +node_modules +yarn.lock \ No newline at end of file diff --git a/AppConfig.js b/AppConfig.js index e6c3bbf..2ebec10 100644 --- a/AppConfig.js +++ b/AppConfig.js @@ -1,67 +1,89 @@ -var path = require('path'); +var path = require('path'); var rootPath = path.normalize(__dirname + '/..'); -var env = process.env.NODE_ENV || 'development'; +var env = process.env.NODE_ENV || 'development'; var config = { - development: { - exchanges: { - coincap: { - name: 'CoinCap', - orgUrl: 'http://coincap.io/', - url: 'https://api.coinmarketcap.com/v1/ticker/dash' - }, - worldcoin: { - name: 'WorldCoinIndex', - orgUrl: 'https://www.worldcoinindex.com', - url: 'https://www.worldcoinindex.com/apiservice/json', - apiKey: 'ePSl8tl8dsFhLyReZ6aIwCQNw' - } - }, - budgets: { - dashwhale: { - name: 'DashWhale', - url: 'https://www.dashwhale.org/api/v1/budget' - } - }, - masternodes: { - node40: { - name: 'Node40', - apiKey: '8e4ec80a6394db3411b8af9afa3b5156d36fd18102f1278fef59a3e40d9bf6af', - apiKeyHeader: 'X-Api-Key', - historyUrl: 'https://node40.com/monitor/api/masterNode/history', - statsUrl: 'https://node40.com/monitor/api/masterNode/stats' - } - }, - chain: { - insight: { - name: 'Insight', - url: 'https://insight.dash.siampm.com/api/blocks', - maxBlocks: 10 - } - }, - root: rootPath, - app: { - name: 'dash.org-api' - }, - port: process.env.PORT || 9090, - logLevel: 'DEBUG' // EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG - }, + development: { + exchanges: { + coincap: { + name: 'CoinCap', + orgUrl: 'http://coincap.io/', + url: 'https://api.coinmarketcap.com/v1/ticker/dash' + }, + worldcoin: { + name: 'WorldCoinIndex', + orgUrl: 'https://www.worldcoinindex.com', + url: 'https://www.worldcoinindex.com/apiservice/json', + apiKey: 'ePSl8tl8dsFhLyReZ6aIwCQNw' + } + }, + budgets: { + dashwhale: { + name: 'DashWhale', + url: 'https://www.dashwhale.org/api/v1/budget' + } + }, + masternodes: { + node40: { + name: 'Node40', + apiKey: '8e4ec80a6394db3411b8af9afa3b5156d36fd18102f1278fef59a3e40d9bf6af', + apiKeyHeader: 'X-Api-Key', + historyUrl: 'https://node40.com/monitor/api/masterNode/history', + statsUrl: 'https://node40.com/monitor/api/masterNode/stats' + } + }, + chain: { + insight: { + name: 'Insight', + url: 'https://insight.dash.siampm.com/api/blocks', + maxBlocks: 10 + } + }, + root: rootPath, + app: { + name: 'dash.org-api' + }, + email: { + contactEmailAddress: "contact@dash.org", + transportConfig : { + port: 2525, + host: "localhost", + secure: false, + auth: { + user: "localWebUser", + pass: "asdfg" + } + } + }, + port: process.env.PORT || 8080, + logLevel: 'DEBUG' // EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG + }, - test: { - root: rootPath, - app: { - name: 'dash.org-api' - }, - port: process.env.PORT || 9090 - }, + test: { + root: rootPath, + app: { + name: 'dash.org-api' + }, + port: process.env.PORT || 9090 + }, - production: { - root: rootPath, - app: { - name: 'dash.org-api' - }, - port: process.env.PORT || 9090 - } + production: { + root: rootPath, + app: { + name: 'dash.org-api' + }, + port: process.env.PORT || 9090, + email: { + contactEmailAddress: "contact@dash.org", + transportConfig : { + service: "Gmail", + auth: { + user: "", + pass: "" + } + } + }, + } }; module.exports = config[env]; diff --git a/Server.js b/Server.js index 940fe1d..85e4761 100644 --- a/Server.js +++ b/Server.js @@ -7,6 +7,13 @@ var AppConfig = require('./AppConfig'); var Cache = require('./service/CacheRepository'); var Masternode = require('./service/MasternodeService'); var Blockchain = require('./service/BlockchainService'); +var Email = require('./service/EmailService'); +var bodyParser = require('body-parser') + +app.use( bodyParser.json() ); // to support JSON-encoded bodies +app.use(bodyParser.urlencoded({ // to support URL-encoded bodies + extended: true +})); // Add headers app.use(function (req, res, next) { @@ -87,6 +94,13 @@ app.get('/exchange', function(req,res){ }); +app.post('/send-contact-email', function(req,res){ + + var results = Email.sendMail(AppConfig.email.contactEmailAddress,req.body.subject, req.body.message); + res.send(results); + +}); + global.cacheConnection = Cache.connect(); var server = app.listen(AppConfig.port, function () { diff --git a/package.json b/package.json index c25529a..9a83bde 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,11 @@ "dependencies": { "async": "^2.0.0", "aws-sdk": "^2.4.7", + "body-parser": "^1.16.0", "express": "^4.13.3", "log": "^1.4.0", "memcached": "^2.2.2", + "nodemailer": "^3.0.2", "request": "^2.60.0" } } diff --git a/service/EmailService.js b/service/EmailService.js new file mode 100644 index 0000000..250f88c --- /dev/null +++ b/service/EmailService.js @@ -0,0 +1,33 @@ +/** + * Created by cwilliams on 2/9/17. + */ +var nodemailer = require("nodemailer"); +var AppConfig = require("../AppConfig"); + +var transport = AppConfig.email.transportConfig; +console.log('transport: ', transport); +var smtpTransport = nodemailer.createTransport(transport); + +function sendMail(to, subject, text) { + var mailOptions = { + to: to, + subject: subject, + text: text + }; + + console.log(mailOptions); + smtpTransport.sendMail(mailOptions, function (error, response) { + if (error) { + console.log(error); + res.end("error"); + } else { + console.log("Message sent: " + response.message); + res.end("sent"); + } + }); +} + + +module.exports = { + sendMail: sendMail +}; \ No newline at end of file