Created
January 24, 2013 00:47
-
-
Save mdedetrich/4616438 to your computer and use it in GitHub Desktop.
This file contains 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
addNewUser:(token) -> | |
errorMessage = 'User no longer exists, try registering again!' | |
async.parallel( | |
user: (cb) -> db.pendingUsers.findOne(token:token,(err,result)-> | |
if !result? then cb(errorMessage) else cb(err,result) | |
) | |
group: (cb) -> db.pendingGroups.findOne(token:token,(err,result)-> | |
if !result? then cb(errorMessage) else cb(err,result) | |
) | |
,(err,results)-> | |
if !err | |
delete results.user.token | |
delete results.group.token | |
results.user.avatar = globals.defaultUserAvatarID | |
results.group.avatar = globals.defaultGroupAvatarID | |
results.user.pages = [] | |
time = new Date | |
results.user.time = time | |
results.group.time = time | |
async.parallel( | |
addData: (cb) -> | |
async.waterfall([ | |
(cb) -> db.users.insert(results.user,cb) | |
(users,cb) -> | |
results.group.users = [users[0]._id] | |
db.groups.insert(results.group,(err,results)-> | |
cb(err,users[0]._id,results[0]._id) | |
) | |
(userID,groupID,cb) -> | |
db.users.findAndModify({_id:userID},{},{ | |
$set:{groupID: groupID} | |
},{},(err)-> | |
cb(err,groupID,userID) | |
) | |
(groupID,userID,cb)-> | |
# create default facebook application | |
db.facebookApplications.add(groupID,{fbAppID: config.get('defaultFBAppID'),fbAppSecret: config.get('defaultFbAppSecret')},(err,result)-> | |
cb(err,userID,groupID,result._id) | |
) | |
(userID,groupID,facebookApplicationID,cb) -> | |
db.groups.findAndModify(_id:groupID,{},$set:{facebookApplications:[facebookApplicationID]},{},(err)-> | |
cb(err,userID,facebookApplicationID) | |
) | |
(userID,facebookApplicationID,cb) -> | |
db.notifications.addDefault(userID,facebookApplicationID,true,cb) | |
],(err,results)-> | |
cb(err,results) | |
) | |
cleanPending: (cb) -> | |
async.parallel( | |
user: (cb) -> db.pendingUsers.remove({token:token},safe:true,cb) | |
group: (cb) -> db.pendingGroups.remove({token:token}, safe:true,cb) | |
,(err,result)-> | |
cb(err,result) | |
) | |
,(err)-> | |
if !err | |
res 'Activated User' | |
else | |
res error:errorMessage | |
) | |
else | |
res error:errorMessage | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment