const modelUtils = require('./utils')
const peertubeCrypto = require('../helpers/peertube-crypto')
+const OAuthToken = mongoose.model('OAuthToken')
+
// ---------------------------------------------------------------------------
const UserSchema = mongoose.Schema({
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) {
})
})
+UserSchema.pre('remove', function (next) {
+ const user = this
+
+ OAuthToken.removeByUserId(user._id, next)
+})
+
mongoose.model('User', UserSchema)
// ------------------------------ METHODS ------------------------------
return {
id: this._id,
username: this.username,
- role: this.role
+ role: this.role,
+ createdDate: this.createdDate
}
}
// ------------------------------ STATICS ------------------------------
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)