rl.on('line', line => {
const log = JSON.parse(line)
- logLevels[log.level](log.message)
+ logLevels[log.level](log.message, log.stack)
})
usersRouter.post('/register',
ensureUserRegistrationAllowed,
usersRegisterValidator,
- asyncMiddleware(registerUser)
+ asyncMiddleware(registerUserRetryWrapper)
)
usersRouter.put('/me',
async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
- arguments: [ req, res ],
+ arguments: [ req ],
errorMessage: 'Cannot insert the user with many retries.'
}
return res.type('json').status(204).end()
}
-async function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function createUser (req: express.Request) {
const body: UserCreate = req.body
const user = db.User.build({
username: body.username,
logger.info('User %s with its channel and account created.', body.username)
}
-async function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const options = {
+ arguments: [ req ],
+ errorMessage: 'Cannot insert the user with many retries.'
+ }
+
+ await retryTransactionWrapper(registerUser, options)
+
+ return res.type('json').status(204).end()
+}
+
+async function registerUser (req: express.Request) {
const body: UserCreate = req.body
const user = db.User.build({
})
await createUserAccountAndChannel(user)
- return res.type('json').status(204).end()
+
+ logger.info('User %s with its channel and account registered.', body.username)
}
async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
import { UserRole } from '../../shared'
import { logger, mkdirpPromise, rimrafPromise } from '../helpers'
import { createUserAccountAndChannel } from '../lib'
-import { createLocalAccount } from '../lib/user'
+import { createLocalAccountWithoutKeys } from '../lib/user'
import { applicationExist, clientsExist, usersExist } from './checker'
import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants'
-
import { database as db } from './database'
async function installApplication () {
const applicationInstance = await db.Application.create({ migrationVersion: LAST_MIGRATION_VERSION })
logger.info('Creating application account.')
- return createLocalAccount(SERVER_ACCOUNT_NAME, null, applicationInstance.id, undefined)
+
+ return createLocalAccountWithoutKeys(SERVER_ACCOUNT_NAME, null, applicationInstance.id, undefined)
}
import { CONFIG } from '../initializers/constants'
import { UserInstance } from '../models'
import { createVideoChannel } from './video-channel'
+import { logger } from '../helpers/logger'
async function createUserAccountAndChannel (user: UserInstance, validateUser = true) {
- const res = await db.sequelize.transaction(async t => {
+ const { account, videoChannel } = await db.sequelize.transaction(async t => {
const userOptions = {
transaction: t,
validate: validateUser
}
const userCreated = await user.save(userOptions)
- const accountCreated = await createLocalAccount(user.username, user.id, null, t)
+ const accountCreated = await createLocalAccountWithoutKeys(user.username, user.id, null, t)
const videoChannelName = `Default ${userCreated.username} channel`
const videoChannelInfo = {
return { account: accountCreated, videoChannel }
})
- return res
+ // Set account keys, this could be long so process after the account creation and do not block the client
+ const { publicKey, privateKey } = await createPrivateAndPublicKeys()
+ account.set('publicKey', publicKey)
+ account.set('privateKey', privateKey)
+ account.save().catch(err => logger.error('Cannot set public/private keys of local account %d.', account.id, err))
+
+ return { account, videoChannel }
}
-async function createLocalAccount (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) {
- const { publicKey, privateKey } = await createPrivateAndPublicKeys()
+async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) {
const url = getActivityPubUrl('account', name)
const accountInstance = db.Account.build({
name,
url,
- publicKey,
- privateKey,
+ publicKey: null,
+ privateKey: null,
followersCount: 0,
followingCount: 0,
inboxUrl: url + '/inbox',
export {
createUserAccountAndChannel,
- createLocalAccount
+ createLocalAccountWithoutKeys
}
// Do not forget to add Account information to the created video channel
videoChannelCreated.Account = account
- await sendCreateVideoChannel(videoChannelCreated, t)
- await shareVideoChannelByServer(videoChannelCreated, t)
-
+ // No need to seed this empty video channel to followers
return videoChannelCreated
}
},
publicKey: {
type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY.max),
- allowNull: false,
+ allowNull: true,
validate: {
publicKeyValid: value => {
const res = isAccountPublicKeyValid(value)
let server = null
before(async function () {
- this.timeout(120000)
+ this.timeout(10000)
await flushTests()
server = await runServer(1)
})
it('Should have a correct config on a server with registration enabled and a users limit', async function () {
- await registerUser(server.url, 'user1', 'super password')
- await registerUser(server.url, 'user2', 'super password')
- await registerUser(server.url, 'user3', 'super password')
+ await Promise.all([
+ registerUser(server.url, 'user1', 'super password'),
+ registerUser(server.url, 'user2', 'super password'),
+ registerUser(server.url, 'user3', 'super password')
+ ])
const res = await getConfig(server.url)
const data = res.body
export * from './config'
export * from './login'
export * from './miscs'
-export * from './pods'
+export * from './follows'
export * from './request-schedulers'
export * from './requests'
export * from './servers'