]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/user.js
1 const mongoose
= require('mongoose')
3 const customUsersValidators
= require('../helpers/custom-validators').users
5 // ---------------------------------------------------------------------------
7 const UserSchema
= mongoose
.Schema({
13 UserSchema
.path('password').required(customUsersValidators
.isUserPasswordValid
)
14 UserSchema
.path('username').required(customUsersValidators
.isUserUsernameValid
)
15 UserSchema
.path('role').validate(customUsersValidators
.isUserRoleValid
)
17 UserSchema
.methods
= {
18 toFormatedJSON: toFormatedJSON
21 UserSchema
.statics
= {
22 getByUsernameAndPassword: getByUsernameAndPassword
,
24 loadByUsername: loadByUsername
27 mongoose
.model('User', UserSchema
)
29 // ---------------------------------------------------------------------------
31 function getByUsernameAndPassword (username
, password
) {
32 return this.findOne({ username: username
, password: password
})
35 function list (callback
) {
36 return this.find(callback
)
39 function loadByUsername (username
, callback
) {
40 return this.findOne({ username: username
}, callback
)
43 function toFormatedJSON () {
46 username: this.username
,