]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/user.js
d289da19af804615ee1f075409a5fa760c2189ea
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
= {
23 getByUsernameAndPassword: getByUsernameAndPassword
,
26 loadByUsername: loadByUsername
29 mongoose
.model('User', UserSchema
)
31 // ---------------------------------------------------------------------------
33 function count (callback
) {
34 return this.count(callback
)
37 function getByUsernameAndPassword (username
, password
) {
38 return this.findOne({ username: username
, password: password
})
41 function list (callback
) {
42 return this.find(callback
)
45 function loadById (id
, callback
) {
46 return this.findById(id
, callback
)
49 function loadByUsername (username
, callback
) {
50 return this.findOne({ username: username
}, callback
)
53 function toFormatedJSON () {
56 username: this.username
,