1
0
Fork 0

added db storage (match email addresses to tokens)

2015
joates 10 years ago
parent d7a4038288
commit 5f52ab39bf

@ -5,6 +5,8 @@ var server = require('http').createServer(handler)
, rn = require('./src/rng') , rn = require('./src/rng')
, fs = require('fs') , fs = require('fs')
, re = new RegExp('\.js$', 'i') , re = new RegExp('\.js$', 'i')
, ip = require('./src/ip-trace')
, db = require('level')('./db/squatconf', { valueEncoding: 'json' })
, port = process.env.PORT || /*80*/ 8000 , port = process.env.PORT || /*80*/ 8000
function handler(req, res) { function handler(req, res) {
@ -34,13 +36,17 @@ function handler(req, res) {
obj.token = rn() obj.token = rn()
obj.verified = false obj.verified = false
obj.events = { paris: params.query.paris ? true : false } obj.events = { paris: params.query.paris ? true : false }
obj.trace = (req.headers['x-forwarded-for'] || '').split(',') obj.trace = ip(req)
|| [ req.connection.remoteAddress ]
var db = require('level')('./db/squatconf', { valueEncoding: 'json' })
db.put(email, obj, function(err) { db.put(email, obj, function(err) {
if (err) cb(err) if (err) throw err
// else.. db updated OK // else.. db updated OK
db.get(email, function (err, value) {
if (err) return console.error('Ooops!', err)
console.log('> '+ email, value)
})
}) })
var nodemailer = require('nodemailer') var nodemailer = require('nodemailer')
@ -53,14 +59,16 @@ function handler(req, res) {
from : config.email.from from : config.email.from
, to : email , to : email
, subject: config.email.subject , subject: config.email.subject
, text : config.email.bodyText.replace(/\%link\%/, link) //, text : config.email.bodyText.replace(/\%link\%/, link)
} }
console.log('mockmail sent...', opts)
/*
transporter.sendMail(opts, function(err, data) { transporter.sendMail(opts, function(err, data) {
if (err) throw err if (err) throw err
// validation email sent // validation email sent
console.log('email sent..', data) console.log('email sent..', data)
}) })
*/
} }
res.statusCode = 302 res.statusCode = 302

@ -0,0 +1,8 @@
module.exports = function(req) {
if (req.headers['x-forwarded-for']) {
return req.headers['x-forwarded-for'].split(',')
} else {
return [ req.connection.remoteAddress ]
}
}
Loading…
Cancel
Save