mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Implement user API (create, update, remove, list)
This commit is contained in:
parent
e4c556196d
commit
9bd2662976
16 changed files with 688 additions and 47 deletions
|
@ -1,28 +1,49 @@
|
|||
const mongoose = require('mongoose')
|
||||
|
||||
const customUsersValidators = require('../helpers/custom-validators').users
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const UserSchema = mongoose.Schema({
|
||||
password: String,
|
||||
username: String
|
||||
username: String,
|
||||
role: String
|
||||
})
|
||||
|
||||
UserSchema.path('password').required(true)
|
||||
UserSchema.path('username').required(true)
|
||||
UserSchema.path('password').required(customUsersValidators.isUserPasswordValid)
|
||||
UserSchema.path('username').required(customUsersValidators.isUserUsernameValid)
|
||||
UserSchema.path('role').validate(customUsersValidators.isUserRoleValid)
|
||||
|
||||
UserSchema.methods = {
|
||||
toFormatedJSON: toFormatedJSON
|
||||
}
|
||||
|
||||
UserSchema.statics = {
|
||||
getByUsernameAndPassword: getByUsernameAndPassword,
|
||||
list: list
|
||||
list: list,
|
||||
loadByUsername: loadByUsername
|
||||
}
|
||||
|
||||
mongoose.model('User', UserSchema)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getByUsernameAndPassword (username, password) {
|
||||
return this.findOne({ username: username, password: password })
|
||||
}
|
||||
|
||||
function list (callback) {
|
||||
return this.find(callback)
|
||||
}
|
||||
|
||||
function getByUsernameAndPassword (username, password) {
|
||||
return this.findOne({ username: username, password: password })
|
||||
function loadByUsername (username, callback) {
|
||||
return this.findOne({ username: username }, callback)
|
||||
}
|
||||
|
||||
function toFormatedJSON () {
|
||||
return {
|
||||
id: this._id,
|
||||
username: this.username,
|
||||
role: this.role
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue