Skip to content

Commit c798dc8

Browse files
committed
Replace deprecated beforeCreate with 'before save' observer
1 parent 3fbdecd commit c798dc8

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

common/models/user.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
module.exports = function(user) {
1+
module.exports = function (user) {
22

3-
user.beforeCreate = function(next, user) {
4-
if (user.username == undefined) {
5-
user.username = user.email;
3+
// Set the username to the users email address by default.
4+
user.observe('before save', function setDefaultUsername(ctx, next) {
5+
if (ctx.instance) {
6+
if (ctx.instance.username === undefined) {
7+
ctx.instance.username = ctx.instance.email;
8+
}
9+
ctx.instance.status = 'created';
10+
ctx.instance.created = Date.now();
11+
ctx.instance.confirmPassword = null;
612
}
7-
user.status = 'created';
8-
user.created = Date.now();
913
next();
10-
};
11-
14+
});
1215

1316
};

0 commit comments

Comments
 (0)