aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorJohn Livingston <38844060+JohnXLivingston@users.noreply.github.com>2020-02-17 10:16:52 +0100
committerGitHub <noreply@github.com>2020-02-17 10:16:52 +0100
commit45f1bd72a08998c60a9dd68ff069cea9de39161c (patch)
tree79e484bd7fd38fe97c84fdb00a164534f43941e9 /server/lib
parentc5621bd23bce038671cd81149a0aa5e238558b67 (diff)
downloadPeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.tar.gz
PeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.tar.zst
PeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.zip
Creating a user with an empty password will send an email to let him set his password (#2479)
* Creating a user with an empty password will send an email to let him set his password * Consideration of Chocobozzz's comments * Tips for optional password * API documentation * Fix circular imports * Tests
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/emailer.ts16
-rw-r--r--server/lib/redis.ts9
2 files changed, 25 insertions, 0 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 9ce6186b1..0f74d2a8c 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -384,6 +384,22 @@ class Emailer {
384 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 384 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
385 } 385 }
386 386
387 addPasswordCreateEmailJob (username: string, to: string, resetPasswordUrl: string) {
388 const text = 'Hi,\n\n' +
389 `Welcome to your ${WEBSERVER.HOST} PeerTube instance. Your username is: ${username}.\n\n` +
390 `Please set your password by following this link: ${resetPasswordUrl} (this link will expire within seven days).\n\n` +
391 'Cheers,\n' +
392 `${CONFIG.EMAIL.BODY.SIGNATURE}`
393
394 const emailPayload: EmailPayload = {
395 to: [ to ],
396 subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'New PeerTube account password',
397 text
398 }
399
400 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
401 }
402
387 addVerifyEmailJob (to: string, verifyEmailUrl: string) { 403 addVerifyEmailJob (to: string, verifyEmailUrl: string) {
388 const text = 'Welcome to PeerTube,\n\n' + 404 const text = 'Welcome to PeerTube,\n\n' +
389 `To start using PeerTube on ${WEBSERVER.HOST} you must verify your email! ` + 405 `To start using PeerTube on ${WEBSERVER.HOST} you must verify your email! ` +
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index 0c5dbdd3e..b4cd6f8e7 100644
--- a/server/lib/redis.ts
+++ b/server/lib/redis.ts
@@ -6,6 +6,7 @@ import {
6 CONTACT_FORM_LIFETIME, 6 CONTACT_FORM_LIFETIME,
7 USER_EMAIL_VERIFY_LIFETIME, 7 USER_EMAIL_VERIFY_LIFETIME,
8 USER_PASSWORD_RESET_LIFETIME, 8 USER_PASSWORD_RESET_LIFETIME,
9 USER_PASSWORD_CREATE_LIFETIME,
9 VIDEO_VIEW_LIFETIME, 10 VIDEO_VIEW_LIFETIME,
10 WEBSERVER 11 WEBSERVER
11} from '../initializers/constants' 12} from '../initializers/constants'
@@ -74,6 +75,14 @@ class Redis {
74 return generatedString 75 return generatedString
75 } 76 }
76 77
78 async setCreatePasswordVerificationString (userId: number) {
79 const generatedString = await generateRandomString(32)
80
81 await this.setValue(this.generateResetPasswordKey(userId), generatedString, USER_PASSWORD_CREATE_LIFETIME)
82
83 return generatedString
84 }
85
77 async getResetPasswordLink (userId: number) { 86 async getResetPasswordLink (userId: number) {
78 return this.getValue(this.generateResetPasswordKey(userId)) 87 return this.getValue(this.generateResetPasswordKey(userId))
79 } 88 }