Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.

Commit

Permalink
Replace deprecated beforeCreate with 'before save' observer
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed May 30, 2015
1 parent 3fbdecd commit c798dc8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions common/models/user.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module.exports = function(user) {
module.exports = function (user) {

user.beforeCreate = function(next, user) {
if (user.username == undefined) {
user.username = user.email;
// Set the username to the users email address by default.
user.observe('before save', function setDefaultUsername(ctx, next) {
if (ctx.instance) {
if (ctx.instance.username === undefined) {
ctx.instance.username = ctx.instance.email;
}
ctx.instance.status = 'created';
ctx.instance.created = Date.now();
ctx.instance.confirmPassword = null;
}
user.status = 'created';
user.created = Date.now();
next();
};

});

};

0 comments on commit c798dc8

Please sign in to comment.