aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth-client.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-11 21:50:51 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-19 21:22:28 +0100
commitfeb4bdfd9b46e87aadfa7c0d5338cde887d1f58c (patch)
tree2abc9fbc9569760e218fd52835850b757344b420 /server/models/oauth-client.js
parent108626609eda75e4ecc0a83a650a4d53c46220e0 (diff)
downloadPeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.tar.gz
PeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.tar.zst
PeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.zip
First version with PostgreSQL
Diffstat (limited to 'server/models/oauth-client.js')
-rw-r--r--server/models/oauth-client.js72
1 files changed, 51 insertions, 21 deletions
diff --git a/server/models/oauth-client.js b/server/models/oauth-client.js
index a1aefa985..15118591a 100644
--- a/server/models/oauth-client.js
+++ b/server/models/oauth-client.js
@@ -1,33 +1,63 @@
1const mongoose = require('mongoose') 1module.exports = function (sequelize, DataTypes) {
2 2 const OAuthClient = sequelize.define('OAuthClient',
3// --------------------------------------------------------------------------- 3 {
4 4 clientId: {
5const OAuthClientSchema = mongoose.Schema({ 5 type: DataTypes.STRING
6 clientSecret: String, 6 },
7 grants: Array, 7 clientSecret: {
8 redirectUris: Array 8 type: DataTypes.STRING
9}) 9 },
10 10 grants: {
11OAuthClientSchema.path('clientSecret').required(true) 11 type: DataTypes.ARRAY(DataTypes.STRING)
12 12 },
13OAuthClientSchema.statics = { 13 redirectUris: {
14 getByIdAndSecret, 14 type: DataTypes.ARRAY(DataTypes.STRING)
15 list, 15 }
16 loadFirstClient 16 },
17 {
18 classMethods: {
19 associate,
20
21 getByIdAndSecret,
22 list,
23 loadFirstClient
24 }
25 }
26 )
27
28 return OAuthClient
17} 29}
18 30
19mongoose.model('OAuthClient', OAuthClientSchema) 31// TODO: validation
32// OAuthClientSchema.path('clientSecret').required(true)
20 33
21// --------------------------------------------------------------------------- 34// ---------------------------------------------------------------------------
22 35
36function associate (models) {
37 this.hasMany(models.OAuthToken, {
38 foreignKey: {
39 name: 'oAuthClientId',
40 allowNull: false
41 },
42 onDelete: 'cascade'
43 })
44}
45
23function list (callback) { 46function list (callback) {
24 return this.find(callback) 47 return this.findAll().asCallback(callback)
25} 48}
26 49
27function loadFirstClient (callback) { 50function loadFirstClient (callback) {
28 return this.findOne({}, callback) 51 return this.findOne().asCallback(callback)
29} 52}
30 53
31function getByIdAndSecret (id, clientSecret) { 54function getByIdAndSecret (clientId, clientSecret) {
32 return this.findOne({ _id: id, clientSecret: clientSecret }).exec() 55 const query = {
56 where: {
57 clientId: clientId,
58 clientSecret: clientSecret
59 }
60 }
61
62 return this.findOne(query)
33} 63}