From 45f1bd72a08998c60a9dd68ff069cea9de39161c Mon Sep 17 00:00:00 2001 From: John Livingston <38844060+JohnXLivingston@users.noreply.github.com> Date: Mon, 17 Feb 2020 10:16:52 +0100 Subject: 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 --- server/lib/emailer.ts | 16 ++++++++++++++++ server/lib/redis.ts | 9 +++++++++ 2 files changed, 25 insertions(+) (limited to 'server/lib') 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 { return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) } + addPasswordCreateEmailJob (username: string, to: string, resetPasswordUrl: string) { + const text = 'Hi,\n\n' + + `Welcome to your ${WEBSERVER.HOST} PeerTube instance. Your username is: ${username}.\n\n` + + `Please set your password by following this link: ${resetPasswordUrl} (this link will expire within seven days).\n\n` + + 'Cheers,\n' + + `${CONFIG.EMAIL.BODY.SIGNATURE}` + + const emailPayload: EmailPayload = { + to: [ to ], + subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'New PeerTube account password', + text + } + + return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) + } + addVerifyEmailJob (to: string, verifyEmailUrl: string) { const text = 'Welcome to PeerTube,\n\n' + `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 { CONTACT_FORM_LIFETIME, USER_EMAIL_VERIFY_LIFETIME, USER_PASSWORD_RESET_LIFETIME, + USER_PASSWORD_CREATE_LIFETIME, VIDEO_VIEW_LIFETIME, WEBSERVER } from '../initializers/constants' @@ -74,6 +75,14 @@ class Redis { return generatedString } + async setCreatePasswordVerificationString (userId: number) { + const generatedString = await generateRandomString(32) + + await this.setValue(this.generateResetPasswordKey(userId), generatedString, USER_PASSWORD_CREATE_LIFETIME) + + return generatedString + } + async getResetPasswordLink (userId: number) { return this.getValue(this.generateResetPasswordKey(userId)) } -- cgit v1.2.3