diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-07-01 16:03:53 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-07-01 16:03:53 +0200 |
commit | 69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd (patch) | |
tree | 8659f819818a3da6419959b6b7838a7f0557c948 /server/initializers | |
parent | a3ee6fa22dee4b68fcde9cd23708b471db446e11 (diff) | |
download | PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.tar.gz PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.tar.zst PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.zip |
OAuth/User models refractoring -> use mongoose api
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/checker.js | 8 | ||||
-rw-r--r-- | server/initializers/database.js | 3 | ||||
-rw-r--r-- | server/initializers/installer.js | 27 |
3 files changed, 28 insertions, 10 deletions
diff --git a/server/initializers/checker.js b/server/initializers/checker.js index 7a2b5b132..3831efb8d 100644 --- a/server/initializers/checker.js +++ b/server/initializers/checker.js | |||
@@ -1,8 +1,10 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const config = require('config') | 3 | const config = require('config') |
4 | const mongoose = require('mongoose') | ||
4 | 5 | ||
5 | const Users = require('../models/users') | 6 | const Client = mongoose.model('OAuthClient') |
7 | const User = mongoose.model('User') | ||
6 | 8 | ||
7 | const checker = { | 9 | const checker = { |
8 | checkConfig: checkConfig, | 10 | checkConfig: checkConfig, |
@@ -29,7 +31,7 @@ function checkConfig () { | |||
29 | } | 31 | } |
30 | 32 | ||
31 | function clientsExist (callback) { | 33 | function clientsExist (callback) { |
32 | Users.getClients(function (err, clients) { | 34 | Client.list(function (err, clients) { |
33 | if (err) return callback(err) | 35 | if (err) return callback(err) |
34 | 36 | ||
35 | return callback(null, clients.length !== 0) | 37 | return callback(null, clients.length !== 0) |
@@ -37,7 +39,7 @@ function clientsExist (callback) { | |||
37 | } | 39 | } |
38 | 40 | ||
39 | function usersExist (callback) { | 41 | function usersExist (callback) { |
40 | Users.getUsers(function (err, users) { | 42 | User.list(function (err, users) { |
41 | if (err) return callback(err) | 43 | if (err) return callback(err) |
42 | 44 | ||
43 | return callback(null, users.length !== 0) | 45 | return callback(null, users.length !== 0) |
diff --git a/server/initializers/database.js b/server/initializers/database.js index e97531781..4a19bc230 100644 --- a/server/initializers/database.js +++ b/server/initializers/database.js | |||
@@ -6,6 +6,9 @@ const mongoose = require('mongoose') | |||
6 | const logger = require('../helpers/logger') | 6 | const logger = require('../helpers/logger') |
7 | 7 | ||
8 | // Bootstrap models | 8 | // Bootstrap models |
9 | require('../models/user') | ||
10 | require('../models/oauth-client') | ||
11 | require('../models/oauth-token') | ||
9 | require('../models/pods') | 12 | require('../models/pods') |
10 | require('../models/video') | 13 | require('../models/video') |
11 | // Request model needs Video model | 14 | // Request model needs Video model |
diff --git a/server/initializers/installer.js b/server/initializers/installer.js index 059fcd8d8..e0ae822cf 100644 --- a/server/initializers/installer.js +++ b/server/initializers/installer.js | |||
@@ -3,13 +3,16 @@ | |||
3 | const async = require('async') | 3 | const async = require('async') |
4 | const config = require('config') | 4 | const config = require('config') |
5 | const mkdirp = require('mkdirp') | 5 | const mkdirp = require('mkdirp') |
6 | const mongoose = require('mongoose') | ||
6 | const passwordGenerator = require('password-generator') | 7 | const passwordGenerator = require('password-generator') |
7 | const path = require('path') | 8 | const path = require('path') |
8 | 9 | ||
9 | const checker = require('./checker') | 10 | const checker = require('./checker') |
10 | const logger = require('../helpers/logger') | 11 | const logger = require('../helpers/logger') |
11 | const peertubeCrypto = require('../helpers/peertubeCrypto') | 12 | const peertubeCrypto = require('../helpers/peertubeCrypto') |
12 | const Users = require('../models/users') | 13 | |
14 | const Client = mongoose.model('OAuthClient') | ||
15 | const User = mongoose.model('User') | ||
13 | 16 | ||
14 | const installer = { | 17 | const installer = { |
15 | installApplication: installApplication | 18 | installApplication: installApplication |
@@ -60,11 +63,16 @@ function createOAuthClientIfNotExist (callback) { | |||
60 | logger.info('Creating a default OAuth Client.') | 63 | logger.info('Creating a default OAuth Client.') |
61 | 64 | ||
62 | const secret = passwordGenerator(32, false) | 65 | const secret = passwordGenerator(32, false) |
63 | Users.createClient(secret, [ 'password' ], function (err, id) { | 66 | const client = new Client({ |
67 | clientSecret: secret, | ||
68 | grants: [ 'password' ] | ||
69 | }) | ||
70 | |||
71 | client.save(function (err, createdClient) { | ||
64 | if (err) return callback(err) | 72 | if (err) return callback(err) |
65 | 73 | ||
66 | logger.info('Client id: ' + id) | 74 | logger.info('Client id: ' + createdClient._id) |
67 | logger.info('Client secret: ' + secret) | 75 | logger.info('Client secret: ' + createdClient.clientSecret) |
68 | 76 | ||
69 | return callback(null) | 77 | return callback(null) |
70 | }) | 78 | }) |
@@ -94,11 +102,16 @@ function createOAuthUserIfNotExist (callback) { | |||
94 | password = passwordGenerator(8, true) | 102 | password = passwordGenerator(8, true) |
95 | } | 103 | } |
96 | 104 | ||
97 | Users.createUser(username, password, function (err) { | 105 | const user = new User({ |
106 | username: username, | ||
107 | password: password | ||
108 | }) | ||
109 | |||
110 | user.save(function (err, createdUser) { | ||
98 | if (err) return callback(err) | 111 | if (err) return callback(err) |
99 | 112 | ||
100 | logger.info('Username: ' + username) | 113 | logger.info('Username: ' + createdUser.username) |
101 | logger.info('User password: ' + password) | 114 | logger.info('User password: ' + createdUser.password) |
102 | 115 | ||
103 | return callback(null) | 116 | return callback(null) |
104 | }) | 117 | }) |