aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/user.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r--server/lib/user.ts47
1 files changed, 32 insertions, 15 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts
index 57c653e55..1094c2401 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -1,6 +1,9 @@
1import * as Sequelize from 'sequelize'
2import { getActivityPubUrl } from '../helpers/activitypub'
3import { createPrivateAndPublicKeys } from '../helpers/peertube-crypto'
1import { database as db } from '../initializers' 4import { database as db } from '../initializers'
5import { CONFIG } from '../initializers/constants'
2import { UserInstance } from '../models' 6import { UserInstance } from '../models'
3import { addVideoAccountToFriends } from './friends'
4import { createVideoChannel } from './video-channel' 7import { createVideoChannel } from './video-channel'
5 8
6async function createUserAccountAndChannel (user: UserInstance, validateUser = true) { 9async function createUserAccountAndChannel (user: UserInstance, validateUser = true) {
@@ -11,32 +14,46 @@ async function createUserAccountAndChannel (user: UserInstance, validateUser = t
11 } 14 }
12 15
13 const userCreated = await user.save(userOptions) 16 const userCreated = await user.save(userOptions)
14 const accountInstance = db.Account.build({ 17 const accountCreated = await createLocalAccount(user.username, user.id, null, t)
15 name: userCreated.username,
16 podId: null, // It is our pod
17 userId: userCreated.id
18 })
19
20 const accountCreated = await accountInstance.save({ transaction: t })
21
22 const remoteVideoAccount = accountCreated.toAddRemoteJSON()
23
24 // Now we'll add the video channel's meta data to our friends
25 const account = await addVideoAccountToFriends(remoteVideoAccount, t)
26 18
27 const videoChannelInfo = { 19 const videoChannelInfo = {
28 name: `Default ${userCreated.username} channel` 20 name: `Default ${userCreated.username} channel`
29 } 21 }
30 const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) 22 const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t)
31 23
32 return { account, videoChannel } 24 return { account: accountCreated, videoChannel }
33 }) 25 })
34 26
35 return res 27 return res
36} 28}
37 29
30async function createLocalAccount (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) {
31 const { publicKey, privateKey } = await createPrivateAndPublicKeys()
32 const url = getActivityPubUrl('account', name)
33
34 const accountInstance = db.Account.build({
35 name,
36 url,
37 publicKey,
38 privateKey,
39 followersCount: 0,
40 followingCount: 0,
41 inboxUrl: url + '/inbox',
42 outboxUrl: url + '/outbox',
43 sharedInboxUrl: CONFIG.WEBSERVER.URL + '/inbox',
44 followersUrl: url + '/followers',
45 followingUrl: url + '/following',
46 userId,
47 applicationId,
48 podId: null // It is our pod
49 })
50
51 return accountInstance.save({ transaction: t })
52}
53
38// --------------------------------------------------------------------------- 54// ---------------------------------------------------------------------------
39 55
40export { 56export {
41 createUserAccountAndChannel 57 createUserAccountAndChannel,
58 createLocalAccount
42} 59}