diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
commit | 99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch) | |
tree | c9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/initializers/installer.js | |
parent | fcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff) | |
parent | 91cc839af88730ba55f84997c56b85ea100070a7 (diff) | |
download | PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip |
Merge branch 'postgresql'
Diffstat (limited to 'server/initializers/installer.js')
-rw-r--r-- | server/initializers/installer.js | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/server/initializers/installer.js b/server/initializers/installer.js index 1df300ba8..fb63b81ac 100644 --- a/server/initializers/installer.js +++ b/server/initializers/installer.js | |||
@@ -3,26 +3,27 @@ | |||
3 | const config = require('config') | 3 | const config = require('config') |
4 | const each = require('async/each') | 4 | const each = require('async/each') |
5 | const mkdirp = require('mkdirp') | 5 | const mkdirp = require('mkdirp') |
6 | const mongoose = require('mongoose') | ||
7 | const passwordGenerator = require('password-generator') | 6 | const passwordGenerator = require('password-generator') |
8 | const path = require('path') | 7 | const path = require('path') |
9 | const series = require('async/series') | 8 | const series = require('async/series') |
10 | 9 | ||
11 | const checker = require('./checker') | 10 | const checker = require('./checker') |
12 | const constants = require('./constants') | 11 | const constants = require('./constants') |
12 | const db = require('./database') | ||
13 | const logger = require('../helpers/logger') | 13 | const logger = require('../helpers/logger') |
14 | const peertubeCrypto = require('../helpers/peertube-crypto') | 14 | const peertubeCrypto = require('../helpers/peertube-crypto') |
15 | 15 | ||
16 | const Application = mongoose.model('Application') | ||
17 | const Client = mongoose.model('OAuthClient') | ||
18 | const User = mongoose.model('User') | ||
19 | |||
20 | const installer = { | 16 | const installer = { |
21 | installApplication | 17 | installApplication |
22 | } | 18 | } |
23 | 19 | ||
24 | function installApplication (callback) { | 20 | function installApplication (callback) { |
25 | series([ | 21 | series([ |
22 | function createDatabase (callbackAsync) { | ||
23 | db.sequelize.sync().asCallback(callbackAsync) | ||
24 | // db.sequelize.sync({ force: true }).asCallback(callbackAsync) | ||
25 | }, | ||
26 | |||
26 | function createDirectories (callbackAsync) { | 27 | function createDirectories (callbackAsync) { |
27 | createDirectoriesIfNotExist(callbackAsync) | 28 | createDirectoriesIfNotExist(callbackAsync) |
28 | }, | 29 | }, |
@@ -65,16 +66,18 @@ function createOAuthClientIfNotExist (callback) { | |||
65 | 66 | ||
66 | logger.info('Creating a default OAuth Client.') | 67 | logger.info('Creating a default OAuth Client.') |
67 | 68 | ||
68 | const secret = passwordGenerator(32, false) | 69 | const id = passwordGenerator(32, false, /[a-z0-9]/) |
69 | const client = new Client({ | 70 | const secret = passwordGenerator(32, false, /[a-zA-Z0-9]/) |
71 | const client = db.OAuthClient.build({ | ||
72 | clientId: id, | ||
70 | clientSecret: secret, | 73 | clientSecret: secret, |
71 | grants: [ 'password', 'refresh_token' ] | 74 | grants: [ 'password', 'refresh_token' ] |
72 | }) | 75 | }) |
73 | 76 | ||
74 | client.save(function (err, createdClient) { | 77 | client.save().asCallback(function (err, createdClient) { |
75 | if (err) return callback(err) | 78 | if (err) return callback(err) |
76 | 79 | ||
77 | logger.info('Client id: ' + createdClient._id) | 80 | logger.info('Client id: ' + createdClient.clientId) |
78 | logger.info('Client secret: ' + createdClient.clientSecret) | 81 | logger.info('Client secret: ' + createdClient.clientSecret) |
79 | 82 | ||
80 | return callback(null) | 83 | return callback(null) |
@@ -93,6 +96,7 @@ function createOAuthAdminIfNotExist (callback) { | |||
93 | 96 | ||
94 | const username = 'root' | 97 | const username = 'root' |
95 | const role = constants.USER_ROLES.ADMIN | 98 | const role = constants.USER_ROLES.ADMIN |
99 | const createOptions = {} | ||
96 | let password = '' | 100 | let password = '' |
97 | 101 | ||
98 | // Do not generate a random password for tests | 102 | // Do not generate a random password for tests |
@@ -102,25 +106,27 @@ function createOAuthAdminIfNotExist (callback) { | |||
102 | if (process.env.NODE_APP_INSTANCE) { | 106 | if (process.env.NODE_APP_INSTANCE) { |
103 | password += process.env.NODE_APP_INSTANCE | 107 | password += process.env.NODE_APP_INSTANCE |
104 | } | 108 | } |
109 | |||
110 | // Our password is weak so do not validate it | ||
111 | createOptions.validate = false | ||
105 | } else { | 112 | } else { |
106 | password = passwordGenerator(8, true) | 113 | password = passwordGenerator(8, true) |
107 | } | 114 | } |
108 | 115 | ||
109 | const user = new User({ | 116 | const userData = { |
110 | username, | 117 | username, |
111 | password, | 118 | password, |
112 | role | 119 | role |
113 | }) | 120 | } |
114 | 121 | ||
115 | user.save(function (err, createdUser) { | 122 | db.User.create(userData, createOptions).asCallback(function (err, createdUser) { |
116 | if (err) return callback(err) | 123 | if (err) return callback(err) |
117 | 124 | ||
118 | logger.info('Username: ' + username) | 125 | logger.info('Username: ' + username) |
119 | logger.info('User password: ' + password) | 126 | logger.info('User password: ' + password) |
120 | 127 | ||
121 | logger.info('Creating Application collection.') | 128 | logger.info('Creating Application table.') |
122 | const application = new Application({ mongoSchemaVersion: constants.LAST_MONGO_SCHEMA_VERSION }) | 129 | db.Application.create({ migrationVersion: constants.LAST_MIGRATION_VERSION }).asCallback(callback) |
123 | application.save(callback) | ||
124 | }) | 130 | }) |
125 | }) | 131 | }) |
126 | } | 132 | } |