Created
March 18, 2014 19:03
-
-
Save npfitz/9627090 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
var bcrypt = require('bcrypt-nodejs'); | |
module.exports = { | |
migrate: 'alter', | |
schema: true, | |
attributes: { | |
first_name: { | |
type:'string', | |
required: true, | |
minLength: 2, | |
maxLength: 40 | |
}, | |
last_name: { | |
type:'string', | |
required: true, | |
minLength: 2, | |
maxLength: 40 | |
}, | |
password: { | |
type:'string', | |
required: true, | |
minLength: 8, | |
}, | |
email: { | |
type:'string', | |
required: true, | |
email: true, | |
unique: true | |
}, | |
title: { | |
type:'string', | |
defaultsTo:'Mystery User' | |
}, | |
work_phone: { | |
type: 'string' | |
}, | |
cell_phone: { | |
type: 'string' | |
}, | |
profile_pic: { | |
type: 'string', | |
defaultsTo: 'Default/default.jpeg' | |
}, | |
role: { | |
type: 'string', | |
defaultsTo: 'internal' | |
}, | |
//Account ID for the account object the user belongs to | |
account: { | |
model: "account" | |
}, | |
//All Projects that the user currently has access to | |
projects: { | |
collection: "project", | |
via: "users" | |
} | |
}, | |
//Encrypt password before storage | |
beforeCreate: function(values, next) { | |
var salt = bcrypt.genSaltSync(10); | |
bcrypt.hash(values.password, salt, null, function(err, hash) { | |
if(err) return next(err); | |
values.password = hash; | |
next(); | |
}); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment