1
0
Fork 0

Merge pull request #7 from squatconf/www-launch-v5

v0.4.1-rc2 [don't use join() in ecstatic.opts]
2015
Julian Oates 10 years ago
commit ddc254169d

@ -1,6 +1,6 @@
{
"name": "squatconf-web",
"version": "0.4.0",
"version": "0.4.1",
"description": "website for the squatConf conference",
"main": "server.js",
"scripts": {

@ -5,14 +5,13 @@ var fs = require('fs')
, stack = require('stack')
, route = require('tiny-route')
, assets = require('ecstatic')
, join = require('path').join
, config = require('./config')
, db = require('level')(config.db_path, config.db_opts)
, port = process.env.PORT || config.port
// create the level db folder if it does not exists
if(!fs.existsSync('./db/squatconf')){
fs.mkdirSync('./db/squatconf', 0766, function(err){
if(!fs.existsSync(config.db_path)){
fs.mkdirSync(config.db_path, 0766, function(err){
if(err){
console.log(err);
}
@ -22,7 +21,7 @@ if(!fs.existsSync('./db/squatconf')){
var app = stack(
route('/email', require('./src/email-submit')(db))
, route('/confirm', require('./src/email-confirm')(db))
, assets(join(__dirname, 'html'))
, assets({ root: __dirname +'/html', handleError: false })
)
process.on('uncaughtException', function (err) {
@ -31,7 +30,7 @@ process.on('uncaughtException', function (err) {
})
http.createServer(app).listen(port, function() {
console.log('['+ process.pid +'] server started on port '+ port)
console.log('[PID='+ process.pid +'] server started on port '+ port)
console.log('(use Ctrl+c to stop the server)')
})

@ -8,13 +8,12 @@ module.exports = function(db) {
var params = require('url').parse(req.url, true)
if (params && params.query.email && params.query.token) {
//console.log('got token:', params.query)
var email = sanitize(params.query.email)
, token = sanitize(params.query.token)
db.get(email, function(err, obj) {
if (err) next(err)
if (err) return console.error(err)
// db read OK..
if (obj && obj.token === token) {
@ -22,7 +21,7 @@ module.exports = function(db) {
obj.trace = obj.trace.concat(ip(req))
db.put(email, obj, function(err) {
if (err) next(err)
if (err) return console.error(err)
// db write OK..
res.statusCode = 302

@ -10,18 +10,19 @@ module.exports = function(db) {
var params = require('url').parse(req.url, true)
if (params && params.query.email) {
console.log('got email:', params.query)
var obj = {}
, email = sanitize(params.query.email)
console.log('got email:', params.query)
obj.token = rn()
obj.verified = false
obj.events = { paris: params.query.paris ? true : false }
obj.trace = ip(req)
db.put(email, obj, function(err) {
if (err) next(err)
if (err) return console.error(err)
// db write OK..
var nodemailer = require('nodemailer')
@ -33,18 +34,20 @@ module.exports = function(db) {
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) {
if (err) throw err
if (err) return console.error(err)
// validation email sent
console.log('email sent..', data)
})
console.log('email sent..', opts)
res.statusCode = 302
res.setHeader('Location', '/')
return res.end()
res.statusCode = 302
res.setHeader('Location', '/')
return res.end()
})
})
}

Loading…
Cancel
Save