X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Finstaller.js;h=8c3148e79fc9576f476f74fc6280ca2c13ecb4ee;hb=f6a0754fdacf9b890292f1efc62a9035bceb454a;hp=e0ae822cfef2936253db786733b222e9efba27e5;hpb=69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/installer.js b/server/initializers/installer.js index e0ae822cf..8c3148e79 100644 --- a/server/initializers/installer.js +++ b/server/initializers/installer.js @@ -1,16 +1,19 @@ 'use strict' -const async = require('async') const config = require('config') +const each = require('async/each') const mkdirp = require('mkdirp') const mongoose = require('mongoose') const passwordGenerator = require('password-generator') const path = require('path') +const series = require('async/series') const checker = require('./checker') +const constants = require('./constants') const logger = require('../helpers/logger') -const peertubeCrypto = require('../helpers/peertubeCrypto') +const peertubeCrypto = require('../helpers/peertube-crypto') +const Application = mongoose.model('Application') const Client = mongoose.model('OAuthClient') const User = mongoose.model('User') @@ -19,7 +22,7 @@ const installer = { } function installApplication (callback) { - async.series([ + series([ function createDirectories (callbackAsync) { createDirectoriesIfNotExist(callbackAsync) }, @@ -33,7 +36,7 @@ function installApplication (callback) { }, function createOAuthUser (callbackAsync) { - createOAuthUserIfNotExist(callbackAsync) + createOAuthAdminIfNotExist(callbackAsync) } ], callback) } @@ -47,7 +50,7 @@ module.exports = installer function createDirectoriesIfNotExist (callback) { const storages = config.get('storage') - async.each(Object.keys(storages), function (key, callbackEach) { + each(Object.keys(storages), function (key, callbackEach) { const dir = storages[key] mkdirp(path.join(__dirname, '..', '..', dir), callbackEach) }, callback) @@ -65,7 +68,7 @@ function createOAuthClientIfNotExist (callback) { const secret = passwordGenerator(32, false) const client = new Client({ clientSecret: secret, - grants: [ 'password' ] + grants: [ 'password', 'refresh_token' ] }) client.save(function (err, createdClient) { @@ -79,7 +82,7 @@ function createOAuthClientIfNotExist (callback) { }) } -function createOAuthUserIfNotExist (callback) { +function createOAuthAdminIfNotExist (callback) { checker.usersExist(function (err, exist) { if (err) return callback(err) @@ -89,6 +92,7 @@ function createOAuthUserIfNotExist (callback) { logger.info('Creating the administrator.') const username = 'root' + const role = constants.USER_ROLES.ADMIN let password = '' // Do not generate a random password for tests @@ -104,16 +108,19 @@ function createOAuthUserIfNotExist (callback) { const user = new User({ username: username, - password: password + password: password, + role: role }) user.save(function (err, createdUser) { if (err) return callback(err) - logger.info('Username: ' + createdUser.username) - logger.info('User password: ' + createdUser.password) + logger.info('Username: ' + username) + logger.info('User password: ' + password) - return callback(null) + logger.info('Creating Application collection.') + const application = new Application({ mongoSchemaVersion: constants.LAST_MONGO_SCHEMA_VERSION }) + application.save(callback) }) }) }