aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/models/oauth-token.js7
-rw-r--r--server/models/user.js8
2 files changed, 14 insertions, 1 deletions
diff --git a/server/models/oauth-token.js b/server/models/oauth-token.js
index f6a814c36..d53fdcf31 100644
--- a/server/models/oauth-token.js
+++ b/server/models/oauth-token.js
@@ -20,7 +20,8 @@ OAuthTokenSchema.path('user').required(true)
20OAuthTokenSchema.statics = { 20OAuthTokenSchema.statics = {
21 getByRefreshTokenAndPopulateClient: getByRefreshTokenAndPopulateClient, 21 getByRefreshTokenAndPopulateClient: getByRefreshTokenAndPopulateClient,
22 getByTokenAndPopulateUser: getByTokenAndPopulateUser, 22 getByTokenAndPopulateUser: getByTokenAndPopulateUser,
23 getByRefreshToken: getByRefreshToken 23 getByRefreshToken: getByRefreshToken,
24 removeByUserId: removeByUserId
24} 25}
25 26
26mongoose.model('OAuthToken', OAuthTokenSchema) 27mongoose.model('OAuthToken', OAuthTokenSchema)
@@ -53,3 +54,7 @@ function getByTokenAndPopulateUser (bearerToken) {
53function getByRefreshToken (refreshToken) { 54function getByRefreshToken (refreshToken) {
54 return this.findOne({ refreshToken: refreshToken }).exec() 55 return this.findOne({ refreshToken: refreshToken }).exec()
55} 56}
57
58function removeByUserId (userId, callback) {
59 return this.remove({ user: userId }, callback)
60}
diff --git a/server/models/user.js b/server/models/user.js
index c2c8807f0..91e8aeae1 100644
--- a/server/models/user.js
+++ b/server/models/user.js
@@ -4,6 +4,8 @@ const customUsersValidators = require('../helpers/custom-validators').users
4const modelUtils = require('./utils') 4const modelUtils = require('./utils')
5const peertubeCrypto = require('../helpers/peertube-crypto') 5const peertubeCrypto = require('../helpers/peertube-crypto')
6 6
7const OAuthToken = mongoose.model('OAuthToken')
8
7// --------------------------------------------------------------------------- 9// ---------------------------------------------------------------------------
8 10
9const UserSchema = mongoose.Schema({ 11const UserSchema = mongoose.Schema({
@@ -46,6 +48,12 @@ UserSchema.pre('save', function (next) {
46 }) 48 })
47}) 49})
48 50
51UserSchema.pre('remove', function (next) {
52 const user = this
53
54 OAuthToken.removeByUserId(user._id, next)
55})
56
49mongoose.model('User', UserSchema) 57mongoose.model('User', UserSchema)
50 58
51// ------------------------------ METHODS ------------------------------ 59// ------------------------------ METHODS ------------------------------