aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/emailer.ts23
-rw-r--r--server/lib/job-queue/handlers/email.ts3
-rw-r--r--server/lib/redis.ts24
3 files changed, 45 insertions, 5 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 3429498e7..9b1c5122f 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -354,13 +354,32 @@ class Emailer {
354 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 354 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
355 } 355 }
356 356
357 sendMail (to: string[], subject: string, text: string) { 357 addContactFormJob (fromEmail: string, fromName: string, body: string) {
358 const text = 'Hello dear admin,\n\n' +
359 fromName + ' sent you a message' +
360 '\n\n---------------------------------------\n\n' +
361 body +
362 '\n\n---------------------------------------\n\n' +
363 'Cheers,\n' +
364 'PeerTube.'
365
366 const emailPayload: EmailPayload = {
367 from: fromEmail,
368 to: [ CONFIG.ADMIN.EMAIL ],
369 subject: '[PeerTube] Contact form submitted',
370 text
371 }
372
373 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
374 }
375
376 sendMail (to: string[], subject: string, text: string, from?: string) {
358 if (!this.enabled) { 377 if (!this.enabled) {
359 throw new Error('Cannot send mail because SMTP is not configured.') 378 throw new Error('Cannot send mail because SMTP is not configured.')
360 } 379 }
361 380
362 return this.transporter.sendMail({ 381 return this.transporter.sendMail({
363 from: CONFIG.SMTP.FROM_ADDRESS, 382 from: from || CONFIG.SMTP.FROM_ADDRESS,
364 to: to.join(','), 383 to: to.join(','),
365 subject, 384 subject,
366 text 385 text
diff --git a/server/lib/job-queue/handlers/email.ts b/server/lib/job-queue/handlers/email.ts
index 73d98ae54..220d0af32 100644
--- a/server/lib/job-queue/handlers/email.ts
+++ b/server/lib/job-queue/handlers/email.ts
@@ -6,13 +6,14 @@ export type EmailPayload = {
6 to: string[] 6 to: string[]
7 subject: string 7 subject: string
8 text: string 8 text: string
9 from?: string
9} 10}
10 11
11async function processEmail (job: Bull.Job) { 12async function processEmail (job: Bull.Job) {
12 const payload = job.data as EmailPayload 13 const payload = job.data as EmailPayload
13 logger.info('Processing email in job %d.', job.id) 14 logger.info('Processing email in job %d.', job.id)
14 15
15 return Emailer.Instance.sendMail(payload.to, payload.subject, payload.text) 16 return Emailer.Instance.sendMail(payload.to, payload.subject, payload.text, payload.from)
16} 17}
17 18
18// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index 3e25e6a2c..3628c0583 100644
--- a/server/lib/redis.ts
+++ b/server/lib/redis.ts
@@ -2,7 +2,13 @@ import * as express from 'express'
2import { createClient, RedisClient } from 'redis' 2import { createClient, RedisClient } from 'redis'
3import { logger } from '../helpers/logger' 3import { logger } from '../helpers/logger'
4import { generateRandomString } from '../helpers/utils' 4import { generateRandomString } from '../helpers/utils'
5import { CONFIG, USER_PASSWORD_RESET_LIFETIME, USER_EMAIL_VERIFY_LIFETIME, VIDEO_VIEW_LIFETIME } from '../initializers' 5import {
6 CONFIG,
7 CONTACT_FORM_LIFETIME,
8 USER_EMAIL_VERIFY_LIFETIME,
9 USER_PASSWORD_RESET_LIFETIME,
10 VIDEO_VIEW_LIFETIME
11} from '../initializers'
6 12
7type CachedRoute = { 13type CachedRoute = {
8 body: string, 14 body: string,
@@ -76,6 +82,16 @@ class Redis {
76 return this.getValue(this.generateVerifyEmailKey(userId)) 82 return this.getValue(this.generateVerifyEmailKey(userId))
77 } 83 }
78 84
85 /************* Contact form per IP *************/
86
87 async setContactFormIp (ip: string) {
88 return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME)
89 }
90
91 async isContactFormIpExists (ip: string) {
92 return this.exists(this.generateContactFormKey(ip))
93 }
94
79 /************* Views per IP *************/ 95 /************* Views per IP *************/
80 96
81 setIPVideoView (ip: string, videoUUID: string) { 97 setIPVideoView (ip: string, videoUUID: string) {
@@ -175,7 +191,11 @@ class Redis {
175 } 191 }
176 192
177 private generateViewKey (ip: string, videoUUID: string) { 193 private generateViewKey (ip: string, videoUUID: string) {
178 return videoUUID + '-' + ip 194 return `views-${videoUUID}-${ip}`
195 }
196
197 private generateContactFormKey (ip: string) {
198 return 'contact-form-' + ip
179 } 199 }
180 200
181 /************* Redis helpers *************/ 201 /************* Redis helpers *************/