refactor: renderers + auth providers + fixes

This commit is contained in:
NGPixel
2018-01-14 22:05:08 -05:00
parent 24fc806b0e
commit 74bd722168
41 changed files with 475 additions and 770 deletions

View File

@@ -1,5 +1,3 @@
'use strict'
/* global $, siteRoot */
let mde

View File

@@ -55,7 +55,8 @@ export default {
this.selectedStrategy = key
this.screen = 'login'
if (!useForm) {
window.location.assign(siteConfig.path + 'login/' + key)
this.isLoading = true
window.location.assign(this.$helpers.resolvePath('login/' + key))
} else {
this.$refs.iptEmail.focus()
}

View File

@@ -15,12 +15,24 @@
use(:xlink:href='subtitleIconClass')
h2 {{subtitleText}}
.navigator-action
.navigator-action-item
.navigator-action-item(:class='{"is-active": userMenuShown}', @click='toggleUserMenu')
svg.icons.is-32(role='img')
title User
use(xlink:href='#nc-user-circle')
transition(name='navigator-action-item-dropdown')
ul.navigator-action-item-dropdown(v-show='userMenuShown', v-cloak)
li
label Account
svg.icons.is-24(role='img')
title Account
use(xlink:href='#nc-man-green')
li(@click='logout')
label Sign out
svg.icons.is-24(role='img')
title Sign Out
use(xlink:href='#nc-exit')
transition(name='navigator-sd')
.navigator-sd(v-show='sdShown')
.navigator-sd(v-show='sdShown', v-cloak)
.navigator-sd-actions
a.is-active(href='', title='Search')
svg.icons.is-24(role='img')
@@ -77,7 +89,8 @@ export default {
name: 'navigator',
data() {
return {
sdShown: false
sdShown: false,
userMenuShown: false
}
},
computed: {
@@ -104,16 +117,39 @@ export default {
methods: {
toggleMainMenu() {
this.sdShown = !this.sdShown
this.userMenuShown = false
if (this.sdShown) {
this.$nextTick(() => {
this.bindOutsideClick()
this.$refs.iptSearch.focus()
})
} else {
this.unbindOutsideClick()
}
// this.$store.dispatch('navigator/alert', {
// style: 'success',
// icon: 'gg-check',
// msg: 'Changes were saved successfully!'
// })
},
toggleUserMenu() {
this.userMenuShown = !this.userMenuShown
this.sdShown = false
if (this.userMenuShown) {
this.bindOutsideClick()
} else {
this.unbindOutsideClick()
}
},
bindOutsideClick() {
document.addEventListener('mousedown', this.handleOutsideClick, false)
},
unbindOutsideClick() {
document.removeEventListener('mousedown', this.handleOutsideClick, false)
},
handleOutsideClick(ev) {
if (!this.$el.contains(ev.target)) {
this.sdShown = false
this.userMenuShown = false
}
},
logout() {
window.location.assign(this.$helpers.resolvePath('logout'))
}
},
mounted() {

View File

@@ -24,7 +24,7 @@ export default {
final: {
ok: false,
error: '',
results: []
redirectUrl: ''
},
conf: {
adminEmail: '',
@@ -219,19 +219,32 @@ export default {
self.final = {
ok: false,
error: '',
results: []
redirectUrl: ''
}
this.$helpers._.delay(() => {
axios.post('/finalize', self.conf).then(resp => {
if (resp.data.ok === true) {
self.final.ok = true
self.final.results = resp.data.results
self.$helpers._.delay(() => {
self.final.ok = true
switch (resp.data.redirectPort) {
case 80:
self.final.redirectUrl = `http://${window.location.hostname}${resp.data.redirectPath}/login`
break
case 443:
self.final.redirectUrl = `https://${window.location.hostname}${resp.data.redirectPath}/login`
break
default:
self.final.redirectUrl = `http://${window.location.hostname}:${resp.data.redirectPort}${resp.data.redirectPath}/login`
break
}
self.loading = false
}, 5000)
} else {
self.final.ok = false
self.final.error = resp.data.error
self.loading = false
}
self.loading = false
self.$nextTick()
}).catch(err => {
window.alert(err.message)
@@ -239,18 +252,7 @@ export default {
}, 1000)
},
finish: function (ev) {
let self = this
self.state = 'restart'
this.$helpers._.delay(() => {
axios.post('/restart', {}).then(resp => {
this.$helpers._.delay(() => {
window.location.assign(self.conf.host)
}, 30000)
}).catch(err => {
window.alert(err.message)
})
}, 1000)
window.location.assign(this.final.redirectUrl)
}
}
}

View File

@@ -1,15 +0,0 @@
'use strict'
import filesize from 'filesize.js'
import toUpper from 'lodash/toUpper'
module.exports = {
/**
* Convert bytes to humanized form
* @param {number} rawSize Size in bytes
* @returns {string} Humanized file size
*/
filesize(rawSize) {
return toUpper(filesize(rawSize))
}
}

View File

@@ -1,25 +0,0 @@
'use strict'
module.exports = {
/**
* Set Input Selection
* @param {DOMElement} input The input element
* @param {number} startPos The starting position
* @param {nunber} endPos The ending position
*/
setInputSelection: (input, startPos, endPos) => {
input.focus()
if (typeof input.selectionStart !== 'undefined') {
input.selectionStart = startPos
input.selectionEnd = endPos
} else if (document.selection && document.selection.createRange) {
// IE branch
input.select()
var range = document.selection.createRange()
range.collapse(true)
range.moveEnd('character', endPos)
range.moveStart('character', startPos)
range.select()
}
}
}

View File

@@ -1,10 +1,59 @@
'use strict'
import filesize from 'filesize.js'
/* global siteConfig */
const _ = require('./lodash')
const helpers = {
_: require('./lodash'),
common: require('./common'),
form: require('./form'),
pages: require('./pages')
/**
* Minimal set of lodash functions
*/
_,
/**
* Convert bytes to humanized form
* @param {number} rawSize Size in bytes
* @returns {string} Humanized file size
*/
filesize (rawSize) {
return _.toUpper(filesize(rawSize))
},
/**
* Convert raw path to safe path
* @param {string} rawPath Raw path
* @returns {string} Safe path
*/
makeSafePath (rawPath) {
let rawParts = _.split(_.trim(rawPath), '/')
rawParts = _.map(rawParts, (r) => {
return _.kebabCase(_.deburr(_.trim(r)))
})
return _.join(_.filter(rawParts, (r) => { return !_.isEmpty(r) }), '/')
},
resolvePath (path) {
if (_.startsWith(path, '/')) { path = path.substring(1) }
return `${siteConfig.path}${path}`
},
/**
* Set Input Selection
* @param {DOMElement} input The input element
* @param {number} startPos The starting position
* @param {nunber} endPos The ending position
*/
setInputSelection (input, startPos, endPos) {
input.focus()
if (typeof input.selectionStart !== 'undefined') {
input.selectionStart = startPos
input.selectionEnd = endPos
} else if (document.selection && document.selection.createRange) {
// IE branch
input.select()
var range = document.selection.createRange()
range.collapse(true)
range.moveEnd('character', endPos)
range.moveStart('character', startPos)
range.select()
}
}
}
export default {

View File

@@ -1,5 +1,3 @@
'use strict'
// ====================================
// Load minimal lodash
// ====================================

View File

@@ -1,26 +0,0 @@
'use strict'
import deburr from 'lodash/deburr'
import filter from 'lodash/filter'
import isEmpty from 'lodash/isEmpty'
import join from 'lodash/join'
import kebabCase from 'lodash/kebabCase'
import map from 'lodash/map'
import split from 'lodash/split'
import trim from 'lodash/trim'
module.exports = {
/**
* Convert raw path to safe path
* @param {string} rawPath Raw path
* @returns {string} Safe path
*/
makeSafePath: (rawPath) => {
let rawParts = split(trim(rawPath), '/')
rawParts = map(rawParts, (r) => {
return kebabCase(deburr(trim(r)))
})
return join(filter(rawParts, (r) => { return !isEmpty(r) }), '/')
}
}

View File

@@ -45,7 +45,7 @@ module.exports = {
defaultNS: 'common',
lng: siteConfig.lang,
fallbackLng: siteConfig.lang,
ns: ['common', 'admin', 'auth']
ns: ['common', 'auth']
})
return new VueI18Next(i18next)
}

View File

@@ -1,5 +1,3 @@
'use strict'
export default {
name: 'admin-edit-user',
props: ['usrdata'],

View File

@@ -1,5 +1,3 @@
'use strict'
export default {
name: 'admin-profile',
props: ['email', 'name', 'provider', 'tfaIsActive'],

View File

@@ -1,5 +1,3 @@
'use strict'
export default {
name: 'admin-settings',
data() {

View File

@@ -1,5 +1,3 @@
'use strict'
export default {
name: 'admin-theme',
props: ['themedata'],

View File

@@ -1,5 +1,3 @@
'use strict'
/* global $ */
export default {

View File

@@ -1,5 +1,3 @@
'use strict'
export default {
name: 'source-view',
data() {

View File

@@ -1,5 +1,3 @@
'use strict'
export default {
namespaced: true,
state: {
@@ -15,7 +13,6 @@ export default {
},
actions: {
open({ commit }, hash) {
console.info('MIGUEL!')
commit('anchorChange', { shown: true, hash })
},
close({ commit }) {