From d3e56c0c4b307c99e83fbafb7f2c5884cbc20055 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 10 Jan 2019 11:12:41 +0100 Subject: Implement contact form in the client --- server/controllers/api/config.ts | 2 +- server/initializers/checker-after-init.ts | 14 +++++++++++++- server/initializers/checker-before-init.ts | 2 +- server/lib/emailer.ts | 11 ++++------- server/middlewares/validators/server.ts | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 43b20e078..dd06a0597 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -65,7 +65,7 @@ async function getConfig (req: express.Request, res: express.Response) { } }, email: { - enabled: Emailer.Instance.isEnabled() + enabled: Emailer.isEnabled() }, contactForm: { enabled: CONFIG.CONTACT_FORM.ENABLED diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts index 72d846957..955d55206 100644 --- a/server/initializers/checker-after-init.ts +++ b/server/initializers/checker-after-init.ts @@ -10,6 +10,7 @@ import { getServerActor } from '../helpers/utils' import { RecentlyAddedStrategy } from '../../shared/models/redundancy' import { isArray } from '../helpers/custom-validators/misc' import { uniq } from 'lodash' +import { Emailer } from '../lib/emailer' async function checkActivityPubUrls () { const actor = await getServerActor() @@ -32,9 +33,19 @@ async function checkActivityPubUrls () { // Some checks on configuration files // Return an error message, or null if everything is okay function checkConfig () { - const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY + + if (!Emailer.isEnabled()) { + if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { + return 'Emailer is disabled but you require signup email verification.' + } + + if (CONFIG.CONTACT_FORM.ENABLED) { + logger.warn('Emailer is disabled so the contact form will not work.') + } + } // NSFW policy + const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY { const available = [ 'do_not_list', 'blur', 'display' ] if (available.indexOf(defaultNSFWPolicy) === -1) { @@ -68,6 +79,7 @@ function checkConfig () { } } + // Check storage directory locations if (isProdInstance()) { const configStorage = config.get('storage') for (const key of Object.keys(configStorage)) { diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts index a7bc7eec8..7905d9ffa 100644 --- a/server/initializers/checker-before-init.ts +++ b/server/initializers/checker-before-init.ts @@ -15,7 +15,7 @@ function checkMissedConfig () { 'storage.redundancy', 'storage.tmp', 'log.level', 'user.video_quota', 'user.video_quota_daily', - 'cache.previews.size', 'admin.email', + 'cache.previews.size', 'admin.email', 'contact_form.enabled', 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', 'redundancy.videos.strategies', 'redundancy.videos.check_interval', diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 9b1c5122f..f384a254e 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts @@ -18,7 +18,6 @@ class Emailer { private static instance: Emailer private initialized = false private transporter: Transporter - private enabled = false private constructor () {} @@ -27,7 +26,7 @@ class Emailer { if (this.initialized === true) return this.initialized = true - if (CONFIG.SMTP.HOSTNAME && CONFIG.SMTP.PORT) { + if (Emailer.isEnabled()) { logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT) let tls @@ -55,8 +54,6 @@ class Emailer { tls, auth }) - - this.enabled = true } else { if (!isTestInstance()) { logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!') @@ -64,8 +61,8 @@ class Emailer { } } - isEnabled () { - return this.enabled + static isEnabled () { + return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT } async checkConnectionOrDie () { @@ -374,7 +371,7 @@ class Emailer { } sendMail (to: string[], subject: string, text: string, from?: string) { - if (!this.enabled) { + if (!Emailer.isEnabled()) { throw new Error('Cannot send mail because SMTP is not configured.') } diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts index d82e19230..d85afc2ff 100644 --- a/server/middlewares/validators/server.ts +++ b/server/middlewares/validators/server.ts @@ -50,7 +50,7 @@ const contactAdministratorValidator = [ .end() } - if (Emailer.Instance.isEnabled() === false) { + if (Emailer.isEnabled() === false) { return res .status(409) .send({ error: 'Emailer is not enabled on this instance.' }) -- cgit v1.2.3