Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = {
- attributes: {
- firstName: {
- type: 'string',
- required: true
- },
- lastName: {
- type: 'string',
- required: true
- },
- fullName: function() {
- return this.firstName + " " + this.lastName;
- },
- email: {
- type: 'email',
- required: true,
- unique: true
- },
- encryptedPassword: {
- type: 'string'
- },
- role: {
- model: 'role'
- },
- groups: {
- collection: 'group',
- via: 'users'
- }
- },
- toJSON: function() {
- var obj = this.toObject();
- delete obj.password;
- delete obj.confirmation;
- delete obj._csrf;
- return obj;
- },
- beforeCreate: function (values, next) {
- // Makes sure the password and password confirmation match
- if (!values.password || values.password != values.confirmation) {
- return next({err: ['Password does not match password confirmation.']});
- }
- // Encrypts the password/confirmation to be stored in the db
- require('bcrypt').hash(values.password, 10, function passwordEncrypted(err, encryptedPassword) {
- values.encryptedPassword = encryptedPassword;
- next();
- });
- }
- };
- module.exports = {
- attributes: {
- name: {
- type: 'string',
- required: true,
- unique: true
- },
- users: {
- collection: 'user',
- via: 'role'
- },
- permissions: {
- collection: 'permission',
- via: 'roles',
- dominant: true
- }
- }
- };
- User.findOne(1).populate('role').exec(function(err, user) {
- if (err) {throw new Error(err);}
- console.log(user.role.name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement