|
|
@ -5,6 +5,11 @@ module.exports = function(db) {
|
|
|
|
return function (req, res, next) {
|
|
|
|
return function (req, res, next) {
|
|
|
|
req.resume()
|
|
|
|
req.resume()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function error(e) {
|
|
|
|
|
|
|
|
console.error(e)
|
|
|
|
|
|
|
|
return next(e || e.msg || 'ERROR')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var params = require('url').parse(req.url, true)
|
|
|
|
var params = require('url').parse(req.url, true)
|
|
|
|
|
|
|
|
|
|
|
|
if (params && params.query.email && params.query.token) {
|
|
|
|
if (params && params.query.email && params.query.token) {
|
|
|
@ -13,25 +18,30 @@ module.exports = function(db) {
|
|
|
|
, token = sanitize(params.query.token)
|
|
|
|
, token = sanitize(params.query.token)
|
|
|
|
|
|
|
|
|
|
|
|
db.get(email, function(err, obj) {
|
|
|
|
db.get(email, function(err, obj) {
|
|
|
|
if (err) return console.error(err)
|
|
|
|
if (err) return error(err)
|
|
|
|
|
|
|
|
|
|
|
|
// db read OK..
|
|
|
|
// db read OK..
|
|
|
|
if (obj && obj.token === token) {
|
|
|
|
if (obj && ! obj.verified) {
|
|
|
|
obj.verified = true
|
|
|
|
if (obj.token === token) {
|
|
|
|
obj.trace = obj.trace.concat(ip(req))
|
|
|
|
obj.verified = true
|
|
|
|
|
|
|
|
obj.trace = obj.trace.concat(ip(req))
|
|
|
|
db.put(email, obj, function(err) {
|
|
|
|
|
|
|
|
if (err) return console.error(err)
|
|
|
|
db.put(email, obj, function(err) {
|
|
|
|
|
|
|
|
if (err) return error(err)
|
|
|
|
// db write OK..
|
|
|
|
|
|
|
|
res.statusCode = 302
|
|
|
|
// db write OK..
|
|
|
|
res.setHeader('Location', '/verified.html')
|
|
|
|
res.statusCode = 302
|
|
|
|
return res.end()
|
|
|
|
res.setHeader('Location', '/verified.html')
|
|
|
|
})
|
|
|
|
return res.end()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
error('email is already verified: '+ email)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (next) return next()
|
|
|
|
} else {
|
|
|
|
|
|
|
|
error('invalid input: '+ JSON.stringify(params.query))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|