meteor/meteor — pull request #270 by stephentcannon (2012-08-11 18:51:46+00:00)
Title: Auth branch added preLogin and postLogin hook

I added a preLogin and postLogin hook to the auth branch to allow someone to intercept and refuse a login both before or after Meteor processes it.

Business use cases:
1. Provides a way for a business to have active/Inactive users instead of deleting them to keep the user record and any audit log trails for the user within the application.

2. Provides for business use cases like day of week or time of day login limitations or any time frame for that matter including trial or temporary accounts.

3. Provides for any potential business use case a business may have.

I believe this feature will be important for any eCommerce, Business or Financial Services type applications being built with Meteor. We will be using it for a Retail Point of Sale System and a Gift Card Management System being built on top of Meteor.

Example usage server side for users.active = boolean.

Meteor.accounts.preLogin(function(options){
console.log('Meteor.accounts.preLogin');
if(options.resume){
var loginToken = Meteor.accounts._loginTokens.findOne({_id: options.resume});
if (loginToken){
if(!Meteor.users.findOne({_id: loginToken.userId, active: true})){
return false;
}
}
}
return true;
});

Meteor.accounts.postLogin(function(result){
console.log('Meteor.accounts.postLogin');
if(!Meteor.users.findOne({_id: result.id, active: true})){
return false;
} else {
return true;
}
});

Thanks
Steeve