Last active
January 2, 2016 14:49
-
-
Save collin/8318983 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var confirmationQueue = new Firebase("https://static-showdown.firebaseio.com/email_confirmations"); | |
imaginaryRouter.route("/confirm_email/:code", function(params) { | |
confirmationQueue.child(params.code).remove(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"rules":{ | |
"email_confirmations": { | |
".write": "root.child('users').child(auth.userId).child('confirmed').val() == true" | |
} | |
}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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