mirror of https://github.com/Requarks/wiki.git
22 changed files with 494 additions and 80 deletions
Split View
Diff Options
-
2client/client-app.js
-
162client/components/admin/admin-general.vue
-
1client/components/admin/admin-locale.vue
-
14client/components/common/loader.vue
-
19client/components/register.vue
-
38client/graph/admin/site/site-mutation-save-config.gql
-
18client/graph/admin/site/site-query-config.gql
-
14client/static/svg/icon-checkmark.svg
-
1package.json
-
12server/controllers/auth.js
-
4server/core/mail.js
-
2server/db/migrations/2.0.0.js
-
6server/graph/resolvers/authentication.js
-
56server/graph/resolvers/site.js
-
59server/graph/schemas/site.graphql
-
4server/helpers/error.js
-
2server/models/authentication.js
-
2server/models/settings.js
-
74server/models/userKeys.js
-
12server/models/users.js
-
70server/setup.js
-
2server/templates/account-verify.html
@ -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 |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
{ |
|||
site { |
|||
config { |
|||
host |
|||
title |
|||
description |
|||
keywords |
|||
robots |
|||
ga |
|||
company |
|||
hasLogo |
|||
logoIsSquare |
|||
featurePageRatings |
|||
featurePageComments |
|||
featurePersonalWikis |
|||
} |
|||
} |
|||
} |
@ -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> |
@ -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) |
|||
} |
|||
} |
|||
} |
|||
} |
@ -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! |
|||
} |
@ -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 |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save