From a4101923e699e49ceb9ff36e971c75417fafc9f0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 9 Jan 2019 15:14:29 +0100 Subject: Implement contact form on server side --- shared/models/server/contact-form.model.ts | 5 +++++ shared/models/server/custom-config.model.ts | 4 ++++ shared/models/server/index.ts | 6 ++++++ shared/models/server/server-config.model.ts | 4 ++++ shared/utils/miscs/email.ts | 4 ++++ shared/utils/server/config.ts | 3 +++ shared/utils/server/contact-form.ts | 28 ++++++++++++++++++++++++++++ 7 files changed, 54 insertions(+) create mode 100644 shared/models/server/contact-form.model.ts create mode 100644 shared/models/server/index.ts create mode 100644 shared/utils/server/contact-form.ts (limited to 'shared') diff --git a/shared/models/server/contact-form.model.ts b/shared/models/server/contact-form.model.ts new file mode 100644 index 000000000..0696be8b4 --- /dev/null +++ b/shared/models/server/contact-form.model.ts @@ -0,0 +1,5 @@ +export interface ContactForm { + fromEmail: string + fromName: string + body: string +} diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts index 028aafa1a..7a3eaa33f 100644 --- a/shared/models/server/custom-config.model.ts +++ b/shared/models/server/custom-config.model.ts @@ -41,6 +41,10 @@ export interface CustomConfig { email: string } + contactForm: { + enabled: boolean + } + user: { videoQuota: number videoQuotaDaily: number diff --git a/shared/models/server/index.ts b/shared/models/server/index.ts new file mode 100644 index 000000000..c42f6f67f --- /dev/null +++ b/shared/models/server/index.ts @@ -0,0 +1,6 @@ +export * from './about.model' +export * from './contact-form.model' +export * from './custom-config.model' +export * from './job.model' +export * from './server-config.model' +export * from './server-stats.model' diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index a6d28e05e..7031009d9 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts @@ -19,6 +19,10 @@ export interface ServerConfig { enabled: boolean } + contactForm: { + enabled: boolean + } + signup: { allowed: boolean, allowedForCurrentIP: boolean, diff --git a/shared/utils/miscs/email.ts b/shared/utils/miscs/email.ts index 6fac7621f..f9f1bd95b 100644 --- a/shared/utils/miscs/email.ts +++ b/shared/utils/miscs/email.ts @@ -15,6 +15,8 @@ class MockSmtpServer { return this.emails.push(msg.email) } }) + + process.on('exit', () => this.kill()) } collectEmails (emailsCollection: object[]) { @@ -42,6 +44,8 @@ class MockSmtpServer { } kill () { + if (!this.emailChildProcess) return + process.kill(this.emailChildProcess.pid) this.emailChildProcess = null diff --git a/shared/utils/server/config.ts b/shared/utils/server/config.ts index ff5288c82..0c5512bab 100644 --- a/shared/utils/server/config.ts +++ b/shared/utils/server/config.ts @@ -80,6 +80,9 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) { admin: { email: 'superadmin1@example.com' }, + contactForm: { + enabled: true + }, user: { videoQuota: 5242881, videoQuotaDaily: 318742 diff --git a/shared/utils/server/contact-form.ts b/shared/utils/server/contact-form.ts new file mode 100644 index 000000000..80394cf99 --- /dev/null +++ b/shared/utils/server/contact-form.ts @@ -0,0 +1,28 @@ +import * as request from 'supertest' +import { ContactForm } from '../../models/server' + +function sendContactForm (options: { + url: string, + fromEmail: string, + fromName: string, + body: string, + expectedStatus?: number +}) { + const path = '/api/v1/server/contact' + + const body: ContactForm = { + fromEmail: options.fromEmail, + fromName: options.fromName, + body: options.body + } + return request(options.url) + .post(path) + .send(body) + .expect(options.expectedStatus || 204) +} + +// --------------------------------------------------------------------------- + +export { + sendContactForm +} -- cgit v1.2.3