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

View file

@ -1,41 +1,38 @@
<template lang="pug">
el-main
h4 <nuxt-link to='/'><img src='/favicon.ico'/></nuxt-link> {{$t('common.settings')}}
el-divider {{$auth.user.email}}
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-input(v-model='password' type='password')
el-button(type='success' native-type='submit') {{$t('common.save')}}
p {{$auth.user.email}}
//- 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-input(v-model='password' type='password')
//- el-button(type='success' native-type='submit') {{$t('common.save')}}
el-divider {{$t('settings.danger_section')}}
p {{$t('settings.remove_account')}}
el-button(type='danger' @click='remove_account') {{$t('common.remove')}}
</template>
<script>
import { mapState, mapActions } from 'vuex'
import { mapState } from 'vuex'
import { Message, MessageBox } from 'element-ui'
import url from 'url'
export default {
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 () {
return {
password: '',
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: {
...mapState(['settings']),
baseurl () {
@ -43,30 +40,30 @@ export default {
}
},
methods: {
async change_password () {
if (!this.password) { return }
const user_data = { id: this.$auth.user.id, password: this.password }
try {
const user = await this.$axios.$put('/user', user_data)
Message({ message: this.$t('settings.password_updated'), showClose: true, type: 'success' })
this.$router.replace('/')
} catch (e) {
console.log(e)
}
},
async update_settings () {
MessageBox.confirm(this.$t('settings.update_confirm'),
this.$t('common.confirm'), {
confirmButtonText: this.$t('common.ok'),
cancelButtonText: this.$t('common.cancel'),
type: 'error'
}).then(async () => {
this.user = await this.$axios.$put('/user', { ...this.user, password: this.password })
}).catch(e => {
Message({ message: e, showClose: true, type: 'warning' })
})
},
async remove_account () {
// async change_password () {
// if (!this.password) { return }
// const user_data = { id: this.$auth.user.id, password: this.password }
// try {
// await this.$axios.$put('/user', user_data)
// Message({ message: this.$t('settings.password_updated'), showClose: true, type: 'success' })
// this.$router.replace('/')
// } catch (e) {
// console.log(e)
// }
// },
// update_settings () {
// MessageBox.confirm(this.$t('settings.update_confirm'),
// this.$t('common.confirm'), {
// confirmButtonText: this.$t('common.ok'),
// cancelButtonText: this.$t('common.cancel'),
// type: 'error'
// }).then(async () => {
// this.user = await this.$axios.$put('/user', { ...this.user, password: this.password })
// }).catch(e => {
// Message({ message: e, showClose: true, type: 'warning' })
// })
// },
remove_account () {
MessageBox.confirm(this.$t('settings.remove_account_confirm'), this.$t('common.confirm'), {
confirmButtonText: this.$t('common.ok'),
cancelButtonText: this.$t('common.cancel'),
@ -77,6 +74,11 @@ export default {
this.$router.replace('/')
})
}
},
head () {
return {
title: `${this.settings.title} - ${this.$t('common.settings')}`
}
}
}
</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,
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,
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'
import locale from 'element-ui/lib/locale'
// import '../assets/style.scss'
const locales = {
it: require('element-ui/lib/locale/lang/it'),
@ -16,6 +17,7 @@ const locales = {
export default ({ app, store }) => {
locale.use(locales[store.state.locale])
Vue.use(Button)
Vue.use(Autocomplete)
Vue.use(Alert)
Vue.use(Icon)
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/network-wired'
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'

View file

@ -100,10 +100,10 @@ const settingsController = {
}
},
getUserLocale (req, res) {
// load user locale specified in configuration
res.json(settingsController.user_locale)
},
// getUserLocale (req, res) {
// // load user locale specified in configuration
// res.json(settingsController.user_locale)
// },
async setRequest (req, res) {
const { key, value, is_secret } = req.body
@ -111,6 +111,12 @@ const settingsController = {
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) {
// get public settings and public configuration
const settings = {

View file

@ -68,10 +68,10 @@ api.delete('/event/notification/:code', eventController.delNotification)
api.get('/settings', settingsController.getAllRequest)
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 event
// confirm eventtags
api.get('/event/confirm/:event_id', isAuth, eventController.confirm)
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
api.get('/event/:month/:year', cors, eventController.getAll)
api.get('/event', cors, eventController.select)
api.get('/instances', isAdmin, instanceController.getAll)
api.get('/instances/:instance_domain', isAdmin, instanceController.get)

View file

@ -30,7 +30,7 @@ module.exports = {
const db = require('./api/models')
const users = await db.user.findAll()
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
}
@ -51,7 +51,7 @@ module.exports = {
await db.notification.create({ action: 'Update', 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 } })
// TODO

View file

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

View file

@ -22,13 +22,16 @@ app.use((req, res, next) => {
app.use(spamFilter)
// 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('/media/', express.static(config.upload_path))
// initialize instance settings / authentication / locale
app.use(cookieParser())
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
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 find from 'lodash/find'
@ -44,7 +44,9 @@ export const getters = {
if (!state.filters.show_recurrent_events && e.recurrent) { return false }
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) {
@ -70,11 +72,11 @@ export const getters = {
if (!state.filters.show_recurrent_events && e.recurrent) { return false }
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) {
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 }
}
@ -147,22 +149,33 @@ export const mutations = {
}
export const actions = {
// this method is called server side only for each request
// we use it to get configuration from db, setting locale, etc...
nuxtServerInit ({ commit }, { app, store, req }) {
if (req.user) {
this.$auth.setUser(req.user)
}
// this method is called server side only for each request for nuxt
// we use it to get configuration from db, set locale, etc...
async nuxtServerInit ({ commit }, { app, store, req }) {
if (req.user) { this.$auth.setUser(req.user) }
const settings = req.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
commit('showRecurrentEvents', settings.allow_recurrent_event && settings.recurrent_event_visible)
},
async updateEvents ({ commit }, page) {
async updateEvents ({ commit, state }, page) {
const month = moment().month()
const year = moment().year()
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)
},
async updateMeta ({ commit }) {