aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth-client.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-12 15:20:03 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-12 15:20:03 +0100
commit99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch)
treec9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/models/oauth-client.js
parentfcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff)
parent91cc839af88730ba55f84997c56b85ea100070a7 (diff)
downloadPeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz
PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst
PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip
Merge branch 'postgresql'
Diffstat (limited to 'server/models/oauth-client.js')
-rw-r--r--server/models/oauth-client.js75
1 files changed, 52 insertions, 23 deletions
diff --git a/server/models/oauth-client.js b/server/models/oauth-client.js
index a1aefa985..021a34007 100644
--- a/server/models/oauth-client.js
+++ b/server/models/oauth-client.js
@@ -1,33 +1,62 @@
1const mongoose = require('mongoose') 1'use strict'
2 2
3// --------------------------------------------------------------------------- 3module.exports = function (sequelize, DataTypes) {
4 4 const OAuthClient = sequelize.define('OAuthClient',
5const OAuthClientSchema = mongoose.Schema({ 5 {
6 clientSecret: String, 6 clientId: {
7 grants: Array, 7 type: DataTypes.STRING,
8 redirectUris: Array 8 allowNull: false
9}) 9 },
10 10 clientSecret: {
11OAuthClientSchema.path('clientSecret').required(true) 11 type: DataTypes.STRING,
12 12 allowNull: false
13OAuthClientSchema.statics = { 13 },
14 getByIdAndSecret, 14 grants: {
15 list, 15 type: DataTypes.ARRAY(DataTypes.STRING)
16 loadFirstClient 16 },
17 redirectUris: {
18 type: DataTypes.ARRAY(DataTypes.STRING)
19 }
20 },
21 {
22 indexes: [
23 {
24 fields: [ 'clientId' ],
25 unique: true
26 },
27 {
28 fields: [ 'clientId', 'clientSecret' ],
29 unique: true
30 }
31 ],
32 classMethods: {
33 countTotal,
34 getByIdAndSecret,
35 loadFirstClient
36 }
37 }
38 )
39
40 return OAuthClient
17} 41}
18 42
19mongoose.model('OAuthClient', OAuthClientSchema)
20
21// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------
22 44
23function list (callback) { 45function countTotal (callback) {
24 return this.find(callback) 46 return this.count().asCallback(callback)
25} 47}
26 48
27function loadFirstClient (callback) { 49function loadFirstClient (callback) {
28 return this.findOne({}, callback) 50 return this.findOne().asCallback(callback)
29} 51}
30 52
31function getByIdAndSecret (id, clientSecret) { 53function getByIdAndSecret (clientId, clientSecret) {
32 return this.findOne({ _id: id, clientSecret: clientSecret }).exec() 54 const query = {
55 where: {
56 clientId: clientId,
57 clientSecret: clientSecret
58 }
59 }
60
61 return this.findOne(query)
33} 62}