feat: admin general + verify account
This commit is contained in:
parent
2b98a5f27a
commit
fcee4c0945
@ -80,7 +80,7 @@ const graphQLLink = ApolloLink.from([
|
||||
})
|
||||
}
|
||||
}),
|
||||
createPersistedQueryLink(),
|
||||
// createPersistedQueryLink(),
|
||||
new BatchHttpLink({
|
||||
includeExtensions: true,
|
||||
uri: graphQLEndpoint,
|
||||
|
@ -22,11 +22,21 @@
|
||||
v-subheader General
|
||||
.px-3.pb-3
|
||||
v-text-field(
|
||||
outline
|
||||
label='Site URL'
|
||||
required
|
||||
:counter='255'
|
||||
v-model='config.host'
|
||||
prepend-icon='label_important'
|
||||
hint='Full URL to your wiki, without the trailing slash. (e.g. https://wiki.example.com)'
|
||||
persistent-hint
|
||||
)
|
||||
v-text-field.mt-2(
|
||||
outline
|
||||
label='Site Title'
|
||||
required
|
||||
:counter='50'
|
||||
v-model='siteTitle'
|
||||
v-model='config.title'
|
||||
prepend-icon='public'
|
||||
)
|
||||
v-divider
|
||||
@ -36,22 +46,28 @@
|
||||
outline
|
||||
label='Site Description'
|
||||
:counter='255'
|
||||
prepend-icon='public'
|
||||
v-model='config.description'
|
||||
prepend-icon='explore'
|
||||
)
|
||||
v-text-field(
|
||||
outline
|
||||
label='Site Keywords'
|
||||
:counter='255'
|
||||
prepend-icon='public'
|
||||
v-model='config.keywords'
|
||||
prepend-icon='explore'
|
||||
hint='Comma-separated list of keywords.'
|
||||
persistent-hint
|
||||
)
|
||||
v-select(
|
||||
v-select.mt-2(
|
||||
outline
|
||||
label='Meta Robots'
|
||||
chips
|
||||
tags
|
||||
multiple
|
||||
:items='metaRobots'
|
||||
v-model='metaRobotsSelection'
|
||||
prepend-icon='public'
|
||||
v-model='config.robots'
|
||||
prepend-icon='explore'
|
||||
:return-object='false'
|
||||
hint='Default: Index, Follow'
|
||||
persistent-hint
|
||||
)
|
||||
v-divider
|
||||
v-subheader Analytics
|
||||
@ -60,30 +76,20 @@
|
||||
outline
|
||||
label='Google Analytics ID'
|
||||
:counter='255'
|
||||
v-model='config.ga'
|
||||
prepend-icon='timeline'
|
||||
persistent-hint
|
||||
hint='Property tracking ID for Google Analytics.'
|
||||
)
|
||||
v-divider
|
||||
v-subheader Footer Copyright
|
||||
.px-3.pb-3
|
||||
v-text-field(
|
||||
outline
|
||||
label='Company / Organization Name'
|
||||
v-model='company'
|
||||
:counter='255'
|
||||
prepend-icon='business'
|
||||
persistent-hint
|
||||
hint='Name to use when displaying copyright notice in the footer. Leave empty to hide.'
|
||||
hint='Property tracking ID for Google Analytics. Leave empty to disable.'
|
||||
)
|
||||
v-flex(lg6 xs12)
|
||||
v-card.wiki-form
|
||||
v-toolbar(color='primary', dark, dense, flat)
|
||||
v-toolbar-title
|
||||
.subheading {{ $t('admin:general.siteBranding') }}
|
||||
v-subheader Logo
|
||||
v-card-text
|
||||
v-layout.pa-3(row, align-center)
|
||||
v-avatar(size='120', color='grey lighten-3', :tile='useSquareLogo')
|
||||
v-layout.px-3(row, align-center)
|
||||
v-avatar(size='120', color='grey lighten-3', :tile='config.logoIsSquare')
|
||||
.ml-4
|
||||
v-layout(row, align-center)
|
||||
v-btn(color='teal', depressed, dark)
|
||||
@ -95,19 +101,23 @@
|
||||
.caption.grey--text An image of 120x120 pixels is recommended for best results.
|
||||
.caption.grey--text SVG, PNG or JPG files only.
|
||||
v-switch(
|
||||
v-model='useSquareLogo'
|
||||
v-model='config.logoIsSquare'
|
||||
label='Use Square Logo Frame'
|
||||
color='primary'
|
||||
persistent-hint
|
||||
hint='Check this option if a round logo frame doesn\'t work with your logo.'
|
||||
)
|
||||
v-divider.mt-3
|
||||
v-switch(
|
||||
v-model='displayMascot'
|
||||
label='Display Wiki.js Mascot'
|
||||
color='primary'
|
||||
v-divider
|
||||
v-subheader Footer Copyright
|
||||
.px-3.pb-3
|
||||
v-text-field(
|
||||
outline
|
||||
label='Company / Organization Name'
|
||||
v-model='config.company'
|
||||
:counter='255'
|
||||
prepend-icon='business'
|
||||
persistent-hint
|
||||
hint='Uncheck this box if you don\'t want Henry, Wiki.js mascot, to be displayed on client-facing pages.'
|
||||
hint='Name to use when displaying copyright notice in the footer. Leave empty to hide.'
|
||||
)
|
||||
|
||||
v-card.wiki-form.mt-3
|
||||
@ -116,17 +126,25 @@
|
||||
.subheading Features
|
||||
v-card-text
|
||||
v-switch(
|
||||
v-model='featurePageRatings'
|
||||
label='Page Ratings'
|
||||
color='primary'
|
||||
v-model='config.featurePageRatings'
|
||||
persistent-hint
|
||||
hint='Allow users to rate pages.'
|
||||
)
|
||||
v-divider.mt-3
|
||||
v-switch(
|
||||
v-model='featurePersonalWiki'
|
||||
label='Page Comments'
|
||||
color='primary'
|
||||
v-model='config.featurePageComments'
|
||||
persistent-hint
|
||||
hint='Allow users to leave comments on pages.'
|
||||
)
|
||||
v-divider.mt-3
|
||||
v-switch(
|
||||
label='Personal Wikis'
|
||||
color='primary'
|
||||
v-model='config.featurePersonalWikis'
|
||||
persistent-hint
|
||||
hint='Allow users to have their own personal wiki.'
|
||||
)
|
||||
@ -134,18 +152,34 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import _ from 'lodash'
|
||||
import { get, sync } from 'vuex-pathify'
|
||||
import siteConfigQuery from 'gql/admin/site/site-query-config.gql'
|
||||
import siteUpdateConfigMutation from 'gql/admin/site/site-mutation-save-config.gql'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
metaRobotsSelection: ['Index', 'Follow'],
|
||||
metaRobots: ['Index', 'Follow', 'No Index', 'No Follow'],
|
||||
useSquareLogo: false,
|
||||
displayMascot: true,
|
||||
featurePageRatings: true,
|
||||
featurePersonalWiki: true
|
||||
metaRobots: [
|
||||
{ text: 'Index', value: 'index' },
|
||||
{ text: 'Follow', value: 'follow' },
|
||||
{ text: 'No Index', value: 'noindex' },
|
||||
{ text: 'No Follow', value: 'nofollow' }
|
||||
],
|
||||
config: {
|
||||
host: '',
|
||||
title: '',
|
||||
description: '',
|
||||
keywords: '',
|
||||
robots: [],
|
||||
ga: '',
|
||||
company: '',
|
||||
hasLogo: false,
|
||||
logoIsSquare: false,
|
||||
featurePageRatings: false,
|
||||
featurePageComments: false,
|
||||
featurePersonalWikis: false
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -155,11 +189,51 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async save () {
|
||||
try {
|
||||
await this.$apollo.mutate({
|
||||
mutation: siteUpdateConfigMutation,
|
||||
variables: {
|
||||
host: this.config.host || '',
|
||||
title: this.config.title || '',
|
||||
description: this.config.description || '',
|
||||
keywords: this.config.keywords || '',
|
||||
robots: this.config.robots || [],
|
||||
ga: this.config.ga || '',
|
||||
company: this.config.company || '',
|
||||
hasLogo: this.config.hasLogo || false,
|
||||
logoIsSquare: this.config.logoIsSquare || false,
|
||||
featurePageRatings: this.config.featurePageRatings || false,
|
||||
featurePageComments: this.config.featurePageComments || false,
|
||||
featurePersonalWikis: this.config.featurePersonalWikis || false
|
||||
},
|
||||
watchLoading (isLoading) {
|
||||
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-site-update')
|
||||
}
|
||||
})
|
||||
this.$store.commit('showNotification', {
|
||||
message: 'Configuration saved successfully.',
|
||||
style: 'success',
|
||||
message: 'Configuration saved successfully.',
|
||||
icon: 'check'
|
||||
})
|
||||
this.siteTitle = this.config.title
|
||||
this.company = this.config.company
|
||||
} catch (err) {
|
||||
this.$store.commit('showNotification', {
|
||||
style: 'red',
|
||||
message: err.message,
|
||||
icon: 'warning'
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
apollo: {
|
||||
config: {
|
||||
query: siteConfigQuery,
|
||||
fetchPolicy: 'network-only',
|
||||
update: (data) => _.cloneDeep(data.site.config),
|
||||
watchLoading (isLoading) {
|
||||
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-site-refresh')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@
|
||||
item-text='name'
|
||||
:label='$t("admin:locale.activeNamespaces.label")'
|
||||
persistent-hint
|
||||
small-chips
|
||||
:hint='$t("admin:locale.activeNamespaces.hint")'
|
||||
)
|
||||
template(slot='item', slot-scope='data')
|
||||
|
@ -3,10 +3,12 @@
|
||||
v-card.loader-dialog.radius-7(:color='color', dark)
|
||||
v-card-text.text-xs-center.py-4
|
||||
atom-spinner.is-inline(
|
||||
v-if='mode === `loading`'
|
||||
:animation-duration='1000'
|
||||
:size='60'
|
||||
color='#FFF'
|
||||
)
|
||||
img(v-else-if='mode === `icon`', :src='`/svg/icon-` + icon + `.svg`', :alt='icon')
|
||||
.subheading {{ title }}
|
||||
.caption {{ subtitle }}
|
||||
</template>
|
||||
@ -34,6 +36,14 @@ export default {
|
||||
subtitle: {
|
||||
type: String,
|
||||
default: 'Please wait'
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
default: 'loading'
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
default: 'checkmark'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -47,5 +57,9 @@ export default {
|
||||
.caption {
|
||||
color: rgba(255,255,255,.7);
|
||||
}
|
||||
|
||||
img {
|
||||
width: 80px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -90,7 +90,7 @@
|
||||
a.caption(href='/login', place='link') {{ $t('auth:switchToLogin.link') }}
|
||||
v-spacer
|
||||
|
||||
loader(v-model='isLoading', :color='loaderColor', :title='loaderTitle', :subtitle='$t(`auth:pleaseWait`)')
|
||||
loader(v-model='isLoading', :mode='loaderMode', :icon='loaderIcon', :color='loaderColor', :title='loaderTitle', :subtitle='loaderSubtitle')
|
||||
nav-footer(color='grey darken-4', dark-color='grey darken-4')
|
||||
</template>
|
||||
|
||||
@ -119,7 +119,10 @@ export default {
|
||||
isLoading: false,
|
||||
isShown: false,
|
||||
loaderColor: 'grey darken-4',
|
||||
loaderTitle: 'Working...'
|
||||
loaderTitle: 'Working...',
|
||||
loaderSubtitle: 'Please wait',
|
||||
loaderMode: 'icon',
|
||||
loaderIcon: 'checkmark'
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -131,6 +134,7 @@ export default {
|
||||
this.isShown = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.iptEmail.focus()
|
||||
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
@ -216,6 +220,8 @@ export default {
|
||||
} else {
|
||||
this.loaderColor = 'grey darken-4'
|
||||
this.loaderTitle = this.$t('auth:registering')
|
||||
this.loaderSubtitle = this.$t(`auth:pleaseWait`)
|
||||
this.loaderMode = 'loading'
|
||||
this.isLoading = true
|
||||
try {
|
||||
let resp = await this.$apollo.mutate({
|
||||
@ -229,12 +235,11 @@ export default {
|
||||
if (_.has(resp, 'data.authentication.register')) {
|
||||
let respObj = _.get(resp, 'data.authentication.register', {})
|
||||
if (respObj.responseResult.succeeded === true) {
|
||||
this.loaderColor = 'green'
|
||||
this.loaderColor = 'grey darken-4'
|
||||
this.loaderTitle = this.$t('auth:registerSuccess')
|
||||
Cookies.set('jwt', respObj.jwt, { expires: 365 })
|
||||
_.delay(() => {
|
||||
window.location.replace('/')
|
||||
}, 1000)
|
||||
this.loaderSubtitle = this.$t(`auth:registerCheckEmail`)
|
||||
this.loaderMode = 'icon'
|
||||
this.isShown = false
|
||||
} else {
|
||||
throw new Error(respObj.responseResult.message)
|
||||
}
|
||||
|
38
client/graph/admin/site/site-mutation-save-config.gql
Normal file
38
client/graph/admin/site/site-mutation-save-config.gql
Normal file
@ -0,0 +1,38 @@
|
||||
mutation (
|
||||
$host: String!
|
||||
$title: String!
|
||||
$description: String!
|
||||
$keywords: String!
|
||||
$robots: [String]!
|
||||
$ga: String!
|
||||
$company: String!
|
||||
$hasLogo: Boolean!
|
||||
$logoIsSquare: Boolean!
|
||||
$featurePageRatings: Boolean!
|
||||
$featurePageComments: Boolean!
|
||||
$featurePersonalWikis: Boolean!
|
||||
) {
|
||||
site {
|
||||
updateConfig(
|
||||
host: $host,
|
||||
title: $title,
|
||||
description: $description,
|
||||
keywords: $keywords,
|
||||
robots: $robots,
|
||||
ga: $ga,
|
||||
company: $company,
|
||||
hasLogo: $hasLogo,
|
||||
logoIsSquare: $logoIsSquare,
|
||||
featurePageRatings: $featurePageRatings,
|
||||
featurePageComments: $featurePageComments,
|
||||
featurePersonalWikis: $featurePersonalWikis
|
||||
) {
|
||||
responseResult {
|
||||
succeeded
|
||||
errorCode
|
||||
slug
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
client/graph/admin/site/site-query-config.gql
Normal file
18
client/graph/admin/site/site-query-config.gql
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
site {
|
||||
config {
|
||||
host
|
||||
title
|
||||
description
|
||||
keywords
|
||||
robots
|
||||
ga
|
||||
company
|
||||
hasLogo
|
||||
logoIsSquare
|
||||
featurePageRatings
|
||||
featurePageComments
|
||||
featurePersonalWikis
|
||||
}
|
||||
}
|
||||
}
|
14
client/static/svg/icon-checkmark.svg
Normal file
14
client/static/svg/icon-checkmark.svg
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Generator: Adobe Illustrator 20.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Слой_1" x="0px" y="0px" viewBox="0 0 64 64" style="enable-background:new 0 0 64 64;" xml:space="preserve" width="64px" height="64px">
|
||||
<linearGradient id="SVGID_1__48003" gradientUnits="userSpaceOnUse" x1="32" y1="12.6636" x2="32" y2="52.4219" spreadMethod="reflect">
|
||||
<stop offset="0" style="stop-color:#1A6DFF"/>
|
||||
<stop offset="1" style="stop-color:#C822FF"/>
|
||||
</linearGradient>
|
||||
<path style="fill:url(#SVGID_1__48003);" d="M24.982,51c-1.273,0-2.547-0.475-3.524-1.429L6.888,35.364C6.315,34.806,6,34.061,6,33.268 s0.315-1.538,0.889-2.097l2.82-2.75c1.166-1.137,3.063-1.137,4.228,0.001l10.259,10.003c0.395,0.385,1.058,0.38,1.446-0.012 l24.341-24.526c1.147-1.156,3.044-1.186,4.228-0.068l2.867,2.705c0.582,0.55,0.91,1.29,0.923,2.083 c0.013,0.793-0.291,1.542-0.854,2.109L28.565,49.514C27.584,50.504,26.283,51,24.982,51z M11.822,29.564 c-0.26,0-0.52,0.097-0.717,0.29l-2.82,2.75C8.101,32.783,8,33.018,8,33.268s0.102,0.485,0.285,0.664l14.569,14.208 c1.19,1.163,3.116,1.148,4.291-0.034l28.581-28.798c0.181-0.182,0.277-0.418,0.273-0.668c-0.004-0.25-0.109-0.485-0.296-0.661 l-2.867-2.705c-0.401-0.381-1.047-0.369-1.435,0.022L27.061,39.823c-1.166,1.173-3.079,1.189-4.263,0.034L12.54,29.853 C12.343,29.66,12.083,29.564,11.822,29.564z"/>
|
||||
<linearGradient id="SVGID_2__48003" gradientUnits="userSpaceOnUse" x1="32.0125" y1="16.8302" x2="32.0125" y2="47.5263" spreadMethod="reflect">
|
||||
<stop offset="0" style="stop-color:#6DC7FF"/>
|
||||
<stop offset="1" style="stop-color:#E6ABFF"/>
|
||||
</linearGradient>
|
||||
<path style="fill:url(#SVGID_2__48003);" d="M24.977,46.609c-0.489,0-0.98-0.181-1.368-0.544L10.318,33.603l1.367-1.459l13.292,12.461 L52.293,17.29l1.414,1.414L26.391,46.019C26,46.411,25.489,46.609,24.977,46.609z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.9 KiB |
@ -113,6 +113,7 @@
|
||||
"mssql": "4.2.3",
|
||||
"multer": "1.4.1",
|
||||
"mysql2": "1.6.4",
|
||||
"nanoid": "2.0.0",
|
||||
"node-2fa": "1.1.2",
|
||||
"node-cache": "4.2.0",
|
||||
"nodemailer": "4.7.0",
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
const express = require('express')
|
||||
const router = express.Router()
|
||||
const moment = require('moment')
|
||||
|
||||
/**
|
||||
* Login form
|
||||
@ -30,6 +31,17 @@ router.get('/register', async (req, res, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Verify
|
||||
*/
|
||||
router.get('/verify/:token', async (req, res, next) => {
|
||||
const usr = await WIKI.models.userKeys.validateToken({ kind: 'verify', token: req.params.token })
|
||||
await WIKI.models.users.query().patch({ isVerified: true }).where('id', usr.id)
|
||||
const result = await WIKI.models.users.refreshToken(usr)
|
||||
res.cookie('jwt', result.token, { expires: moment().add(1, 'years').toDate() })
|
||||
res.redirect('/')
|
||||
})
|
||||
|
||||
/**
|
||||
* JWT Public Endpoints
|
||||
*/
|
||||
|
@ -48,14 +48,14 @@ module.exports = {
|
||||
}
|
||||
await this.loadTemplate(opts.template)
|
||||
return this.transport.sendMail({
|
||||
from: 'noreply@requarks.io',
|
||||
from: `"${WIKI.config.mail.senderName}" <${WIKI.config.mail.senderEmail}>`,
|
||||
to: opts.to,
|
||||
subject: `${opts.subject} - ${WIKI.config.title}`,
|
||||
text: opts.text,
|
||||
html: _.get(this.templates, opts.template)({
|
||||
logo: '',
|
||||
siteTitle: WIKI.config.title,
|
||||
copyright: 'Powered by Wiki.js',
|
||||
copyright: WIKI.config.company.length > 0 ? WIKI.config.company : 'Powered by Wiki.js',
|
||||
...opts.data
|
||||
})
|
||||
})
|
||||
|
@ -175,7 +175,7 @@ exports.up = knex => {
|
||||
table.charset('utf8mb4')
|
||||
table.increments('id').primary()
|
||||
table.string('kind').notNullable()
|
||||
table.string('key').notNullable()
|
||||
table.string('token').notNullable()
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('validUntil').notNullable()
|
||||
})
|
||||
|
@ -61,13 +61,7 @@ module.exports = {
|
||||
async register(obj, args, context) {
|
||||
try {
|
||||
await WIKI.models.users.register(args, context)
|
||||
const authResult = await WIKI.models.users.login({
|
||||
username: args.email,
|
||||
password: args.password,
|
||||
strategy: 'local'
|
||||
}, context)
|
||||
return {
|
||||
jwt: authResult.jwt,
|
||||
responseResult: graphHelper.generateSuccess('Registration success')
|
||||
}
|
||||
} catch (err) {
|
||||
|
56
server/graph/resolvers/site.js
Normal file
56
server/graph/resolvers/site.js
Normal file
@ -0,0 +1,56 @@
|
||||
const _ = require('lodash')
|
||||
const graphHelper = require('../../helpers/graph')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
async site() { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
async site() { return {} }
|
||||
},
|
||||
SiteQuery: {
|
||||
async config(obj, args, context, info) {
|
||||
return {
|
||||
host: WIKI.config.host,
|
||||
title: WIKI.config.title,
|
||||
company: WIKI.config.company,
|
||||
...WIKI.config.seo,
|
||||
...WIKI.config.logo,
|
||||
...WIKI.config.features
|
||||
}
|
||||
}
|
||||
},
|
||||
SiteMutation: {
|
||||
async updateConfig(obj, args, context) {
|
||||
try {
|
||||
WIKI.config.host = args.host
|
||||
WIKI.config.title = args.title
|
||||
WIKI.config.company = args.company
|
||||
WIKI.config.seo = {
|
||||
description: args.description,
|
||||
keywords: args.keywords,
|
||||
robots: args.robots,
|
||||
ga: args.ga
|
||||
}
|
||||
WIKI.config.logo = {
|
||||
hasLogo: args.hasLogo,
|
||||
logoIsSquare: args.logoIsSquare
|
||||
}
|
||||
WIKI.config.features = {
|
||||
featurePageRatings: args.featurePageRatings,
|
||||
featurePageComments: args.featurePageComments,
|
||||
featurePersonalWikis: args.featurePersonalWikis
|
||||
}
|
||||
await WIKI.configSvc.saveToDb(['host', 'title', 'company', 'seo', 'logo', 'features'])
|
||||
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Site configuration updated successfully')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
59
server/graph/schemas/site.graphql
Normal file
59
server/graph/schemas/site.graphql
Normal file
@ -0,0 +1,59 @@
|
||||
# ===============================================
|
||||
# SITE
|
||||
# ===============================================
|
||||
|
||||
extend type Query {
|
||||
site: SiteQuery
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
site: SiteMutation
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
|
||||
type SiteQuery {
|
||||
config: SiteConfig @auth(requires: ["manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# MUTATIONS
|
||||
# -----------------------------------------------
|
||||
|
||||
type SiteMutation {
|
||||
updateConfig(
|
||||
host: String!
|
||||
title: String!
|
||||
description: String!
|
||||
keywords: String!
|
||||
robots: [String]!
|
||||
ga: String!
|
||||
company: String!
|
||||
hasLogo: Boolean!
|
||||
logoIsSquare: Boolean!
|
||||
featurePageRatings: Boolean!
|
||||
featurePageComments: Boolean!
|
||||
featurePersonalWikis: Boolean!
|
||||
): DefaultResponse @auth(requires: ["manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
||||
|
||||
type SiteConfig {
|
||||
host: String!
|
||||
title: String!
|
||||
description: String!
|
||||
keywords: String!
|
||||
robots: [String]!
|
||||
ga: String!
|
||||
company: String!
|
||||
hasLogo: Boolean!
|
||||
logoIsSquare: Boolean!
|
||||
featurePageRatings: Boolean!
|
||||
featurePageComments: Boolean!
|
||||
featurePersonalWikis: Boolean!
|
||||
}
|
@ -41,6 +41,10 @@ module.exports = {
|
||||
message: 'Invalid TFA Security Code or Login Token.',
|
||||
code: 1006
|
||||
}),
|
||||
AuthValidationTokenInvalid: CustomError('AuthValidationTokenInvalid', {
|
||||
message: 'Invalid validation token.',
|
||||
code: 1018
|
||||
}),
|
||||
BruteInstanceIsInvalid: CustomError('BruteInstanceIsInvalid', {
|
||||
message: 'Invalid Brute Force Instance.',
|
||||
code: 1007
|
||||
|
@ -40,7 +40,7 @@ module.exports = class Authentication extends Model {
|
||||
...str,
|
||||
domainWhitelist: _.get(str.domainWhitelist, 'v', []),
|
||||
autoEnrollGroups: _.get(str.autoEnrollGroups, 'v', [])
|
||||
})), ['title'])
|
||||
})), ['key'])
|
||||
}
|
||||
|
||||
static async refreshStrategiesFromDisk() {
|
||||
|
@ -35,7 +35,7 @@ module.exports = class Setting extends Model {
|
||||
const settings = await WIKI.models.settings.query()
|
||||
if (settings.length > 0) {
|
||||
return _.reduce(settings, (res, val, key) => {
|
||||
_.set(res, val.key, (val.value.v) ? val.value.v : val.value)
|
||||
_.set(res, val.key, (_.has(val.value, 'v')) ? val.value.v : val.value)
|
||||
return res
|
||||
}, {})
|
||||
} else {
|
||||
|
74
server/models/userKeys.js
Normal file
74
server/models/userKeys.js
Normal file
@ -0,0 +1,74 @@
|
||||
/* global WIKI */
|
||||
|
||||
const _ = require('lodash')
|
||||
const securityHelper = require('../helpers/security')
|
||||
const Model = require('objection').Model
|
||||
const moment = require('moment')
|
||||
const nanoid = require('nanoid')
|
||||
|
||||
/**
|
||||
* Users model
|
||||
*/
|
||||
module.exports = class UserKey extends Model {
|
||||
static get tableName() { return 'userKeys' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
type: 'object',
|
||||
required: ['kind', 'token', 'validUntil'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
kind: {type: 'string'},
|
||||
token: {type: 'string'},
|
||||
createdAt: {type: 'string'},
|
||||
validUntil: {type: 'string'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static get relationMappings() {
|
||||
return {
|
||||
user: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: require('./users'),
|
||||
join: {
|
||||
from: 'userKeys.userId',
|
||||
to: 'users.id'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async $beforeInsert(context) {
|
||||
await super.$beforeInsert(context)
|
||||
|
||||
this.createdAt = moment.utc().toISOString()
|
||||
}
|
||||
|
||||
static async generateToken ({ userId, kind }, context) {
|
||||
const token = await nanoid()
|
||||
await WIKI.models.userKeys.query().insert({
|
||||
kind,
|
||||
token,
|
||||
validUntil: moment.utc().add(1, 'days').toISOString(),
|
||||
userId
|
||||
})
|
||||
return token
|
||||
}
|
||||
|
||||
static async validateToken ({ kind, token }, context) {
|
||||
const res = await WIKI.models.userKeys.query().findOne({ kind, token }).eager('user')
|
||||
if (res) {
|
||||
await WIKI.models.userKeys.query().deleteById(res.id)
|
||||
if (moment.utc().isAfter(moment.utc(res.validUntil))) {
|
||||
throw new WIKI.Error.AuthValidationTokenInvalid()
|
||||
}
|
||||
return res.user
|
||||
} else {
|
||||
throw new WIKI.Error.AuthValidationTokenInvalid()
|
||||
}
|
||||
|
||||
return token
|
||||
}
|
||||
}
|
@ -345,7 +345,7 @@ module.exports = class User extends Model {
|
||||
const usr = await WIKI.models.users.query().findOne({ email, providerKey: 'local' })
|
||||
if (!usr) {
|
||||
// Create the account
|
||||
await WIKI.models.users.query().insert({
|
||||
const newUsr = await WIKI.models.users.query().insert({
|
||||
provider: 'local',
|
||||
email,
|
||||
name,
|
||||
@ -358,6 +358,12 @@ module.exports = class User extends Model {
|
||||
isVerified: false
|
||||
})
|
||||
|
||||
// Create verification token
|
||||
const verificationToken = await WIKI.models.userKeys.generateToken({
|
||||
kind: 'verify',
|
||||
userId: newUsr.id
|
||||
})
|
||||
|
||||
// Send verification email
|
||||
await WIKI.mail.send({
|
||||
template: 'accountVerify',
|
||||
@ -367,10 +373,10 @@ module.exports = class User extends Model {
|
||||
preheadertext: 'Verify your account in order to gain access to the wiki.',
|
||||
title: 'Verify your account',
|
||||
content: 'Click the button below in order to verify your account and gain access to the wiki.',
|
||||
buttonLink: 'http://www.google.com',
|
||||
buttonLink: `${WIKI.config.host}/verify/${verificationToken}`,
|
||||
buttonText: 'Verify'
|
||||
},
|
||||
text: `You must open the following link in your browser to verify your account and gain access to the wiki: http://www.google.com`
|
||||
text: `You must open the following link in your browser to verify your account and gain access to the wiki: ${WIKI.config.host}/verify/${verificationToken}`
|
||||
})
|
||||
return true
|
||||
} else {
|
||||
|
@ -98,18 +98,54 @@ module.exports = () => {
|
||||
await fs.ensureDir(path.join(dataPath, 'uploads'))
|
||||
|
||||
// Set config
|
||||
_.set(WIKI.config, 'company', '')
|
||||
_.set(WIKI.config, 'defaultEditor', 'markdown')
|
||||
_.set(WIKI.config, 'features', {
|
||||
featurePageRatings: true,
|
||||
featurePageComments: true,
|
||||
featurePersonalWikis: true
|
||||
})
|
||||
_.set(WIKI.config, 'graphEndpoint', 'https://graph.requarks.io')
|
||||
_.set(WIKI.config, 'lang.code', 'en')
|
||||
_.set(WIKI.config, 'lang.autoUpdate', true)
|
||||
_.set(WIKI.config, 'lang.namespacing', false)
|
||||
_.set(WIKI.config, 'lang.namespaces', [])
|
||||
_.set(WIKI.config, 'host', 'http://')
|
||||
_.set(WIKI.config, 'lang', {
|
||||
code: 'en',
|
||||
autoUpdate: true,
|
||||
namespacing: false,
|
||||
namespaces: []
|
||||
})
|
||||
_.set(WIKI.config, 'logo', {
|
||||
hasLogo: false,
|
||||
logoIsSquare: false
|
||||
})
|
||||
_.set(WIKI.config, 'mail', {
|
||||
senderName: '',
|
||||
senderEmail: '',
|
||||
host: '',
|
||||
port: 465,
|
||||
secure: true,
|
||||
user: '',
|
||||
pass: '',
|
||||
useDKIM: false,
|
||||
dkimDomainName: '',
|
||||
dkimKeySelector: '',
|
||||
dkimPrivateKey: ''
|
||||
})
|
||||
_.set(WIKI.config, 'public', false)
|
||||
_.set(WIKI.config, 'seo', {
|
||||
description: '',
|
||||
keywords: '',
|
||||
robots: ['index', 'follow'],
|
||||
ga: ''
|
||||
})
|
||||
_.set(WIKI.config, 'sessionSecret', (await crypto.randomBytesAsync(32)).toString('hex'))
|
||||
_.set(WIKI.config, 'telemetry.isEnabled', req.body.telemetry === 'true')
|
||||
_.set(WIKI.config, 'telemetry.clientId', WIKI.telemetry.cid)
|
||||
_.set(WIKI.config, 'theming.theme', 'default')
|
||||
_.set(WIKI.config, 'theming.darkMode', false)
|
||||
_.set(WIKI.config, 'telemetry', {
|
||||
isEnabled: req.body.telemetry === 'true',
|
||||
clientId: WIKI.telemetry.cid
|
||||
})
|
||||
_.set(WIKI.config, 'theming', {
|
||||
theme: 'default',
|
||||
darkMode: false
|
||||
})
|
||||
_.set(WIKI.config, 'title', 'Wiki.js')
|
||||
|
||||
// Generate certificates
|
||||
@ -128,22 +164,30 @@ module.exports = () => {
|
||||
}
|
||||
})
|
||||
|
||||
_.set(WIKI.config, 'certs.jwk', pem2jwk(certs.publicKey))
|
||||
_.set(WIKI.config, 'certs.public', certs.publicKey)
|
||||
_.set(WIKI.config, 'certs.private', certs.privateKey)
|
||||
_.set(WIKI.config, 'certs', {
|
||||
jwk: pem2jwk(certs.publicKey),
|
||||
public: certs.publicKey,
|
||||
private: certs.privateKey
|
||||
})
|
||||
|
||||
// Save config to DB
|
||||
WIKI.logger.info('Persisting config to DB...')
|
||||
await WIKI.configSvc.saveToDb([
|
||||
'certs',
|
||||
'company',
|
||||
'defaultEditor',
|
||||
'features',
|
||||
'graphEndpoint',
|
||||
'host',
|
||||
'lang',
|
||||
'logo',
|
||||
'mail',
|
||||
'public',
|
||||
'seo',
|
||||
'sessionSecret',
|
||||
'telemetry',
|
||||
'theming',
|
||||
'title',
|
||||
'certs'
|
||||
'title'
|
||||
])
|
||||
|
||||
// Create default locale
|
||||
|
@ -233,7 +233,7 @@
|
||||
<!-- Email Header : BEGIN -->
|
||||
<tr>
|
||||
<td style="padding: 20px 0; text-align: center">
|
||||
<img src="<%= logo %>" width="200" height="50" alt="<%= siteTitle %>" border="0" style="height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; line-height: 15px; color: #555555;">
|
||||
<img src="<%= logo %>" height="50" alt="<%= siteTitle %>" border="0" style="width: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; line-height: 15px; color: #555555;">
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Email Header : END -->
|
||||
|
Loading…
Reference in New Issue
Block a user