aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-04 22:32:36 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-04 22:33:38 +0200
commit9bd2662976a75d3b03364cdbe6419e57c80f99a6 (patch)
tree0b5289660f843a8ba7f13aa79d458f53c94b36d9 /server/models/user.js
parente4c556196d7b31111f17596840d2e1d60caa7dcb (diff)
downloadPeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.tar.gz
PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.tar.zst
PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.zip
Implement user API (create, update, remove, list)
Diffstat (limited to 'server/models/user.js')
-rw-r--r--server/models/user.js33
1 files changed, 27 insertions, 6 deletions
diff --git a/server/models/user.js b/server/models/user.js
index 14ffecbff..0bbd638d4 100644
--- a/server/models/user.js
+++ b/server/models/user.js
@@ -1,28 +1,49 @@
1const mongoose = require('mongoose') 1const mongoose = require('mongoose')
2 2
3const customUsersValidators = require('../helpers/custom-validators').users
4
3// --------------------------------------------------------------------------- 5// ---------------------------------------------------------------------------
4 6
5const UserSchema = mongoose.Schema({ 7const UserSchema = mongoose.Schema({
6 password: String, 8 password: String,
7 username: String 9 username: String,
10 role: String
8}) 11})
9 12
10UserSchema.path('password').required(true) 13UserSchema.path('password').required(customUsersValidators.isUserPasswordValid)
11UserSchema.path('username').required(true) 14UserSchema.path('username').required(customUsersValidators.isUserUsernameValid)
15UserSchema.path('role').validate(customUsersValidators.isUserRoleValid)
16
17UserSchema.methods = {
18 toFormatedJSON: toFormatedJSON
19}
12 20
13UserSchema.statics = { 21UserSchema.statics = {
14 getByUsernameAndPassword: getByUsernameAndPassword, 22 getByUsernameAndPassword: getByUsernameAndPassword,
15 list: list 23 list: list,
24 loadByUsername: loadByUsername
16} 25}
17 26
18mongoose.model('User', UserSchema) 27mongoose.model('User', UserSchema)
19 28
20// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
21 30
31function getByUsernameAndPassword (username, password) {
32 return this.findOne({ username: username, password: password })
33}
34
22function list (callback) { 35function list (callback) {
23 return this.find(callback) 36 return this.find(callback)
24} 37}
25 38
26function getByUsernameAndPassword (username, password) { 39function loadByUsername (username, callback) {
27 return this.findOne({ username: username, password: password }) 40 return this.findOne({ username: username }, callback)
41}
42
43function toFormatedJSON () {
44 return {
45 id: this._id,
46 username: this.username,
47 role: this.role
48 }
28} 49}