Refactor email enabled function
This commit is contained in:
parent
45f1bd72a0
commit
4c1c170934
|
@ -12,12 +12,10 @@
|
||||||
display: grid !important;
|
display: grid !important;
|
||||||
grid-template-columns: 1fr auto;
|
grid-template-columns: 1fr auto;
|
||||||
grid-template-rows: 1fr auto / 1fr auto;
|
grid-template-rows: 1fr auto / 1fr auto;
|
||||||
grid-template-areas: "name buttons"
|
grid-template-areas: "name buttons" "lower buttons";
|
||||||
"lower buttons";
|
|
||||||
|
|
||||||
@media screen and (max-width: #{map-get($grid-breakpoints, lg)}) {
|
@media screen and (max-width: #{map-get($grid-breakpoints, lg)}) {
|
||||||
grid-template-areas: "name name"
|
grid-template-areas: "name name" "lower buttons";
|
||||||
"lower buttons";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,4 +51,4 @@
|
||||||
my-subscribe-button {
|
my-subscribe-button {
|
||||||
height: min-content;
|
height: min-content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,9 @@
|
||||||
import {
|
import { Component, ElementRef, OnDestroy, OnInit, QueryList, ViewChild } from '@angular/core'
|
||||||
Component,
|
import { ActivatedRoute, Params, Router } from '@angular/router'
|
||||||
OnInit,
|
|
||||||
OnDestroy,
|
|
||||||
QueryList,
|
|
||||||
ViewChild,
|
|
||||||
ElementRef
|
|
||||||
} from '@angular/core'
|
|
||||||
import { Router, Params, ActivatedRoute } from '@angular/router'
|
|
||||||
import { AuthService, ServerService } from '@app/core'
|
import { AuthService, ServerService } from '@app/core'
|
||||||
import { first, tap } from 'rxjs/operators'
|
import { first, tap } from 'rxjs/operators'
|
||||||
import { ListKeyManager } from '@angular/cdk/a11y'
|
import { ListKeyManager } from '@angular/cdk/a11y'
|
||||||
import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes'
|
import { Result, SuggestionComponent } from './suggestion.component'
|
||||||
import { SuggestionComponent, Result } from './suggestion.component'
|
|
||||||
import { of } from 'rxjs'
|
import { of } from 'rxjs'
|
||||||
import { ServerConfig } from '@shared/models'
|
import { ServerConfig } from '@shared/models'
|
||||||
|
|
||||||
|
@ -145,13 +137,13 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy {
|
||||||
handleKeyUp (event: KeyboardEvent) {
|
handleKeyUp (event: KeyboardEvent) {
|
||||||
event.stopImmediatePropagation()
|
event.stopImmediatePropagation()
|
||||||
if (!this.keyboardEventsManager) return
|
if (!this.keyboardEventsManager) return
|
||||||
|
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "ArrowDown":
|
case 'ArrowDown':
|
||||||
case "ArrowUp":
|
case 'ArrowUp':
|
||||||
this.keyboardEventsManager.onKeydown(event)
|
this.keyboardEventsManager.onKeydown(event)
|
||||||
break
|
break
|
||||||
case "Enter":
|
case 'Enter':
|
||||||
this.newSearch = false
|
this.newSearch = false
|
||||||
this.doSearch()
|
this.doSearch()
|
||||||
break
|
break
|
||||||
|
|
|
@ -103,8 +103,8 @@ $variables: (
|
||||||
|
|
||||||
$zindex: (
|
$zindex: (
|
||||||
header : 1000,
|
header : 1000,
|
||||||
/* header context */
|
/* header context */
|
||||||
headerLeft : 10,
|
headerLeft : 10,
|
||||||
menu : 11000,
|
menu : 11000,
|
||||||
dropdown : 12000,
|
dropdown : 12000,
|
||||||
loadbar : 13000,
|
loadbar : 13000,
|
||||||
|
|
|
@ -11,10 +11,9 @@ import { ClientHtml } from '../../lib/client-html'
|
||||||
import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger'
|
import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger'
|
||||||
import { remove, writeJSON } from 'fs-extra'
|
import { remove, writeJSON } from 'fs-extra'
|
||||||
import { getServerCommit } from '../../helpers/utils'
|
import { getServerCommit } from '../../helpers/utils'
|
||||||
import { Emailer } from '../../lib/emailer'
|
|
||||||
import validator from 'validator'
|
import validator from 'validator'
|
||||||
import { objectConverter } from '../../helpers/core-utils'
|
import { objectConverter } from '../../helpers/core-utils'
|
||||||
import { CONFIG, reloadConfig } from '../../initializers/config'
|
import { CONFIG, isEmailEnabled, reloadConfig } from '../../initializers/config'
|
||||||
import { PluginManager } from '../../lib/plugins/plugin-manager'
|
import { PluginManager } from '../../lib/plugins/plugin-manager'
|
||||||
import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
|
import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
|
||||||
import { Hooks } from '@server/lib/plugins/hooks'
|
import { Hooks } from '@server/lib/plugins/hooks'
|
||||||
|
@ -87,7 +86,7 @@ async function getConfig (req: express.Request, res: express.Response) {
|
||||||
default: defaultTheme
|
default: defaultTheme
|
||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
enabled: Emailer.isEnabled()
|
enabled: isEmailEnabled()
|
||||||
},
|
},
|
||||||
contactForm: {
|
contactForm: {
|
||||||
enabled: CONFIG.CONTACT_FORM.ENABLED
|
enabled: CONFIG.CONTACT_FORM.ENABLED
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import * as cors from 'cors'
|
import * as cors from 'cors'
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import {
|
import {
|
||||||
|
CONSTRAINTS_FIELDS,
|
||||||
|
DEFAULT_THEME_NAME,
|
||||||
HLS_STREAMING_PLAYLIST_DIRECTORY,
|
HLS_STREAMING_PLAYLIST_DIRECTORY,
|
||||||
PEERTUBE_VERSION,
|
PEERTUBE_VERSION,
|
||||||
ROUTE_CACHE_LIFETIME,
|
ROUTE_CACHE_LIFETIME,
|
||||||
STATIC_DOWNLOAD_PATHS,
|
STATIC_DOWNLOAD_PATHS,
|
||||||
STATIC_MAX_AGE,
|
STATIC_MAX_AGE,
|
||||||
STATIC_PATHS,
|
STATIC_PATHS,
|
||||||
WEBSERVER,
|
WEBSERVER
|
||||||
CONSTRAINTS_FIELDS,
|
|
||||||
DEFAULT_THEME_NAME
|
|
||||||
} from '../initializers/constants'
|
} from '../initializers/constants'
|
||||||
import { cacheRoute } from '../middlewares/cache'
|
import { cacheRoute } from '../middlewares/cache'
|
||||||
import { asyncMiddleware, videosDownloadValidator } from '../middlewares'
|
import { asyncMiddleware, videosDownloadValidator } from '../middlewares'
|
||||||
|
@ -19,8 +19,7 @@ import { VideoCommentModel } from '../models/video/video-comment'
|
||||||
import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo'
|
import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { root } from '../helpers/core-utils'
|
import { root } from '../helpers/core-utils'
|
||||||
import { CONFIG } from '../initializers/config'
|
import { CONFIG, isEmailEnabled } from '../initializers/config'
|
||||||
import { Emailer } from '../lib/emailer'
|
|
||||||
import { getPreview, getVideoCaption } from './lazy-static'
|
import { getPreview, getVideoCaption } from './lazy-static'
|
||||||
import { VideoStreamingPlaylistType } from '@shared/models/videos/video-streaming-playlist.type'
|
import { VideoStreamingPlaylistType } from '@shared/models/videos/video-streaming-playlist.type'
|
||||||
import { MVideoFile, MVideoFullLight } from '@server/typings/models'
|
import { MVideoFile, MVideoFullLight } from '@server/typings/models'
|
||||||
|
@ -249,7 +248,7 @@ async function generateNodeinfo (req: express.Request, res: express.Response) {
|
||||||
default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
|
default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
|
||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
enabled: Emailer.isEnabled()
|
enabled: isEmailEnabled()
|
||||||
},
|
},
|
||||||
contactForm: {
|
contactForm: {
|
||||||
enabled: CONFIG.CONTACT_FORM.ENABLED
|
enabled: CONFIG.CONTACT_FORM.ENABLED
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { UserRole } from '../../../shared'
|
||||||
import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants'
|
||||||
import { exists, isArray, isBooleanValid, isFileValid } from './misc'
|
import { exists, isArray, isBooleanValid, isFileValid } from './misc'
|
||||||
import { values } from 'lodash'
|
import { values } from 'lodash'
|
||||||
import { CONFIG } from '../../initializers/config'
|
import { isEmailEnabled } from '../../initializers/config'
|
||||||
|
|
||||||
const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
|
const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
|
||||||
|
|
||||||
|
@ -13,9 +13,8 @@ function isUserPasswordValid (value: string) {
|
||||||
|
|
||||||
function isUserPasswordValidOrEmpty (value: string) {
|
function isUserPasswordValidOrEmpty (value: string) {
|
||||||
// Empty password is only possible if emailing is enabled.
|
// Empty password is only possible if emailing is enabled.
|
||||||
if (value === '') {
|
if (value === '') return isEmailEnabled()
|
||||||
return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
|
|
||||||
}
|
|
||||||
return isUserPasswordValid(value)
|
return isUserPasswordValid(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,12 @@ import { UserModel } from '../models/account/user'
|
||||||
import { ApplicationModel } from '../models/application/application'
|
import { ApplicationModel } from '../models/application/application'
|
||||||
import { OAuthClientModel } from '../models/oauth/oauth-client'
|
import { OAuthClientModel } from '../models/oauth/oauth-client'
|
||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
import { CONFIG } from './config'
|
import { CONFIG, isEmailEnabled } from './config'
|
||||||
import { logger } from '../helpers/logger'
|
import { logger } from '../helpers/logger'
|
||||||
import { getServerActor } from '../helpers/utils'
|
import { getServerActor } from '../helpers/utils'
|
||||||
import { RecentlyAddedStrategy } from '../../shared/models/redundancy'
|
import { RecentlyAddedStrategy } from '../../shared/models/redundancy'
|
||||||
import { isArray } from '../helpers/custom-validators/misc'
|
import { isArray } from '../helpers/custom-validators/misc'
|
||||||
import { uniq } from 'lodash'
|
import { uniq } from 'lodash'
|
||||||
import { Emailer } from '../lib/emailer'
|
|
||||||
import { WEBSERVER } from './constants'
|
import { WEBSERVER } from './constants'
|
||||||
|
|
||||||
async function checkActivityPubUrls () {
|
async function checkActivityPubUrls () {
|
||||||
|
@ -41,7 +40,7 @@ function checkConfig () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Email verification
|
// Email verification
|
||||||
if (!Emailer.isEnabled()) {
|
if (!isEmailEnabled()) {
|
||||||
if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) {
|
if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) {
|
||||||
return 'Emailer is disabled but you require signup email verification.'
|
return 'Emailer is disabled but you require signup email verification.'
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,11 +284,16 @@ function registerConfigChangedHandler (fun: Function) {
|
||||||
configChangedHandlers.push(fun)
|
configChangedHandlers.push(fun)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isEmailEnabled () {
|
||||||
|
return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
CONFIG,
|
CONFIG,
|
||||||
registerConfigChangedHandler
|
registerConfigChangedHandler,
|
||||||
|
isEmailEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { createTransport, Transporter } from 'nodemailer'
|
import { createTransport, Transporter } from 'nodemailer'
|
||||||
import { isTestInstance } from '../helpers/core-utils'
|
import { isTestInstance } from '../helpers/core-utils'
|
||||||
import { bunyanLogger, logger } from '../helpers/logger'
|
import { bunyanLogger, logger } from '../helpers/logger'
|
||||||
import { CONFIG } from '../initializers/config'
|
import { CONFIG, isEmailEnabled } from '../initializers/config'
|
||||||
import { JobQueue } from './job-queue'
|
import { JobQueue } from './job-queue'
|
||||||
import { EmailPayload } from './job-queue/handlers/email'
|
import { EmailPayload } from './job-queue/handlers/email'
|
||||||
import { readFileSync } from 'fs-extra'
|
import { readFileSync } from 'fs-extra'
|
||||||
|
@ -40,7 +40,7 @@ class Emailer {
|
||||||
if (this.initialized === true) return
|
if (this.initialized === true) return
|
||||||
this.initialized = true
|
this.initialized = true
|
||||||
|
|
||||||
if (Emailer.isEnabled()) {
|
if (isEmailEnabled) {
|
||||||
logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
|
logger.info('Using %s:%s as SMTP server.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT)
|
||||||
|
|
||||||
let tls
|
let tls
|
||||||
|
@ -459,7 +459,7 @@ class Emailer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendMail (options: EmailPayload) {
|
async sendMail (options: EmailPayload) {
|
||||||
if (!Emailer.isEnabled()) {
|
if (!isEmailEnabled()) {
|
||||||
throw new Error('Cannot send mail because SMTP is not configured.')
|
throw new Error('Cannot send mail because SMTP is not configured.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@ import { body } from 'express-validator'
|
||||||
import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
|
import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { CustomConfig } from '../../../shared/models/server/custom-config.model'
|
import { CustomConfig } from '../../../shared/models/server/custom-config.model'
|
||||||
import { Emailer } from '../../lib/emailer'
|
|
||||||
import { areValidationErrors } from './utils'
|
import { areValidationErrors } from './utils'
|
||||||
import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
|
import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
|
||||||
import { isThemeRegistered } from '../../lib/plugins/theme-utils'
|
import { isThemeRegistered } from '../../lib/plugins/theme-utils'
|
||||||
|
import { isEmailEnabled } from '@server/initializers/config'
|
||||||
|
|
||||||
const customConfigUpdateValidator = [
|
const customConfigUpdateValidator = [
|
||||||
body('instance.name').exists().withMessage('Should have a valid instance name'),
|
body('instance.name').exists().withMessage('Should have a valid instance name'),
|
||||||
|
@ -73,7 +73,7 @@ export {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) {
|
function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) {
|
||||||
if (Emailer.isEnabled()) return true
|
if (isEmailEnabled()) return true
|
||||||
|
|
||||||
if (customConfig.signup.requiresEmailVerification === true) {
|
if (customConfig.signup.requiresEmailVerification === true) {
|
||||||
res.status(400)
|
res.status(400)
|
||||||
|
|
|
@ -5,9 +5,8 @@ import { isHostValid, isValidContactBody } from '../../helpers/custom-validators
|
||||||
import { ServerModel } from '../../models/server/server'
|
import { ServerModel } from '../../models/server/server'
|
||||||
import { body } from 'express-validator'
|
import { body } from 'express-validator'
|
||||||
import { isUserDisplayNameValid } from '../../helpers/custom-validators/users'
|
import { isUserDisplayNameValid } from '../../helpers/custom-validators/users'
|
||||||
import { Emailer } from '../../lib/emailer'
|
|
||||||
import { Redis } from '../../lib/redis'
|
import { Redis } from '../../lib/redis'
|
||||||
import { CONFIG } from '../../initializers/config'
|
import { CONFIG, isEmailEnabled } from '../../initializers/config'
|
||||||
|
|
||||||
const serverGetValidator = [
|
const serverGetValidator = [
|
||||||
body('host').custom(isHostValid).withMessage('Should have a valid host'),
|
body('host').custom(isHostValid).withMessage('Should have a valid host'),
|
||||||
|
@ -50,7 +49,7 @@ const contactAdministratorValidator = [
|
||||||
.end()
|
.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Emailer.isEnabled() === false) {
|
if (isEmailEnabled() === false) {
|
||||||
return res
|
return res
|
||||||
.status(409)
|
.status(409)
|
||||||
.send({ error: 'Emailer is not enabled on this instance.' })
|
.send({ error: 'Emailer is not enabled on this instance.' })
|
||||||
|
|
Loading…
Reference in New Issue