aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/installer.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/installer.js')
-rw-r--r--server/initializers/installer.js27
1 files changed, 20 insertions, 7 deletions
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 @@
3const async = require('async') 3const async = require('async')
4const config = require('config') 4const config = require('config')
5const mkdirp = require('mkdirp') 5const mkdirp = require('mkdirp')
6const mongoose = require('mongoose')
6const passwordGenerator = require('password-generator') 7const passwordGenerator = require('password-generator')
7const path = require('path') 8const path = require('path')
8 9
9const checker = require('./checker') 10const checker = require('./checker')
10const logger = require('../helpers/logger') 11const logger = require('../helpers/logger')
11const peertubeCrypto = require('../helpers/peertubeCrypto') 12const peertubeCrypto = require('../helpers/peertubeCrypto')
12const Users = require('../models/users') 13
14const Client = mongoose.model('OAuthClient')
15const User = mongoose.model('User')
13 16
14const installer = { 17const 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 })