X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fuser.js;h=a19de7072cd77ae5e881297e775f25c829ab45aa;hb=8eb7d0fa0974995d3cfb8a440d72222cc18cd77d;hp=db6f1765b66ddf56ef54b0676c276c48b2455c2c;hpb=d74a0680f72021f82c2718cbf6c490a7715a9e35;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/user.js b/server/models/user.js index db6f1765b..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 ------------------------------ @@ -71,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)