]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/user.js
Server: fix remaining milli seconds before the next requests feature
[github/Chocobozzz/PeerTube.git] / server / models / user.js
index db6f1765b66ddf56ef54b0676c276c48b2455c2c..91e8aeae1c93fa26aaae2fa4fa65692f55c8def6 100644 (file)
@@ -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({
@@ -28,6 +30,7 @@ UserSchema.methods = {
 UserSchema.statics = {
   countTotal: countTotal,
   getByUsername: getByUsername,
+  list: list,
   listForApi: listForApi,
   loadById: loadById,
   loadByUsername: loadByUsername
@@ -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)