Commit ca845172 authored by NGPixel's avatar NGPixel

feat: setup wizard cleanup + upgrade UI

[ci skip]
parent c94e2d57
......@@ -8,6 +8,7 @@ import CONSTANTS from './constants'
import Vue from 'vue'
import VueResource from 'vue-resource'
import VueClipboards from 'vue-clipboards'
import VeeValidate from 'vee-validate'
import { ApolloClient, createBatchingNetworkInterface } from 'apollo-client'
import store from './store'
......@@ -83,6 +84,17 @@ Vue.use(VueResource)
Vue.use(VueClipboards)
Vue.use(localization.VueI18Next)
Vue.use(helpers)
Vue.use(VeeValidate, {
enableAutoClasses: true,
classNames: {
touched: 'is-touched', // the control has been blurred
untouched: 'is-untouched', // the control hasn't been blurred
valid: 'is-valid', // model is valid
invalid: 'is-invalid', // model is invalid
pristine: 'is-pristine', // control has not been interacted with
dirty: 'is-dirty' // control has been interacted with
}
})
// ====================================
// Register Vue Components
......
'use strict'
/* global siteConfig */
import VeeValidate from 'vee-validate'
import axios from 'axios'
Vue.use(VeeValidate, {
enableAutoClasses: true,
classNames: {
touched: 'is-touched', // the control has been blurred
untouched: 'is-untouched', // the control hasn't been blurred
valid: 'is-valid', // model is valid
invalid: 'is-invalid', // model is invalid
pristine: 'is-pristine', // control has not been interacted with
dirty: 'is-dirty' // control has been interacted with
}
})
export default {
name: 'configManager',
data() {
......@@ -42,12 +27,12 @@ export default {
results: []
},
conf: {
upgrade: false,
title: siteConfig.title || 'Wiki',
host: siteConfig.host || 'http://',
port: siteConfig.port || 80,
lang: siteConfig.lang || 'en',
public: (siteConfig.public === true),
db: siteConfig.db || 'mongodb://localhost:27017/wiki',
pathData: './data',
pathRepo: './repo',
gitUseRemote: (siteConfig.git !== false),
......@@ -82,28 +67,19 @@ export default {
perc = (this.syscheck.ok) ? '15%' : '5%'
break
case 'general':
perc = '20%'
perc = '25%'
break
case 'considerations':
perc = '30%'
break
case 'db':
perc = '35%'
break
case 'dbcheck':
perc = (this.dbcheck.ok) ? '50%' : '40%'
break
case 'paths':
perc = '55%'
break
case 'git':
perc = '60%'
perc = '50%'
break
case 'gitcheck':
perc = (this.gitcheck.ok) ? '75%' : '65%'
perc = (this.gitcheck.ok) ? '70%' : '55%'
break
case 'admin':
perc = '80%'
perc = '75%'
break
}
return perc
......@@ -176,48 +152,6 @@ export default {
this.state = 'considerations'
this.loading = false
},
proceedToDb: function (ev) {
let self = this
self.state = 'db'
self.loading = false
self.$nextTick(() => {
self.$validator.validateAll('db')
})
},
proceedToDbcheck: function (ev) {
let self = this
this.state = 'dbcheck'
this.loading = true
self.dbcheck = {
ok: false,
error: ''
}
this.$helpers._.delay(() => {
axios.post('/dbcheck', {
db: self.conf.db
}).then(resp => {
if (resp.data.ok === true) {
self.dbcheck.ok = true
} else {
self.dbcheck.ok = false
self.dbcheck.error = resp.data.error
}
self.loading = false
self.$nextTick()
}).catch(err => {
window.alert(err.message)
})
}, 1000)
},
proceedToPaths: function (ev) {
let self = this
self.state = 'paths'
self.loading = false
self.$nextTick(() => {
self.$validator.validateAll('paths')
})
},
proceedToGit: function (ev) {
let self = this
self.state = 'git'
......
......@@ -26,6 +26,7 @@ defaults:
readonly: false
site:
path: ''
lang: en
title: Wiki.js
configNamespaces:
- auth
......@@ -87,6 +88,9 @@ langs:
id: ko
name: Korean - 한국어
-
id: fa
name: Persian (Fārsi) - فارسی
-
id: pt
name: Portuguese - Português
-
......
......@@ -53,7 +53,9 @@ module.exports = () => {
// ----------------------------------------
app.get('*', (req, res) => {
res.render('configure/index')
fs.readJsonAsync(path.join(wiki.ROOTPATH, 'package.json')).then(packageObj => {
res.render('configure/index', { packageObj })
})
})
/**
......@@ -63,7 +65,7 @@ module.exports = () => {
Promise.mapSeries([
() => {
const semver = require('semver')
if (!semver.satisfies(semver.clean(process.version), '>=6.9.0')) {
if (!semver.satisfies(semver.clean(process.version), '>=6.11.1')) {
throw new Error('Node.js version is too old. Minimum is 6.11.1.')
}
return 'Node.js ' + process.version + ' detected. Minimum is 6.11.1.'
......@@ -114,43 +116,6 @@ module.exports = () => {
})
/**
* Check the DB connection
*/
app.post('/dbcheck', (req, res) => {
let mongo = require('mongodb').MongoClient
let mongoURI = cfgHelper.parseConfigValue(req.body.db)
mongo.connect(mongoURI, {
autoReconnect: false,
reconnectTries: 2,
reconnectInterval: 1000,
connectTimeoutMS: 5000,
socketTimeoutMS: 5000
}, (err, db) => {
if (err === null) {
// Try to create a test collection
db.createCollection('test', (err, results) => {
if (err === null) {
// Try to drop test collection
db.dropCollection('test', (err, results) => {
if (err === null) {
res.json({ ok: true })
} else {
res.json({ ok: false, error: 'Unable to delete test collection. Verify permissions. ' + err.message })
}
db.close()
})
} else {
res.json({ ok: false, error: 'Unable to create test collection. Verify permissions. ' + err.message })
db.close()
}
})
} else {
res.json({ ok: false, error: err.message })
}
})
})
/**
* Check the Git connection
*/
app.post('/gitcheck', (req, res) => {
......
'use strict'
/* global db, lang, rights, winston */
/* global wiki */
var express = require('express')
var router = express.Router()
......@@ -33,14 +33,14 @@ router.post('/profile', (req, res) => {
return res.render('error-forbidden')
}
return db.User.findById(req.user.id).then((usr) => {
return wiki.db.User.findById(req.user.id).then((usr) => {
usr.name = _.trim(req.body.name)
if (usr.provider === 'local' && req.body.password !== '********') {
let nPwd = _.trim(req.body.password)
if (nPwd.length < 6) {
return Promise.reject(new Error('New Password too short!'))
} else {
return db.User.hashPassword(nPwd).then((pwd) => {
return wiki.db.User.hashPassword(nPwd).then((pwd) => {
usr.password = pwd
return usr.save()
})
......@@ -61,9 +61,9 @@ router.get('/stats', (req, res) => {
}
Promise.all([
db.Entry.count(),
db.UplFile.count(),
db.User.count()
wiki.db.Entry.count(),
wiki.db.UplFile.count(),
wiki.db.User.count()
]).spread((totalEntries, totalUploads, totalUsers) => {
return res.render('pages/admin/stats', {
totalEntries, totalUploads, totalUsers, adminTab: 'stats'
......@@ -78,7 +78,7 @@ router.get('/users', (req, res) => {
return res.render('error-forbidden')
}
db.User.find({})
wiki.db.User.find({})
.select('-password -rights')
.sort('name email')
.exec().then((usrs) => {
......@@ -95,7 +95,7 @@ router.get('/users/:id', (req, res) => {
return res.render('error-forbidden')
}
db.User.findById(req.params.id)
wiki.db.User.findById(req.params.id)
.select('-password -providerId')
.exec().then((usr) => {
let usrOpts = {
......@@ -137,12 +137,12 @@ router.post('/users/create', (req, res) => {
return res.status(400).json({ msg: 'Name is missing' })
}
db.User.findOne({ email: nUsr.email, provider: nUsr.provider }).then(exUsr => {
wiki.db.User.findOne({ email: nUsr.email, provider: nUsr.provider }).then(exUsr => {
if (exUsr) {
return res.status(400).json({ msg: 'User already exists!' }) || true
}
let pwdGen = (nUsr.provider === 'local') ? db.User.hashPassword(nUsr.password) : Promise.resolve(true)
let pwdGen = (nUsr.provider === 'local') ? wiki.db.User.hashPassword(nUsr.password) : Promise.resolve(true)
return pwdGen.then(nPwd => {
if (nUsr.provider !== 'local') {
nUsr.password = ''
......@@ -158,37 +158,37 @@ router.post('/users/create', (req, res) => {
deny: false
}]
return db.User.create(nUsr).then(() => {
return wiki.db.User.create(nUsr).then(() => {
return res.json({ ok: true })
})
}).catch(err => {
winston.warn(err)
wiki.logger.warn(err)
return res.status(500).json({ msg: err })
})
}).catch(err => {
winston.warn(err)
wiki.logger.warn(err)
return res.status(500).json({ msg: err })
})
})
router.post('/users/:id', (req, res) => {
if (!res.locals.rights.manage) {
return res.status(401).json({ msg: lang.t('errors:unauthorized') })
return res.status(401).json({ msg: wiki.lang.t('errors:unauthorized') })
}
if (!validator.isMongoId(req.params.id)) {
return res.status(400).json({ msg: lang.t('errors:invaliduserid') })
return res.status(400).json({ msg: wiki.lang.t('errors:invaliduserid') })
}
return db.User.findById(req.params.id).then((usr) => {
return wiki.db.User.findById(req.params.id).then((usr) => {
usr.name = _.trim(req.body.name)
usr.rights = JSON.parse(req.body.rights)
if (usr.provider === 'local' && req.body.password !== '********') {
let nPwd = _.trim(req.body.password)
if (nPwd.length < 6) {
return Promise.reject(new Error(lang.t('errors:newpasswordtooshort')))
return Promise.reject(new Error(wiki.lang.t('errors:newpasswordtooshort')))
} else {
return db.User.hashPassword(nPwd).then((pwd) => {
return wiki.db.User.hashPassword(nPwd).then((pwd) => {
usr.password = pwd
return usr.save()
})
......@@ -199,7 +199,7 @@ router.post('/users/:id', (req, res) => {
}).then((usr) => {
// Update guest rights for future requests
if (usr.provider === 'local' && usr.email === 'guest') {
rights.guest = usr
wiki.rights.guest = usr
}
return usr
}).then(() => {
......@@ -214,14 +214,14 @@ router.post('/users/:id', (req, res) => {
*/
router.delete('/users/:id', (req, res) => {
if (!res.locals.rights.manage) {
return res.status(401).json({ msg: lang.t('errors:unauthorized') })
return res.status(401).json({ msg: wiki.lang.t('errors:unauthorized') })
}
if (!validator.isMongoId(req.params.id)) {
return res.status(400).json({ msg: lang.t('errors:invaliduserid') })
return res.status(400).json({ msg: wiki.lang.t('errors:invaliduserid') })
}
return db.User.findByIdAndRemove(req.params.id).then(() => {
return wiki.db.User.findByIdAndRemove(req.params.id).then(() => {
return res.json({ ok: true })
}).catch((err) => {
res.status(500).json({ ok: false, msg: err.message })
......@@ -249,7 +249,7 @@ router.get('/system', (req, res) => {
cwd: process.cwd()
}
fs.readJsonAsync(path.join(ROOTPATH, 'package.json')).then(packageObj => {
fs.readJsonAsync(path.join(wiki.ROOTPATH, 'package.json')).then(packageObj => {
axios.get('https://api.github.com/repos/Requarks/wiki/releases/latest').then(resp => {
let sysversion = {
current: 'v' + packageObj.version,
......@@ -259,7 +259,7 @@ router.get('/system', (req, res) => {
res.render('pages/admin/system', { adminTab: 'system', hostInfo, sysversion })
}).catch(err => {
winston.warn(err)
wiki.logger.warn(err)
res.render('pages/admin/system', { adminTab: 'system', hostInfo, sysversion: { current: 'v' + packageObj.version } })
})
})
......@@ -287,19 +287,19 @@ router.post('/theme', (req, res) => {
return res.render('error-forbidden')
}
if (!validator.isIn(req.body.primary, appdata.colors)) {
if (!validator.isIn(req.body.primary, wiki.data.colors)) {
return res.status(406).json({ msg: 'Primary color is invalid.' })
} else if (!validator.isIn(req.body.alt, appdata.colors)) {
} else if (!validator.isIn(req.body.alt, wiki.data.colors)) {
return res.status(406).json({ msg: 'Alternate color is invalid.' })
} else if (!validator.isIn(req.body.footer, appdata.colors)) {
} else if (!validator.isIn(req.body.footer, wiki.data.colors)) {
return res.status(406).json({ msg: 'Footer color is invalid.' })
}
appconfig.theme.primary = req.body.primary
appconfig.theme.alt = req.body.alt
appconfig.theme.footer = req.body.footer
appconfig.theme.code.dark = req.body.codedark === 'true'
appconfig.theme.code.colorize = req.body.codecolorize === 'true'
wiki.config.theme.primary = req.body.primary
wiki.config.theme.alt = req.body.alt
wiki.config.theme.footer = req.body.footer
wiki.config.theme.code.dark = req.body.codedark === 'true'
wiki.config.theme.code.colorize = req.body.codecolorize === 'true'
return res.json({ msg: 'OK' })
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment