diff options
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r-- | server/lib/user.ts | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts index 2e433da04..ffb57944a 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts | |||
@@ -10,7 +10,7 @@ import { sequelizeTypescript } from '../initializers/database' | |||
10 | import { AccountModel } from '../models/account/account' | 10 | import { AccountModel } from '../models/account/account' |
11 | import { UserNotificationSettingModel } from '../models/user/user-notification-setting' | 11 | import { UserNotificationSettingModel } from '../models/user/user-notification-setting' |
12 | import { MAccountDefault, MChannelActor } from '../types/models' | 12 | import { MAccountDefault, MChannelActor } from '../types/models' |
13 | import { MUser, MUserDefault, MUserId } from '../types/models/user' | 13 | import { MRegistration, MUser, MUserDefault, MUserId } from '../types/models/user' |
14 | import { generateAndSaveActorKeys } from './activitypub/actors' | 14 | import { generateAndSaveActorKeys } from './activitypub/actors' |
15 | import { getLocalAccountActivityPubUrl } from './activitypub/url' | 15 | import { getLocalAccountActivityPubUrl } from './activitypub/url' |
16 | import { Emailer } from './emailer' | 16 | import { Emailer } from './emailer' |
@@ -97,7 +97,7 @@ async function createUserAccountAndChannelAndPlaylist (parameters: { | |||
97 | }) | 97 | }) |
98 | userCreated.Account = accountCreated | 98 | userCreated.Account = accountCreated |
99 | 99 | ||
100 | const channelAttributes = await buildChannelAttributes(userCreated, t, channelNames) | 100 | const channelAttributes = await buildChannelAttributes({ user: userCreated, transaction: t, channelNames }) |
101 | const videoChannel = await createLocalVideoChannel(channelAttributes, accountCreated, t) | 101 | const videoChannel = await createLocalVideoChannel(channelAttributes, accountCreated, t) |
102 | 102 | ||
103 | const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) | 103 | const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) |
@@ -160,15 +160,28 @@ async function createApplicationActor (applicationId: number) { | |||
160 | // --------------------------------------------------------------------------- | 160 | // --------------------------------------------------------------------------- |
161 | 161 | ||
162 | async function sendVerifyUserEmail (user: MUser, isPendingEmail = false) { | 162 | async function sendVerifyUserEmail (user: MUser, isPendingEmail = false) { |
163 | const verificationString = await Redis.Instance.setVerifyEmailVerificationString(user.id) | 163 | const verificationString = await Redis.Instance.setUserVerifyEmailVerificationString(user.id) |
164 | let url = WEBSERVER.URL + '/verify-account/email?userId=' + user.id + '&verificationString=' + verificationString | 164 | let verifyEmailUrl = `${WEBSERVER.URL}/verify-account/email?userId=${user.id}&verificationString=${verificationString}` |
165 | 165 | ||
166 | if (isPendingEmail) url += '&isPendingEmail=true' | 166 | if (isPendingEmail) verifyEmailUrl += '&isPendingEmail=true' |
167 | |||
168 | const to = isPendingEmail | ||
169 | ? user.pendingEmail | ||
170 | : user.email | ||
167 | 171 | ||
168 | const email = isPendingEmail ? user.pendingEmail : user.email | ||
169 | const username = user.username | 172 | const username = user.username |
170 | 173 | ||
171 | Emailer.Instance.addVerifyEmailJob(username, email, url) | 174 | Emailer.Instance.addVerifyEmailJob({ username, to, verifyEmailUrl, isRegistrationRequest: false }) |
175 | } | ||
176 | |||
177 | async function sendVerifyRegistrationEmail (registration: MRegistration) { | ||
178 | const verificationString = await Redis.Instance.setRegistrationVerifyEmailVerificationString(registration.id) | ||
179 | const verifyEmailUrl = `${WEBSERVER.URL}/verify-account/email?registrationId=${registration.id}&verificationString=${verificationString}` | ||
180 | |||
181 | const to = registration.email | ||
182 | const username = registration.username | ||
183 | |||
184 | Emailer.Instance.addVerifyEmailJob({ username, to, verifyEmailUrl, isRegistrationRequest: true }) | ||
172 | } | 185 | } |
173 | 186 | ||
174 | // --------------------------------------------------------------------------- | 187 | // --------------------------------------------------------------------------- |
@@ -232,7 +245,10 @@ export { | |||
232 | createApplicationActor, | 245 | createApplicationActor, |
233 | createUserAccountAndChannelAndPlaylist, | 246 | createUserAccountAndChannelAndPlaylist, |
234 | createLocalAccountWithoutKeys, | 247 | createLocalAccountWithoutKeys, |
248 | |||
235 | sendVerifyUserEmail, | 249 | sendVerifyUserEmail, |
250 | sendVerifyRegistrationEmail, | ||
251 | |||
236 | isAbleToUploadVideo, | 252 | isAbleToUploadVideo, |
237 | buildUser | 253 | buildUser |
238 | } | 254 | } |
@@ -264,7 +280,13 @@ function createDefaultUserNotificationSettings (user: MUserId, t: Transaction | | |||
264 | return UserNotificationSettingModel.create(values, { transaction: t }) | 280 | return UserNotificationSettingModel.create(values, { transaction: t }) |
265 | } | 281 | } |
266 | 282 | ||
267 | async function buildChannelAttributes (user: MUser, transaction?: Transaction, channelNames?: ChannelNames) { | 283 | async function buildChannelAttributes (options: { |
284 | user: MUser | ||
285 | transaction?: Transaction | ||
286 | channelNames?: ChannelNames | ||
287 | }) { | ||
288 | const { user, transaction, channelNames } = options | ||
289 | |||
268 | if (channelNames) return channelNames | 290 | if (channelNames) return channelNames |
269 | 291 | ||
270 | const channelName = await findAvailableLocalActorName(user.username + '_channel', transaction) | 292 | const channelName = await findAvailableLocalActorName(user.username + '_channel', transaction) |