diff options
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r-- | server/lib/user.ts | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts index 9884e566f..2d7b36b4f 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts | |||
@@ -5,16 +5,17 @@ import { database as db } from '../initializers' | |||
5 | import { CONFIG } from '../initializers/constants' | 5 | import { CONFIG } from '../initializers/constants' |
6 | import { UserInstance } from '../models' | 6 | import { UserInstance } from '../models' |
7 | import { createVideoChannel } from './video-channel' | 7 | import { createVideoChannel } from './video-channel' |
8 | import { logger } from '../helpers/logger' | ||
8 | 9 | ||
9 | async function createUserAccountAndChannel (user: UserInstance, validateUser = true) { | 10 | async function createUserAccountAndChannel (user: UserInstance, validateUser = true) { |
10 | const res = await db.sequelize.transaction(async t => { | 11 | const { account, videoChannel } = await db.sequelize.transaction(async t => { |
11 | const userOptions = { | 12 | const userOptions = { |
12 | transaction: t, | 13 | transaction: t, |
13 | validate: validateUser | 14 | validate: validateUser |
14 | } | 15 | } |
15 | 16 | ||
16 | const userCreated = await user.save(userOptions) | 17 | const userCreated = await user.save(userOptions) |
17 | const accountCreated = await createLocalAccount(user.username, user.id, null, t) | 18 | const accountCreated = await createLocalAccountWithoutKeys(user.username, user.id, null, t) |
18 | 19 | ||
19 | const videoChannelName = `Default ${userCreated.username} channel` | 20 | const videoChannelName = `Default ${userCreated.username} channel` |
20 | const videoChannelInfo = { | 21 | const videoChannelInfo = { |
@@ -25,18 +26,23 @@ async function createUserAccountAndChannel (user: UserInstance, validateUser = t | |||
25 | return { account: accountCreated, videoChannel } | 26 | return { account: accountCreated, videoChannel } |
26 | }) | 27 | }) |
27 | 28 | ||
28 | return res | 29 | // Set account keys, this could be long so process after the account creation and do not block the client |
30 | const { publicKey, privateKey } = await createPrivateAndPublicKeys() | ||
31 | account.set('publicKey', publicKey) | ||
32 | account.set('privateKey', privateKey) | ||
33 | account.save().catch(err => logger.error('Cannot set public/private keys of local account %d.', account.id, err)) | ||
34 | |||
35 | return { account, videoChannel } | ||
29 | } | 36 | } |
30 | 37 | ||
31 | async function createLocalAccount (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { | 38 | async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { |
32 | const { publicKey, privateKey } = await createPrivateAndPublicKeys() | ||
33 | const url = getActivityPubUrl('account', name) | 39 | const url = getActivityPubUrl('account', name) |
34 | 40 | ||
35 | const accountInstance = db.Account.build({ | 41 | const accountInstance = db.Account.build({ |
36 | name, | 42 | name, |
37 | url, | 43 | url, |
38 | publicKey, | 44 | publicKey: null, |
39 | privateKey, | 45 | privateKey: null, |
40 | followersCount: 0, | 46 | followersCount: 0, |
41 | followingCount: 0, | 47 | followingCount: 0, |
42 | inboxUrl: url + '/inbox', | 48 | inboxUrl: url + '/inbox', |
@@ -56,5 +62,5 @@ async function createLocalAccount (name: string, userId: number, applicationId: | |||
56 | 62 | ||
57 | export { | 63 | export { |
58 | createUserAccountAndChannel, | 64 | createUserAccountAndChannel, |
59 | createLocalAccount | 65 | createLocalAccountWithoutKeys |
60 | } | 66 | } |