Skip to content

Instantly share code, notes, and snippets.

@collin
Last active January 2, 2016 14:49
Show Gist options
  • Save collin/8318983 to your computer and use it in GitHub Desktop.
Save collin/8318983 to your computer and use it in GitHub Desktop.
var confirmationQueue = new Firebase("https://static-showdown.firebaseio.com/email_confirmations");
imaginaryRouter.route("/confirm_email/:code", function(params) {
confirmationQueue.child(params.code).remove();
});
{"rules":{
"email_confirmations": {
".write": "root.child('users').child(auth.userId).child('confirmed').val() == true"
}
}}
var mail = require("nodemailer").mail;
var Firebase = require("firebase");
var base = new Firebase("https://static-showdown.firebaseio.com/");
var mailQueue = base.child("group_invitations");
var confirmationQueue = base.child("email_confirmations");
var users = base.child("users");
mailQueue.on('child_added', function (snapshot) {
confirmationQueue.push({email: snapshot.child('invited_party').val()}, function (snapshot) {
mail({
from: snapshot.child('inviting_party').val(), // sender address
to: snapshot.child('invited_party').val(), // list of receivers
subject: "Join my StaticShowdown Crew", // Subject line
text: "https://staticshowdown.com/#/confirm_email/" + snapshot.name()
}, (error, response) {
if (error) raise "handle error"
mailQueue.child(snapshot.name()).remove()
});
})
});
confirmationQueue.on('child_removed', function (snapshot) {
var email = snapshot.child('email').val();
users.child(email).child('confirmed').set(true);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment