X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Finstaller.js;h=1df300ba8d467fb76d3a7b5647fe1efc76559294;hb=763381deafebc660657ff175210a9585962ed9c4;hp=014efbcb7b7daf14b6420c63d18250947d557d43;hpb=5f698b82c7055df763f3830882ac5bad1397db23;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/installer.js b/server/initializers/installer.js index 014efbcb7..1df300ba8 100644 --- a/server/initializers/installer.js +++ b/server/initializers/installer.js @@ -1,25 +1,28 @@ '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/peertube-crypto') +const Application = mongoose.model('Application') const Client = mongoose.model('OAuthClient') const User = mongoose.model('User') const installer = { - installApplication: installApplication + installApplication } 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 @@ -103,17 +107,20 @@ function createOAuthUserIfNotExist (callback) { } const user = new User({ - username: username, - password: password + username, + password, + 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) }) }) }