mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
OAuth/User models refractoring -> use mongoose api
This commit is contained in:
parent
a3ee6fa22d
commit
69b0a27cbb
14 changed files with 217 additions and 156 deletions
34
server/models/oauth-token.js
Normal file
34
server/models/oauth-token.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const mongoose = require('mongoose')
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const OAuthTokenSchema = mongoose.Schema({
|
||||
accessToken: String,
|
||||
accessTokenExpiresOn: Date,
|
||||
client: { type: mongoose.Schema.Types.ObjectId, ref: 'OAuthClient' },
|
||||
refreshToken: String,
|
||||
refreshTokenExpiresOn: Date,
|
||||
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
||||
})
|
||||
|
||||
OAuthTokenSchema.path('accessToken').required(true)
|
||||
OAuthTokenSchema.path('client').required(true)
|
||||
OAuthTokenSchema.path('user').required(true)
|
||||
|
||||
OAuthTokenSchema.statics = {
|
||||
loadByRefreshToken: loadByRefreshToken,
|
||||
loadByTokenAndPopulateUser: loadByTokenAndPopulateUser
|
||||
}
|
||||
|
||||
mongoose.model('OAuthToken', OAuthTokenSchema)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function loadByRefreshToken (refreshToken, callback) {
|
||||
return this.findOne({ refreshToken: refreshToken }, callback)
|
||||
}
|
||||
|
||||
function loadByTokenAndPopulateUser (bearerToken, callback) {
|
||||
// FIXME: allow to use callback
|
||||
return this.findOne({ accessToken: bearerToken }).populate('user')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue