|
|
@ -19,42 +19,47 @@ module.exports = function(db) {
|
|
|
|
var obj = {}
|
|
|
|
var obj = {}
|
|
|
|
, email = sanitize(params.query.email)
|
|
|
|
, email = sanitize(params.query.email)
|
|
|
|
|
|
|
|
|
|
|
|
console.log('got email:', params.query)
|
|
|
|
db.get(email, function(err, value) {
|
|
|
|
|
|
|
|
if ((err && err.type == 'NotFoundError') || ! value.verified) {
|
|
|
|
obj.token = rn()
|
|
|
|
|
|
|
|
obj.verified = false
|
|
|
|
console.log('got email:', params.query)
|
|
|
|
obj.events = { paris: params.query.paris ? true : false }
|
|
|
|
|
|
|
|
obj.trace = ip(req)
|
|
|
|
obj.token = rn()
|
|
|
|
|
|
|
|
obj.verified = false
|
|
|
|
db.put(email, obj, function(err) {
|
|
|
|
obj.events = { paris: params.query.paris ? true : false }
|
|
|
|
if (err) return error(err)
|
|
|
|
obj.trace = ip(req)
|
|
|
|
|
|
|
|
|
|
|
|
// db write OK..
|
|
|
|
db.put(email, obj, function(err) {
|
|
|
|
var nodemailer = require('nodemailer')
|
|
|
|
if (err) return error(err)
|
|
|
|
, transporter = nodemailer.createTransport()
|
|
|
|
|
|
|
|
, url = config.host +'/confirm'
|
|
|
|
|
|
|
|
, qstr = '?email='+ email +'&token='+ obj.token
|
|
|
|
|
|
|
|
, link = url + qstr +'\n\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var opts = {
|
|
|
|
|
|
|
|
from : config.email.from
|
|
|
|
|
|
|
|
, to : email
|
|
|
|
|
|
|
|
, subject: config.email.subject
|
|
|
|
|
|
|
|
//, link : link
|
|
|
|
|
|
|
|
, text : config.email.bodyText.replace(/\%link\%/, link)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transporter.sendMail(opts, function(err, data) {
|
|
|
|
// db write OK..
|
|
|
|
if (err) return error(err)
|
|
|
|
var nodemailer = require('nodemailer')
|
|
|
|
|
|
|
|
, transporter = nodemailer.createTransport()
|
|
|
|
|
|
|
|
, url = config.host +'/confirm'
|
|
|
|
|
|
|
|
, qstr = '?email='+ email +'&token='+ obj.token
|
|
|
|
|
|
|
|
, link = url + qstr +'\n\n'
|
|
|
|
|
|
|
|
|
|
|
|
// validation email sent
|
|
|
|
var opts = {
|
|
|
|
console.log('email sent..', opts)
|
|
|
|
from : config.email.from
|
|
|
|
|
|
|
|
, to : email
|
|
|
|
|
|
|
|
, subject: config.email.subject
|
|
|
|
|
|
|
|
, text : config.email.bodyText.replace(/\%link\%/, link)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transporter.sendMail(opts, function(err, data) {
|
|
|
|
|
|
|
|
if (err) return error(err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// validation email sent
|
|
|
|
|
|
|
|
console.log('email sent..', opts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.statusCode = 302
|
|
|
|
|
|
|
|
res.setHeader('Location', '/')
|
|
|
|
|
|
|
|
return res.end()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res.statusCode = 302
|
|
|
|
|
|
|
|
res.setHeader('Location', '/')
|
|
|
|
|
|
|
|
return res.end()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
error('invalid input: '+ JSON.stringify(params.query))
|
|
|
|
error('invalid input: '+ JSON.stringify(params.query))
|
|
|
|
}
|
|
|
|
}
|
|
|
|