feat: login bg + bypass + hide local option

This commit is contained in:
NGPixel 2020-07-05 01:36:02 -04:00
parent 5282a82afe
commit b475795595
8 changed files with 50 additions and 7 deletions

View File

@ -163,12 +163,21 @@
v-switch(
inset
:label='$t(`admin:security.bypassLogin`)'
color='red darken-2'
color='primary'
v-model='config.authAutoLogin'
prepend-icon='mdi-fast-forward'
persistent-hint
:hint='$t(`admin:security.bypassLoginHint`)'
)
v-switch(
inset
:label='$t(`admin:security.hideLocalLogin`)'
color='primary'
v-model='config.authHideLocal'
prepend-icon='mdi-eye-off-outline'
persistent-hint
:hint='$t(`admin:security.hideLocalLoginHint`)'
)
v-divider.mt-3
.overline.grey--text.pa-4 {{$t('admin:security.jwt')}}
.px-4.pb-3
@ -231,6 +240,7 @@ export default {
securityCSP: false,
securityCSPDirectives: '',
authAutoLogin: false,
authHideLocal: false,
authLoginBgUrl: '',
authJwtAudience: 'urn:wiki.js',
authJwtExpiration: '30m',
@ -256,6 +266,7 @@ export default {
mutation: gql`
mutation (
$authAutoLogin: Boolean
$authHideLocal: Boolean
$authLoginBgUrl: String
$authJwtAudience: String
$authJwtExpiration: String
@ -275,6 +286,7 @@ export default {
site {
updateConfig(
authAutoLogin: $authAutoLogin,
authHideLocal: $authHideLocal,
authLoginBgUrl: $authLoginBgUrl,
authJwtAudience: $authJwtAudience,
authJwtExpiration: $authJwtExpiration,
@ -303,6 +315,7 @@ export default {
`,
variables: {
authAutoLogin: _.get(this.config, 'authAutoLogin', false),
authHideLocal: _.get(this.config, 'authHideLocal', false),
authLoginBgUrl: _.get(this.config, 'authLoginBgUrl', ''),
authJwtAudience: _.get(this.config, 'authJwtAudience', ''),
authJwtExpiration: _.get(this.config, 'authJwtExpiration', ''),
@ -352,6 +365,7 @@ export default {
site {
config {
authAutoLogin
authHideLocal
authLoginBgUrl
authJwtAudience
authJwtExpiration

View File

@ -1,6 +1,6 @@
<template lang="pug">
v-app
.login
.login(:style='`background-image: url(` + bgUrl + `);`')
.login-sd
.d-flex
.login-logo
@ -238,6 +238,16 @@ import { sync } from 'vuex-pathify'
export default {
i18nOptions: { namespaces: 'auth' },
props: {
bgUrl: {
type: String,
default: ''
},
hideLocal: {
type: Boolean,
default: false
}
},
data () {
return {
error: false,
@ -535,7 +545,8 @@ export default {
<style lang="scss">
.login {
background-image: url('/_assets/img/splash/1.jpg');
// background-image: url('/_assets/img/splash/1.jpg');
background-color: mc('grey', '900');
background-size: cover;
background-position: center center;
width: 100%;

View File

@ -55,6 +55,7 @@ defaults:
darkMode: false
auth:
autoLogin: false
hideLocal: false
loginBgUrl: ''
audience: 'urn:wiki.js'
tokenExpiration: '30m'

View File

@ -33,7 +33,17 @@ router.get('/login', async (req, res, next) => {
socialStrategies
})
} else {
res.render('login')
// -> Bypass Login
if (WIKI.config.auth.autoLogin && !req.query.all) {
const stg = await WIKI.models.authentication.query().orderBy('order').first()
const stgInfo = _.find(WIKI.data.authentication, ['key', stg.strategyKey])
if (!stgInfo.useForm) {
return res.redirect(`/login/${stg.key}`)
}
}
// -> Show Login
const bgUrl = !_.isEmpty(WIKI.config.auth.loginBgUrl) ? WIKI.config.auth.loginBgUrl : '/_assets/img/splash/1.jpg'
res.render('login', { bgUrl, hideLocal: WIKI.config.auth.hideLocal })
}
})

View File

@ -22,6 +22,7 @@ module.exports = {
...WIKI.config.features,
...WIKI.config.security,
authAutoLogin: WIKI.config.auth.autoLogin,
authHideLocal: WIKI.config.auth.hideLocal,
authLoginBgUrl: WIKI.config.auth.loginBgUrl,
authJwtAudience: WIKI.config.auth.audience,
authJwtExpiration: WIKI.config.auth.tokenExpiration,
@ -67,6 +68,7 @@ module.exports = {
WIKI.config.auth = {
autoLogin: _.get(args, 'authAutoLogin', WIKI.config.auth.autoLogin),
hideLocal: _.get(args, 'authHideLocal', WIKI.config.auth.hideLocal),
loginBgUrl: _.get(args, 'authLoginBgUrl', WIKI.config.auth.loginBgUrl),
audience: _.get(args, 'authJwtAudience', WIKI.config.auth.audience),
tokenExpiration: _.get(args, 'authJwtExpiration', WIKI.config.auth.tokenExpiration),

View File

@ -34,6 +34,7 @@ type SiteMutation {
contentLicense: String
logoUrl: String
authAutoLogin: Boolean
authHideLocal: Boolean
authLoginBgUrl: String
authJwtAudience: String
authJwtExpiration: String
@ -71,6 +72,7 @@ type SiteConfig {
contentLicense: String!
logoUrl: String!
authAutoLogin: Boolean
authHideLocal: Boolean
authLoginBgUrl: String
authJwtAudience: String
authJwtExpiration: String

View File

@ -36,11 +36,11 @@ module.exports = class Authentication extends Model {
static async getStrategies() {
const strategies = await WIKI.models.authentication.query().orderBy('order')
return _.sortBy(strategies.map(str => ({
return strategies.map(str => ({
...str,
domainWhitelist: _.get(str.domainWhitelist, 'v', []),
autoEnrollGroups: _.get(str.autoEnrollGroups, 'v', [])
})), ['key'])
}))
}
static async getStrategiesForLegacyClient() {

View File

@ -2,4 +2,7 @@ extends master.pug
block body
#root.is-fullscreen
login
login(
bg-url=bgUrl
hide-local=hideLocal
)