ok lot of smtp minors

This commit is contained in:
lesion
2021-10-18 15:46:38 +02:00
parent 858d6b31c8
commit b63f22fd31
8 changed files with 76 additions and 35 deletions

View File

@@ -39,7 +39,8 @@ const defaultSettings = {
{ href: '/', label: 'home' },
{ href: '/about', label: 'about' }
],
admin_email: config.admin_email || ''
admin_email: config.admin_email || '',
smtp: config.smtp || false
}
/**
@@ -127,6 +128,19 @@ const settingsController = {
if (ret) { res.sendStatus(200) } else { res.sendStatus(400) }
},
async testSMTP (req, res) {
const smtp = req.body
await settingsController.set('smtp', smtp.smtp)
const mail = require('../mail')
try {
await mail._send(settingsController.settings.admin_email, 'test')
return res.sendStatus(200)
} catch (e) {
console.error(e)
return res.status(400).send(String(e))
}
},
setLogo (req, res) {
if (!req.file) {
settingsController.set('logo', false)

View File

@@ -1,18 +1,9 @@
const URL = require('url')
const helpers = require('../../helpers.js')
const log = require('../../log')
const db = require('../models/index.js')
const config = require('../../config')
const settingsController = require('./settings')
const crypto = require('crypto')
const { promisify } = require('util')
const randomBytes = promisify(crypto.randomBytes)
async function randomString (len = 16) {
const bytes = await randomBytes(len * 8)
return crypto
.createHash('sha1')
.update(bytes)
.digest('hex')
}
const setupController = {
@@ -62,8 +53,8 @@ const setupController = {
await settingsController.set('hostname', new URL.URL(settingsController.settings.baseurl).hostname)
// create admin
const password = await randomString()
const email = `admin@${settingsController.settings.hostname}`
const password = helpers.randomString()
const email = `admin`
const User = require('../models/user')
await User.create({
email,