aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/user.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-14 11:18:49 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 10:51:09 +0100
commitfadf619ad61a016c1c7fc53de5a8f398a4f77519 (patch)
treebd449b9fe2353d812f4cf57f6dd03c2221b25607 /server/lib/user.ts
parent7efe153b0bc23e596d5019b9fb3e3e32b6cfeccd (diff)
downloadPeerTube-fadf619ad61a016c1c7fc53de5a8f398a4f77519.tar.gz
PeerTube-fadf619ad61a016c1c7fc53de5a8f398a4f77519.tar.zst
PeerTube-fadf619ad61a016c1c7fc53de5a8f398a4f77519.zip
Save
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r--server/lib/user.ts24
1 files changed, 17 insertions, 7 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts
index c4722fae2..6aeb198b9 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -3,6 +3,7 @@ import { createPrivateAndPublicKeys, logger } from '../helpers'
3import { CONFIG, sequelizeTypescript } from '../initializers' 3import { CONFIG, sequelizeTypescript } from '../initializers'
4import { AccountModel } from '../models/account/account' 4import { AccountModel } from '../models/account/account'
5import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
6import { ActorModel } from '../models/activitypub/actor'
6import { getAccountActivityPubUrl } from './activitypub' 7import { getAccountActivityPubUrl } from './activitypub'
7import { createVideoChannel } from './video-channel' 8import { createVideoChannel } from './video-channel'
8 9
@@ -27,9 +28,10 @@ async function createUserAccountAndChannel (user: UserModel, validateUser = true
27 28
28 // Set account keys, this could be long so process after the account creation and do not block the client 29 // Set account keys, this could be long so process after the account creation and do not block the client
29 const { publicKey, privateKey } = await createPrivateAndPublicKeys() 30 const { publicKey, privateKey } = await createPrivateAndPublicKeys()
30 account.set('publicKey', publicKey) 31 const actor = account.Actor
31 account.set('privateKey', privateKey) 32 actor.set('publicKey', publicKey)
32 account.save().catch(err => logger.error('Cannot set public/private keys of local account %d.', account.id, err)) 33 actor.set('privateKey', privateKey)
34 actor.save().catch(err => logger.error('Cannot set public/private keys of actor %d.', actor.uuid, err))
33 35
34 return { account, videoChannel } 36 return { account, videoChannel }
35} 37}
@@ -37,8 +39,7 @@ async function createUserAccountAndChannel (user: UserModel, validateUser = true
37async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { 39async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) {
38 const url = getAccountActivityPubUrl(name) 40 const url = getAccountActivityPubUrl(name)
39 41
40 const accountInstance = new AccountModel({ 42 const actorInstance = new ActorModel({
41 name,
42 url, 43 url,
43 publicKey: null, 44 publicKey: null,
44 privateKey: null, 45 privateKey: null,
@@ -48,13 +49,22 @@ async function createLocalAccountWithoutKeys (name: string, userId: number, appl
48 outboxUrl: url + '/outbox', 49 outboxUrl: url + '/outbox',
49 sharedInboxUrl: CONFIG.WEBSERVER.URL + '/inbox', 50 sharedInboxUrl: CONFIG.WEBSERVER.URL + '/inbox',
50 followersUrl: url + '/followers', 51 followersUrl: url + '/followers',
51 followingUrl: url + '/following', 52 followingUrl: url + '/following'
53 })
54 const actorInstanceCreated = await actorInstance.save({ transaction: t })
55
56 const accountInstance = new AccountModel({
57 name,
52 userId, 58 userId,
53 applicationId, 59 applicationId,
60 actorId: actorInstanceCreated.id,
54 serverId: null // It is our server 61 serverId: null // It is our server
55 }) 62 })
56 63
57 return accountInstance.save({ transaction: t }) 64 const accountInstanceCreated = await accountInstance.save({ transaction: t })
65 accountInstanceCreated.Actor = actorInstanceCreated
66
67 return accountInstanceCreated
58} 68}
59 69
60// --------------------------------------------------------------------------- 70// ---------------------------------------------------------------------------