diff --git a/api/handlers/register.js b/api/handlers/register.js index 64060b9b..cb4d97ee 100644 --- a/api/handlers/register.js +++ b/api/handlers/register.js @@ -5,6 +5,7 @@ var bcrypt = require('bcrypt'); // see: https://github.com/nelsonic/bcrypt var aguid = require('aguid'); // import the module we are using to create (GU)IDs var JWTSign = require('../lib/auth_jwt_sign.js'); // used to sign JWTS duh. var transfer = require('../lib/transfer_anon_to_registered.js'); +var email = require('../lib/email_welcome'); module.exports = function handler(req, reply) { var personid = aguid(req.payload.email) @@ -30,16 +31,21 @@ module.exports = function handler(req, reply) { Hoek.assert(res.created, 'Person NOT Registered!'); // only if DB fails! // transfer any anonymous timers & session to the person - if(req.headers.authorization){ - // console.log("AUTH TOKEN:"+req.headers.authorization); - return transfer(req, reply); - } - else { - JWTSign(req, function(token, esres){ - return reply(esres).header("Authorization", token); - }); // Asynchronous - } - + console.log(' - - - - - - - - - - person') + console.log(person); + console.log(' - - - - - - - - - - email success') + email(person, function(err, eres){ + console.log(eres); + if(req.headers.authorization){ + // console.log("AUTH TOKEN:"+req.headers.authorization); + return transfer(req, reply); + } + else { + JWTSign(req, function(token, esres){ + return reply(esres).header("Authorization", token); + }); // Asynchronous + } + }) }); // end ES.CREATE }); // end bcrypt.hash }); // end bcrypt.genSalt diff --git a/api/lib/email_welcome.js b/api/lib/email_welcome.js new file mode 100644 index 00000000..28a9446e --- /dev/null +++ b/api/lib/email_welcome.js @@ -0,0 +1,45 @@ +var nodemailer = require('nodemailer'); +var fs = require('fs'); +var path = require('path'); +var htmlpath = path.resolve(__dirname +'/../templates/welcome_html.html'); +var textpath = path.resolve(__dirname +'/../templates/welcome_text.txt'); +var template = fs.readFileSync(htmlpath, 'utf8') +var textonly = fs.readFileSync(textpath, 'utf8') +// create reusable transporter object using SMTP transport +var transporter = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: 'welcome.to.dwyl@gmail.com', + pass: process.env.GMAIL_PASSWORD + } +}); + +// NB! No need to recreate the transporter object. You can use +// the same transporter object for all e-mails + +var email = function(person, callback){ + var mailOptions = { + from: '#dwyl do what you love! ', // sender address + to: person.email, // list of receivers + subject: 'Welcome to dwyl!', // Subject line + text: textonly, // plaintext body + html: template + }; + // send mail with defined transport object + transporter.sendMail(mailOptions, function(error, info){ + // console.log(error, info); + callback(error, info) + }); +} + +var person = { + email : 'dwyl.smith@gmail.com', + name : 'FirstName' +} + +// email(person, function(error,info){ +// console.log('hello!'); +// console.log(info); +// }) + +module.exports = email; diff --git a/api/templates/welcome_html.html b/api/templates/welcome_html.html new file mode 100644 index 00000000..c2c2a9cf --- /dev/null +++ b/api/templates/welcome_html.html @@ -0,0 +1,14 @@ +

Hi!

+ +

Thanks so much for joining us to alpha test dwyl, we’re excited to have you!

+ +

For now, dwyl will help you track your time and soon it will help you do much more, including + + making time for what you love + . +

+ +

If you have any questions or find any bugs, big or small, please drop us a note or add an issue to github, we really appreciate it!

+ +

Happy dwyling!

+Ines & Nelson \ No newline at end of file diff --git a/api/templates/welcome_text.txt b/api/templates/welcome_text.txt new file mode 100644 index 00000000..c24bc023 --- /dev/null +++ b/api/templates/welcome_text.txt @@ -0,0 +1,11 @@ +Hi! + +Thanks so much for joining us to alpha test dwyl, we’re excited to have you! + +For now, dwyl will help you track your time and soon it will help you do much more, including making time for what you love. https://github.com/ideaq/start-here/blob/master/manifesto.md + +If you have any questions or find any bugs, big or small, please drop us a note or add an issue to github: +https://github.com/ideaq/time/labels/MVP We really appreciate it! + +Happy dwyling +Ines & Nelson \ No newline at end of file diff --git a/api/test/anonymous.js b/api/test/anonymous.js index 66267a7b..f7d4ba50 100644 --- a/api/test/anonymous.js +++ b/api/test/anonymous.js @@ -34,7 +34,7 @@ test(file + "Anonymous people can create timers!", function(t) { }; server.inject(options, function(res) { var T = JSON.parse(res.payload); - t.equal(res.statusCode, 200, "New timer started! " + T.st); + t.equal(res.statusCode, 200, "New timer started! " + T.start); t.end(); server.stop(); }); diff --git a/front/public/js/alpha.js b/front/public/js/alpha.js index 9caad691..a5516460 100644 --- a/front/public/js/alpha.js +++ b/front/public/js/alpha.js @@ -306,6 +306,7 @@ $(document).ready(function() { return obj; } catch(e){ + console.log("DB.GET FAIL: "+key +" | "+value); console.log(e); // value is not a stringified object return value; diff --git a/package.json b/package.json index dd3c4e7d..0940f580 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dwyl", - "version": "0.1.5", + "version": "0.1.6", "description": "Track any time-based activity", "main": "index.js", "scripts": { @@ -10,7 +10,7 @@ "faster": "node ./node_modules/faster/bin/faster.js", "jshint": "./node_modules/jshint/bin/jshint -c .jshintrc --exclude-path .gitignore .", "start": "node web.js", - "test": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./api/test/*.js | node_modules/tap-spec/bin/cmd.js", + "test": "istanbul cover ./node_modules/tape/bin/tape ./api/test/*.js | node_modules/tap-spec/bin/cmd.js", "spec": "node ./node_modules/tape/bin/tape ./api/test/*.js | node_modules/tap-spec/bin/cmd.js" }, "repository": { @@ -41,6 +41,7 @@ "joi": "^6.1.0", "jsonwebtoken": "^5.0.0", "lout": "^6.2.1", + "nodemailer": "^1.3.4", "perma": "^2.0.1", "sad": "^1.0.7" }, diff --git a/web.js b/web.js index 7d11daf6..35ddd540 100644 --- a/web.js +++ b/web.js @@ -38,8 +38,7 @@ server.register([ {register: Basic}, {register: AuthJWT} ], function (err) { }); -server.start(function(){ - console.log('Now Visit: http://' + ip + ':' +port); -}); +server.start(); +console.log('Now Visit: http://' + ip + ':' +port); module.exports = server;