mirror of https://github.com/Chocobozzz/PeerTube
Server: when we remove a user, remove the oauthtokens too
parent
0eb78d5303
commit
b81929a014
|
@ -20,7 +20,8 @@ OAuthTokenSchema.path('user').required(true)
|
||||||
OAuthTokenSchema.statics = {
|
OAuthTokenSchema.statics = {
|
||||||
getByRefreshTokenAndPopulateClient: getByRefreshTokenAndPopulateClient,
|
getByRefreshTokenAndPopulateClient: getByRefreshTokenAndPopulateClient,
|
||||||
getByTokenAndPopulateUser: getByTokenAndPopulateUser,
|
getByTokenAndPopulateUser: getByTokenAndPopulateUser,
|
||||||
getByRefreshToken: getByRefreshToken
|
getByRefreshToken: getByRefreshToken,
|
||||||
|
removeByUserId: removeByUserId
|
||||||
}
|
}
|
||||||
|
|
||||||
mongoose.model('OAuthToken', OAuthTokenSchema)
|
mongoose.model('OAuthToken', OAuthTokenSchema)
|
||||||
|
@ -53,3 +54,7 @@ function getByTokenAndPopulateUser (bearerToken) {
|
||||||
function getByRefreshToken (refreshToken) {
|
function getByRefreshToken (refreshToken) {
|
||||||
return this.findOne({ refreshToken: refreshToken }).exec()
|
return this.findOne({ refreshToken: refreshToken }).exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeByUserId (userId, callback) {
|
||||||
|
return this.remove({ user: userId }, callback)
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ const customUsersValidators = require('../helpers/custom-validators').users
|
||||||
const modelUtils = require('./utils')
|
const modelUtils = require('./utils')
|
||||||
const peertubeCrypto = require('../helpers/peertube-crypto')
|
const peertubeCrypto = require('../helpers/peertube-crypto')
|
||||||
|
|
||||||
|
const OAuthToken = mongoose.model('OAuthToken')
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const UserSchema = mongoose.Schema({
|
const UserSchema = mongoose.Schema({
|
||||||
|
@ -46,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)
|
mongoose.model('User', UserSchema)
|
||||||
|
|
||||||
// ------------------------------ METHODS ------------------------------
|
// ------------------------------ METHODS ------------------------------
|
||||||
|
|
Loading…
Reference in New Issue