Skip to content
This repository was archived by the owner on Feb 4, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ app.locals.theme = process.env.THEME; //Make the THEME environment variable avai
var config = fs.readFileSync('./app_config.json', 'utf8');
config = JSON.parse(config);

// provide AWS credentials somehow, see http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
// AWS.config.loadFromPath('../bikeshistory/scraper/credentials.aws.js');

//Create DynamoDB client and pass in region.
var db = new AWS.DynamoDB({region: config.AWS_REGION});
//Create SNS client and pass in region.
Expand All @@ -47,32 +50,40 @@ app.post('/signup', function(req, res) {
var nameField = req.body.name,
emailField = req.body.email,
previewBool = req.body.previewAccess;
res.send(200);
signup(nameField, emailField, previewBool);
// res.send(200);
signup(nameField, emailField, previewBool, res);
});

//Add signup form data to database.
var signup = function (nameSubmitted, emailSubmitted, previewPreference) {
var signup = function (nameSubmitted, emailSubmitted, previewPreference, res) {
var formData = {
TableName: config.STARTUP_SIGNUP_TABLE,
Item: {
email: {'S': emailSubmitted},
name: {'S': nameSubmitted},
preview: {'S': previewPreference}
}
},
ConditionExpression: "attribute_not_exists(email)"
};
db.putItem(formData, function(err, data) {
if (err) {
console.log('Error adding item to database: ', err);
if (err.code === 'ConditionalCheckFailedException') {
res.send(409);
} else {
res.send(500);
}
} else {
console.log('Form data added to database.');
var snsMessage = 'New signup: %EMAIL%'; //Send SNS notification containing email from form.
snsMessage = snsMessage.replace('%EMAIL%', formData.Item.email['S']);
sns.publish({ TopicArn: config.NEW_SIGNUP_TOPIC, Message: snsMessage }, function(err, data) {
if (err) {
console.log('Error publishing SNS message: ' + err);
res.send(500);
} else {
console.log('SNS message sent.');
res.send(200);
}
});
}
Expand Down
6 changes: 6 additions & 0 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ block content
$.post( "/signup", $("#signupForm").serialize(),
function(data) {
$("#signupSuccess").show();
$("#signupDuplicate").hide();
$("#signupError").hide();
}
)
.error(function(xhr) {
switch(xhr.status) {
case 409:
$("#signupSuccess").hide();
$("#signupDuplicate").show();
$("#signupError").hide();
break;
default:
$("#signupSuccess").hide();
$("#signupDuplicate").hide();
$("#signupError").show();
}
})
Expand Down