minors + set Favicon

This commit is contained in:
les
2020-01-15 23:51:09 +01:00
parent 474794e9ab
commit 3b04cdd485
10 changed files with 116 additions and 73 deletions

View File

@@ -31,11 +31,8 @@ export default {
user: {} user: {}
} }
}, },
head () { // https://nuxtjs.org/api/pages-validate/
return { // If the validate method does not return true, Nuxt.js will automatically load the 404 error page.
title: this.settings.title + ' - ' + this.$t('common.register')
}
},
validate ({ store }) { validate ({ store }) {
return store.state.settings.allow_registration return store.state.settings.allow_registration
}, },
@@ -71,6 +68,11 @@ export default {
} }
this.loading = false this.loading = false
} }
},
head () {
return {
title: this.settings.title + ' - ' + this.$t('common.register')
}
} }
} }
</script> </script>

View File

@@ -1,41 +1,38 @@
<template lang="pug"> <template lang="pug">
el-main el-main
h4 <nuxt-link to='/'><img src='/favicon.ico'/></nuxt-link> {{$t('common.settings')}}
el-divider {{$auth.user.email}} p {{$auth.user.email}}
el-form(action='/api/user' method='PUT' @submit.native.prevent='update_settings' inline label-width='200px') //- el-form(action='/api/user' method='PUT' @submit.native.prevent='update_settings' inline label-width='200px')
//- el-form-item(:label="$t('settings.change_password')")
el-form-item(:label="$t('settings.change_password')") //- el-input(v-model='password' type='password')
el-input(v-model='password' type='password') //- el-button(type='success' native-type='submit') {{$t('common.save')}}
el-button(type='success' native-type='submit') {{$t('common.save')}}
el-divider {{$t('settings.danger_section')}} el-divider {{$t('settings.danger_section')}}
p {{$t('settings.remove_account')}} p {{$t('settings.remove_account')}}
el-button(type='danger' @click='remove_account') {{$t('common.remove')}} el-button(type='danger' @click='remove_account') {{$t('common.remove')}}
</template> </template>
<script> <script>
import { mapState, mapActions } from 'vuex' import { mapState } from 'vuex'
import { Message, MessageBox } from 'element-ui' import { Message, MessageBox } from 'element-ui'
import url from 'url' import url from 'url'
export default { export default {
name: 'Settings', name: 'Settings',
async asyncData ({ $axios, params, error }) {
try {
const user = await $axios.$get('/auth/user')
return { user }
} catch (e) {
error({ statusCode: 404, message: 'Something goes wrong...' })
}
},
middleware: ['auth'],
data () { data () {
return { return {
password: '', password: '',
user: { } user: { }
} }
}, },
head () {
return {
title: `${this.settings.title} - ${this.$t('common.settings')}`
}
},
async asyncData ({ $axios, params }) {
const user = await $axios.$get('/auth/user')
return { user }
},
computed: { computed: {
...mapState(['settings']), ...mapState(['settings']),
baseurl () { baseurl () {
@@ -43,30 +40,30 @@ export default {
} }
}, },
methods: { methods: {
async change_password () { // async change_password () {
if (!this.password) { return } // if (!this.password) { return }
const user_data = { id: this.$auth.user.id, password: this.password } // const user_data = { id: this.$auth.user.id, password: this.password }
try { // try {
const user = await this.$axios.$put('/user', user_data) // await this.$axios.$put('/user', user_data)
Message({ message: this.$t('settings.password_updated'), showClose: true, type: 'success' }) // Message({ message: this.$t('settings.password_updated'), showClose: true, type: 'success' })
this.$router.replace('/') // this.$router.replace('/')
} catch (e) { // } catch (e) {
console.log(e) // console.log(e)
} // }
}, // },
async update_settings () { // update_settings () {
MessageBox.confirm(this.$t('settings.update_confirm'), // MessageBox.confirm(this.$t('settings.update_confirm'),
this.$t('common.confirm'), { // this.$t('common.confirm'), {
confirmButtonText: this.$t('common.ok'), // confirmButtonText: this.$t('common.ok'),
cancelButtonText: this.$t('common.cancel'), // cancelButtonText: this.$t('common.cancel'),
type: 'error' // type: 'error'
}).then(async () => { // }).then(async () => {
this.user = await this.$axios.$put('/user', { ...this.user, password: this.password }) // this.user = await this.$axios.$put('/user', { ...this.user, password: this.password })
}).catch(e => { // }).catch(e => {
Message({ message: e, showClose: true, type: 'warning' }) // Message({ message: e, showClose: true, type: 'warning' })
}) // })
}, // },
async remove_account () { remove_account () {
MessageBox.confirm(this.$t('settings.remove_account_confirm'), this.$t('common.confirm'), { MessageBox.confirm(this.$t('settings.remove_account_confirm'), this.$t('common.confirm'), {
confirmButtonText: this.$t('common.ok'), confirmButtonText: this.$t('common.ok'),
cancelButtonText: this.$t('common.cancel'), cancelButtonText: this.$t('common.cancel'),
@@ -77,6 +74,11 @@ export default {
this.$router.replace('/') this.$router.replace('/')
}) })
} }
},
head () {
return {
title: `${this.settings.title} - ${this.$t('common.settings')}`
}
} }
} }
</script> </script>

View File

@@ -2,9 +2,10 @@ import Vue from 'vue'
import { Button, Select, Tag, Option, Table, FormItem, Card, Row, Col, Upload, Checkbox, RadioButton, RadioGroup, import { Button, Select, Tag, Option, Table, FormItem, Card, Row, Col, Upload, Checkbox, RadioButton, RadioGroup,
Form, Tabs, TabPane, Switch, Input, Loading, TimeSelect, Badge, ButtonGroup, Divider, Step, Steps, Radio, Main, Form, Tabs, TabPane, Switch, Input, Loading, TimeSelect, Badge, ButtonGroup, Divider, Step, Steps, Radio, Main,
TableColumn, ColorPicker, Pagination, Popover, Tooltip, Dialog, Image, Backtop, Collapse, CollapseItem, Link, TableColumn, ColorPicker, Pagination, Popover, Tooltip, Dialog, Image, Backtop, Collapse, CollapseItem, Link,
Dropdown, DropdownMenu, DropdownItem, Submenu, PageHeader, Header, Icon, Alert, Dropdown, DropdownMenu, DropdownItem, Submenu, PageHeader, Header, Icon, Alert, Autocomplete,
Container, Footer, Timeline, TimelineItem, Menu, MenuItem } from 'element-ui' Container, Footer, Timeline, TimelineItem, Menu, MenuItem } from 'element-ui'
import locale from 'element-ui/lib/locale' import locale from 'element-ui/lib/locale'
// import '../assets/style.scss'
const locales = { const locales = {
it: require('element-ui/lib/locale/lang/it'), it: require('element-ui/lib/locale/lang/it'),
@@ -16,6 +17,7 @@ const locales = {
export default ({ app, store }) => { export default ({ app, store }) => {
locale.use(locales[store.state.locale]) locale.use(locales[store.state.locale])
Vue.use(Button) Vue.use(Button)
Vue.use(Autocomplete)
Vue.use(Alert) Vue.use(Alert)
Vue.use(Icon) Vue.use(Icon)
Vue.use(Dropdown) Vue.use(Dropdown)

View File

@@ -33,6 +33,19 @@ import 'vue-awesome/icons/calendar-week'
import 'vue-awesome/icons/calendar-alt' import 'vue-awesome/icons/calendar-alt'
import 'vue-awesome/icons/network-wired' import 'vue-awesome/icons/network-wired'
import 'vue-awesome/icons/rss' import 'vue-awesome/icons/rss'
import 'vue-awesome/icons/bold'
import 'vue-awesome/icons/italic'
import 'vue-awesome/icons/strikethrough'
import 'vue-awesome/icons/quote-right'
import 'vue-awesome/icons/underline'
import 'vue-awesome/icons/code'
import 'vue-awesome/icons/paragraph'
import 'vue-awesome/icons/list-ul'
import 'vue-awesome/icons/list-ol'
import 'vue-awesome/icons/heading'
import 'vue-awesome/icons/link'
import 'vue-awesome/icons/hands-helping'
import 'vue-awesome/icons/question'
import Icon from 'vue-awesome/components/Icon' import Icon from 'vue-awesome/components/Icon'

View File

@@ -100,10 +100,10 @@ const settingsController = {
} }
}, },
getUserLocale (req, res) { // getUserLocale (req, res) {
// load user locale specified in configuration // // load user locale specified in configuration
res.json(settingsController.user_locale) // res.json(settingsController.user_locale)
}, // },
async setRequest (req, res) { async setRequest (req, res) {
const { key, value, is_secret } = req.body const { key, value, is_secret } = req.body
@@ -111,6 +111,12 @@ const settingsController = {
if (ret) { res.sendStatus(200) } else { res.sendStatus(400) } if (ret) { res.sendStatus(200) } else { res.sendStatus(400) }
}, },
async setFavicon (req, res) {
if (!req.file) return res.status(400).send('Mmmmm sould not be here!')
await settingsController.set('favicon', path.join(req.file.destination, req.file.filename))
res.sendStatus(200)
},
getAllRequest (req, res) { getAllRequest (req, res) {
// get public settings and public configuration // get public settings and public configuration
const settings = { const settings = {

View File

@@ -68,10 +68,10 @@ api.delete('/event/notification/:code', eventController.delNotification)
api.get('/settings', settingsController.getAllRequest) api.get('/settings', settingsController.getAllRequest)
api.post('/settings', isAdmin, settingsController.setRequest) api.post('/settings', isAdmin, settingsController.setRequest)
api.post('/settings/favicon', isAdmin, multer({ dest: 'thumb/' }).single('favicon'), settingsController.setFavicon)
// api.get('/settings/user_locale', settingsController.getUserLocale)
api.get('/settings/user_locale', settingsController.getUserLocale) // confirm eventtags
// confirm event
api.get('/event/confirm/:event_id', isAuth, eventController.confirm) api.get('/event/confirm/:event_id', isAuth, eventController.confirm)
api.get('/event/unconfirm/:event_id', isAuth, eventController.unconfirm) api.get('/event/unconfirm/:event_id', isAuth, eventController.unconfirm)
@@ -83,6 +83,7 @@ api.get('/export/:type', cors, exportController.export)
// get events in this range // get events in this range
api.get('/event/:month/:year', cors, eventController.getAll) api.get('/event/:month/:year', cors, eventController.getAll)
api.get('/event', cors, eventController.select)
api.get('/instances', isAdmin, instanceController.getAll) api.get('/instances', isAdmin, instanceController.getAll)
api.get('/instances/:instance_domain', isAdmin, instanceController.get) api.get('/instances/:instance_domain', isAdmin, instanceController.get)

View File

@@ -30,7 +30,7 @@ module.exports = {
const db = require('./api/models') const db = require('./api/models')
const users = await db.user.findAll() const users = await db.user.findAll()
if (users.length) { if (users.length) {
consola.warn(` ⚠ Non empty db! Please move your current db elsewhere than retry.`) consola.warn(' ⚠ Non empty db! Please move your current db elsewhere than retry.')
return false return false
} }
@@ -51,7 +51,7 @@ module.exports = {
await db.notification.create({ action: 'Update', type: 'ap', filters: { is_visible: true } }) await db.notification.create({ action: 'Update', type: 'ap', filters: { is_visible: true } })
await db.notification.create({ action: 'Delete', type: 'ap', filters: { is_visible: true } }) await db.notification.create({ action: 'Delete', type: 'ap', filters: { is_visible: true } })
// send anon email to administrator // send anon event to administrator
await db.notification.create({ action: 'Create', type: 'admin_email', filters: { is_visible: false } }) await db.notification.create({ action: 'Create', type: 'admin_email', filters: { is_visible: false } })
// TODO // TODO

View File

@@ -13,7 +13,7 @@ const jwt = expressJwt({
if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') { if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
return req.headers.authorization.split(' ')[1] return req.headers.authorization.split(' ')[1]
} else if (req.cookies && req.cookies['auth._token.local']) { } else if (req.cookies && req.cookies['auth._token.local']) {
const [ prefix, token ] = req.cookies['auth._token.local'].split(' ') const [prefix, token] = req.cookies['auth._token.local'].split(' ')
if (prefix === 'Bearer') { return token } if (prefix === 'Bearer') { return token }
} }
return null return null
@@ -28,8 +28,8 @@ module.exports = {
req.secretSettings = settingsController.secretSettings req.secretSettings = settingsController.secretSettings
req.settings.baseurl = config.baseurl req.settings.baseurl = config.baseurl
req.settings.title = config.title req.settings.title = req.settings.title || config.title
req.settings.description = config.description req.settings.description = req.settings.description || config.description
req.settings.version = pkg.version req.settings.version = pkg.version
// set locale and user locale // set locale and user locale
@@ -39,6 +39,7 @@ module.exports = {
req.settings.locale = acceptLanguage.get(acceptedLanguages) req.settings.locale = acceptLanguage.get(acceptedLanguages)
req.settings.user_locale = settingsController.user_locale[req.settings.locale] req.settings.user_locale = settingsController.user_locale[req.settings.locale]
moment.locale(req.settings.locale) moment.locale(req.settings.locale)
moment.tz.setDefault(req.settings.instance_timezone)
// TODO: oauth // TODO: oauth
// auth // auth

View File

@@ -22,13 +22,16 @@ app.use((req, res, next) => {
app.use(spamFilter) app.use(spamFilter)
// serve favicon and static content // serve favicon and static content
app.use('/favicon.ico', express.static(path.resolve(config.favicon || './assets/favicon.ico')))
app.use('/logo.png', express.static('./static/gancio.png')) app.use('/logo.png', express.static('./static/gancio.png'))
app.use('/media/', express.static(config.upload_path)) app.use('/media/', express.static(config.upload_path))
// initialize instance settings / authentication / locale // initialize instance settings / authentication / locale
app.use(cookieParser()) app.use(cookieParser())
app.use(helpers.initMiddleware) app.use(helpers.initMiddleware)
app.use('/favicon.ico', (req, res, next) => {
const favicon_path = req.settings.favicon || config.favicon || './assets/favicon.ico'
return express.static(path.resolve(favicon_path))(req, res, next)
})
// rss/ics/atom feed // rss/ics/atom feed
app.get('/feed/:type', cors(), exportController.export) app.get('/feed/:type', cors(), exportController.export)

View File

@@ -1,4 +1,4 @@
import moment from 'dayjs' import moment from 'moment-timezone'
import intersection from 'lodash/intersection' import intersection from 'lodash/intersection'
import find from 'lodash/find' import find from 'lodash/find'
@@ -44,7 +44,9 @@ export const getters = {
if (!state.filters.show_recurrent_events && e.recurrent) { return false } if (!state.filters.show_recurrent_events && e.recurrent) { return false }
if (search_for_places) { if (search_for_places) {
if (find(state.filters.places, p => p === e.place.id)) { return true } if (find(state.filters.places, p => p.id === e.place.id)) {
return true
}
} }
if (search_for_tags) { if (search_for_tags) {
@@ -70,11 +72,11 @@ export const getters = {
if (!state.filters.show_recurrent_events && e.recurrent) { return false } if (!state.filters.show_recurrent_events && e.recurrent) { return false }
if (!match && search_for_places) { if (!match && search_for_places) {
if (find(state.filters.places, p => p === e.place.id)) { return true } if (find(state.filters.places, p => p.id === e.place.id)) { return true }
} }
if (search_for_tags) { if (search_for_tags) {
const common_tags = intersection(e.tags, state.filters.tags) const common_tags = intersection(e.tags, state.filters.tags.map(t => t.tag))
if (common_tags.length > 0) { return true } if (common_tags.length > 0) { return true }
} }
@@ -147,22 +149,33 @@ export const mutations = {
} }
export const actions = { export const actions = {
// this method is called server side only for each request // this method is called server side only for each request for nuxt
// we use it to get configuration from db, setting locale, etc... // we use it to get configuration from db, set locale, etc...
nuxtServerInit ({ commit }, { app, store, req }) { async nuxtServerInit ({ commit }, { app, store, req }) {
if (req.user) { if (req.user) { this.$auth.setUser(req.user) }
this.$auth.setUser(req.user)
}
const settings = req.settings const settings = req.settings
commit('setSettings', settings) commit('setSettings', settings)
const start_datetime = moment().startOf('month').startOf('week').unix()
const events = await this.$axios.$get(`/event?start=${start_datetime}`)
commit('setEvents', events)
const { tags, places } = await this.$axios.$get('/event/meta')
store.commit('update', { tags, places })
// apply settings // apply settings
commit('showRecurrentEvents', settings.allow_recurrent_event && settings.recurrent_event_visible) commit('showRecurrentEvents', settings.allow_recurrent_event && settings.recurrent_event_visible)
}, },
async updateEvents ({ commit }, page) { async updateEvents ({ commit, state }, page) {
const month = moment().month() const month = moment().month()
const year = moment().year() const year = moment().year()
commit('setPast', page.year < year || (page.year === year && page.month <= month)) commit('setPast', page.year < year || (page.year === year && page.month <= month))
const events = await this.$axios.$get(`/event/${page.month - 1}/${page.year}`) // const events = await this.$axios.$get(`/event/${page.month - 1}/${page.year}`)
const start_datetime = moment().year(page.year).month(page.month - 1).unix()
const query = `start=${start_datetime}`
const events = await this.$axios.$get(`/event?${query}`)
commit('setEvents', events) commit('setEvents', events)
}, },
async updateMeta ({ commit }) { async updateMeta ({ commit }) {