   password:
     type: String
     required: true
-    set: (password) ->
-      return unless password
-      salt = bcrypt.genSaltSync()
-      bcrypt.hashSync password, salt
-  activated: 
+  activated:
     type: Boolean
     default: false
   last_active:

Schema = mongoose.Schema

userSchema = new Schema
  name: 
    type: String
    required: true
  email: 
    type: String
    required: true
    lowercase: true

  /^(?=[^\d_].*?\d)\w(\w|[!@#$%]){5,20}/.test value
, 'Your password must be between 6–20 characters, start with a letter, and include a number.'

userSchema.post 'validate', ->
  @password = bcrypt.hashSync @password, bcrypt.genSaltSync()

userSchema.plugin uniqueValidator, message: '“{VALUE}” is already a user.'

userSchema.set 'toJSON', virtuals: true

module.exports = db.model 'User', userSchema
