X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fuser.js;h=a19de7072cd77ae5e881297e775f25c829ab45aa;hb=55723d16fd0e323ce7175db8c4806c73d18b895d;hp=e76aab2ce5ad25d1459b90c9a7423cce8acef7d7;hpb=26d7d31ba3b1d26ea9a51e8626e4a4537867db94;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/user.js b/server/models/user.js index e76aab2ce..a19de7072 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -4,6 +4,8 @@ const customUsersValidators = require('../helpers/custom-validators').users const modelUtils = require('./utils') const peertubeCrypto = require('../helpers/peertube-crypto') +const OAuthToken = mongoose.model('OAuthToken') + // --------------------------------------------------------------------------- const UserSchema = mongoose.Schema({ @@ -21,16 +23,17 @@ UserSchema.path('username').required(customUsersValidators.isUserUsernameValid) UserSchema.path('role').validate(customUsersValidators.isUserRoleValid) UserSchema.methods = { - isPasswordMatch: isPasswordMatch, - toFormatedJSON: toFormatedJSON + isPasswordMatch, + toFormatedJSON } UserSchema.statics = { - countTotal: countTotal, - getByUsername: getByUsername, - listForApi: listForApi, - loadById: loadById, - loadByUsername: loadByUsername + countTotal, + getByUsername, + list, + listForApi, + loadById, + loadByUsername } UserSchema.pre('save', function (next) { @@ -45,6 +48,12 @@ UserSchema.pre('save', function (next) { }) }) +UserSchema.pre('remove', function (next) { + const user = this + + OAuthToken.removeByUserId(user._id, next) +}) + mongoose.model('User', UserSchema) // ------------------------------ METHODS ------------------------------ @@ -57,7 +66,8 @@ function toFormatedJSON () { return { id: this._id, username: this.username, - role: this.role + role: this.role, + createdDate: this.createdDate } } // ------------------------------ STATICS ------------------------------ @@ -70,6 +80,10 @@ function getByUsername (username) { return this.findOne({ username: username }) } +function list (callback) { + return this.find(callback) +} + function listForApi (start, count, sort, callback) { const query = {} return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback)