user.js
774 Bytes
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
// # models - user
var mongoose = require('mongoose')
var common = require('./common')
var Schema = mongoose.Schema
var mongooseTypes = require('nifty-mongoose-types')
var jsonSelect = require('mongoose-json-select')
var passportLocalMongoose = require('passport-local-mongoose')
mongooseTypes.loadTypes(mongoose)
var Email = mongoose.SchemaTypes.Email
var User = new Schema({
email: {
type: Email,
required: true,
unique: true
}
})
User.plugin(common)
User.virtual('type').get(function() {
return 'User'
})
User.plugin(common)
User.plugin(passportLocalMongoose, {
usernameField: 'email',
usernameLowerCase: true,
userExistsError: 'User already exists with email %s'
})
User.plugin(jsonSelect, '-_group -salt -hash')
module.exports = User