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')
},
function createOAuthUser (callbackAsync) {
- createOAuthUserIfNotExist(callbackAsync)
+ createOAuthAdminIfNotExist(callbackAsync)
}
], callback)
}
const secret = passwordGenerator(32, false)
const client = new Client({
clientSecret: secret,
- grants: [ 'password' ]
+ grants: [ 'password', 'refresh_token' ]
})
client.save(function (err, createdClient) {
})
}
-function createOAuthUserIfNotExist (callback) {
+function createOAuthAdminIfNotExist (callback) {
checker.usersExist(function (err, exist) {
if (err) return callback(err)
logger.info('Creating the administrator.')
const username = 'root'
+ const role = constants.USER_ROLES.ADMIN
let password = ''
// Do not generate a random password for tests
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)
})
})
}