Code coverage report for api/models/User.js

Statements: 100% (15 / 15)      Branches: 100% (4 / 4)      Functions: 100% (4 / 4)      Lines: 100% (13 / 13)      Ignored: 2 statements, 2 branches     

All files » api/models/ » User.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75              1                                                   3 3 3 3 3                                       3   3   3   3   3   3 3            
/**
* Users.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs        :: http://sailsjs.org/#!documentation/models
*/
 
module.exports = {
  schema:true,
 
  attributes: {
    name: {
      type: 'string',
      required: true
    },
    password: {
      type: 'string',
      required: true,
      minLength: 6
    },
    email: {
      type: 'string',
      email: true,
      unique: true,
      required: true
    },
    // Add a reference to User
    projects: {
        collection: 'project',
        via: 'members',
        dominant:true
    },
    toJSON: function(){
      var obj = this.toObject()
      delete obj.password;
      delete obj.admin;
      delete obj._csrf;
      return obj;
    }
  },
 
  validation_messages: {
    name: {
        required: 'you have to specify a name'
    },
    email: {
      email: 'invalid email, bro',
      unique: 'email alreay exists, don\'t try to use the same email to signup again',
      required: 'you have to specify a email'
    },
    password:{
      required: "you forgot the password",
      minLength: "password too short! 6 charater at minimum"
    }
  },
 
  beforeCreate: function (attrs, next) {
    var bcrypt = require('bcrypt');
 
    bcrypt.genSalt(10, function(err, salt) {
      /* istanbul ignore next */
      Iif (err) return next(err);
 
      bcrypt.hash(attrs.password, salt, function(err, hash) {
        /* istanbul ignore next */
        Iif (err) return next(err);
 
        attrs.password = hash;
        next();
      });
    });
  }
};