       roles: [{type: 'ObjectId', ref: 'Role'}]
     options:
       strict: false
-      
+
   schema = dal.schemaFactory modelDefinition
   modelDefinition.schema = schema
 

        @apiSecret = buf.toString 'base64'
        @save callback

 
  schema.pre 'save', (next) ->
    user = @


      else
        callback 'cannot find user'

  create = (json, callback) ->
    crud.findOneBy 'email', json.email, json.systemId , (err, user) ->
      if err and err isnt "Cannot find User"
        callback err, null
      else if user?
        callback 'Username already exists'
      else
        crud.create json, callback

  exports = gi.common.extend {}, crud
  exports.update = update
  exports.findOrCreate = findOrCreate
  exports.findOneByProviderId = findOneByProviderId
  exports.resetAPISecret = resetAPISecret
  exports.comparePassword = comparePassword
  exports.create = create
  exports
