aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-06-07 16:59:53 +0200
committerChocobozzz <me@florianbigard.com>2019-06-07 17:05:42 +0200
commit1f20622f2b087eaf8738d60fae00a44b9c558ca3 (patch)
tree1c8554623665ca96b8a1e6f2a6bcb8c1b5a83c2e /server/lib
parent1a03bea0c42fa1064ce4770157b4fd2e3edd5565 (diff)
downloadPeerTube-1f20622f2b087eaf8738d60fae00a44b9c558ca3.tar.gz
PeerTube-1f20622f2b087eaf8738d60fae00a44b9c558ca3.tar.zst
PeerTube-1f20622f2b087eaf8738d60fae00a44b9c558ca3.zip
Improve registration
* Add ability to set the user display name * Use display name to guess the username/channel name * Add explanations about what is the purpose of a username/channel name * Add a loader at the "done" step
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/user.ts41
1 files changed, 31 insertions, 10 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts
index d9fd89e15..b50b09d72 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -1,4 +1,3 @@
1import * as Sequelize from 'sequelize'
2import * as uuidv4 from 'uuid/v4' 1import * as uuidv4 from 'uuid/v4'
3import { ActivityPubActorType } from '../../shared/models/activitypub' 2import { ActivityPubActorType } from '../../shared/models/activitypub'
4import { SERVER_ACTOR_NAME } from '../initializers/constants' 3import { SERVER_ACTOR_NAME } from '../initializers/constants'
@@ -12,9 +11,17 @@ import { UserNotificationSettingModel } from '../models/account/user-notificatio
12import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' 11import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users'
13import { createWatchLaterPlaylist } from './video-playlist' 12import { createWatchLaterPlaylist } from './video-playlist'
14import { sequelizeTypescript } from '../initializers/database' 13import { sequelizeTypescript } from '../initializers/database'
14import { Transaction } from 'sequelize/types'
15 15
16type ChannelNames = { name: string, displayName: string } 16type ChannelNames = { name: string, displayName: string }
17async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel, channelNames?: ChannelNames, validateUser = true) { 17async function createUserAccountAndChannelAndPlaylist (parameters: {
18 userToCreate: UserModel,
19 userDisplayName?: string,
20 channelNames?: ChannelNames,
21 validateUser?: boolean
22}) {
23 const { userToCreate, userDisplayName, channelNames, validateUser = true } = parameters
24
18 const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { 25 const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => {
19 const userOptions = { 26 const userOptions = {
20 transaction: t, 27 transaction: t,
@@ -24,7 +31,13 @@ async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel,
24 const userCreated = await userToCreate.save(userOptions) 31 const userCreated = await userToCreate.save(userOptions)
25 userCreated.NotificationSetting = await createDefaultUserNotificationSettings(userCreated, t) 32 userCreated.NotificationSetting = await createDefaultUserNotificationSettings(userCreated, t)
26 33
27 const accountCreated = await createLocalAccountWithoutKeys(userCreated.username, userCreated.id, null, t) 34 const accountCreated = await createLocalAccountWithoutKeys({
35 name: userCreated.username,
36 displayName: userDisplayName,
37 userId: userCreated.id,
38 applicationId: null,
39 t: t
40 })
28 userCreated.Account = accountCreated 41 userCreated.Account = accountCreated
29 42
30 const channelAttributes = await buildChannelAttributes(userCreated, channelNames) 43 const channelAttributes = await buildChannelAttributes(userCreated, channelNames)
@@ -46,20 +59,22 @@ async function createUserAccountAndChannelAndPlaylist (userToCreate: UserModel,
46 return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel } 59 return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel }
47} 60}
48 61
49async function createLocalAccountWithoutKeys ( 62async function createLocalAccountWithoutKeys (parameters: {
50 name: string, 63 name: string,
64 displayName?: string,
51 userId: number | null, 65 userId: number | null,
52 applicationId: number | null, 66 applicationId: number | null,
53 t: Sequelize.Transaction | undefined, 67 t: Transaction | undefined,
54 type: ActivityPubActorType= 'Person' 68 type?: ActivityPubActorType
55) { 69}) {
70 const { name, displayName, userId, applicationId, t, type = 'Person' } = parameters
56 const url = getAccountActivityPubUrl(name) 71 const url = getAccountActivityPubUrl(name)
57 72
58 const actorInstance = buildActorInstance(type, url, name) 73 const actorInstance = buildActorInstance(type, url, name)
59 const actorInstanceCreated = await actorInstance.save({ transaction: t }) 74 const actorInstanceCreated = await actorInstance.save({ transaction: t })
60 75
61 const accountInstance = new AccountModel({ 76 const accountInstance = new AccountModel({
62 name, 77 name: displayName || name,
63 userId, 78 userId,
64 applicationId, 79 applicationId,
65 actorId: actorInstanceCreated.id 80 actorId: actorInstanceCreated.id
@@ -72,7 +87,13 @@ async function createLocalAccountWithoutKeys (
72} 87}
73 88
74async function createApplicationActor (applicationId: number) { 89async function createApplicationActor (applicationId: number) {
75 const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACTOR_NAME, null, applicationId, undefined, 'Application') 90 const accountCreated = await createLocalAccountWithoutKeys({
91 name: SERVER_ACTOR_NAME,
92 userId: null,
93 applicationId: applicationId,
94 t: undefined,
95 type: 'Application'
96 })
76 97
77 accountCreated.Actor = await setAsyncActorKeys(accountCreated.Actor) 98 accountCreated.Actor = await setAsyncActorKeys(accountCreated.Actor)
78 99
@@ -89,7 +110,7 @@ export {
89 110
90// --------------------------------------------------------------------------- 111// ---------------------------------------------------------------------------
91 112
92function createDefaultUserNotificationSettings (user: UserModel, t: Sequelize.Transaction | undefined) { 113function createDefaultUserNotificationSettings (user: UserModel, t: Transaction | undefined) {
93 const values: UserNotificationSetting & { userId: number } = { 114 const values: UserNotificationSetting & { userId: number } = {
94 userId: user.id, 115 userId: user.id,
95 newVideoFromSubscription: UserNotificationSettingValue.WEB, 116 newVideoFromSubscription: UserNotificationSettingValue.WEB,