auth.nuxt.js plugin
This commit is contained in:
@@ -1,62 +1,62 @@
|
||||
<template lang="pug">
|
||||
b-modal(ref='modal' @hidden='$router.replace("/")' size='lg' :visible='true'
|
||||
:title="edit?$t('Edit event'):$t('New event')" hide-footer)
|
||||
:title="edit?$t('common.edit_event'):$t('common.add_event')" hide-footer)
|
||||
el-form
|
||||
el-tabs.mb-2(v-model='activeTab' v-loading='sending')
|
||||
|
||||
//- NOT LOGGED EVENT
|
||||
el-tab-pane(v-if='!logged')
|
||||
span(slot='label') {{$t('anon_newevent')}} <v-icon name='user-secret'/>
|
||||
p(v-html="$t('anon_newevent_explanation')")
|
||||
el-button.float-right(@click='next' :disabled='!couldProceed') {{$t('Next')}}
|
||||
span(slot='label') {{$t('event.anon')}} <v-icon name='user-secret'/>
|
||||
p(v-html="$t('event.anon_description')")
|
||||
el-button.float-right(@click='next' :disabled='!couldProceed') {{$t('common.next')}}
|
||||
|
||||
//- WHERE
|
||||
el-tab-pane
|
||||
span(slot='label') {{$t('Where')}} <v-icon name='map-marker-alt'/>
|
||||
div {{$t('where_explanation')}}
|
||||
span(slot='label') {{$t('common.where')}} <v-icon name='map-marker-alt'/>
|
||||
div {{$t('common.where')}}
|
||||
el-select.mb-3(v-model='event.place.name' @change='placeChoosed' filterable allow-create default-first-option)
|
||||
el-option(v-for='place in places_name' :label='place' :value='place' :key='place.id')
|
||||
div {{$t("Address")}}
|
||||
el-input.mb-3(ref='address' v-model='event.place.address' @keydown.native.enter='next')
|
||||
el-button.float-right(@click='next' :disabled='!couldProceed') {{$t('Next')}}
|
||||
div {{$t("common.address")}}
|
||||
el-input.mb-3(ref='address' v-model='event.place.address' :disabled='places_name.indexOf(event.place.name)>-1' @keydown.native.enter='next')
|
||||
el-button.float-right(@click='next' :disabled='!couldProceed') {{$t('common.next')}}
|
||||
|
||||
//- WHEN
|
||||
el-tab-pane
|
||||
span(slot='label') {{$t('When')}} <v-icon name='clock'/>
|
||||
span {{event.multidate ? $t('dates_explanation') : $t('date_explanation')}}
|
||||
el-switch.float-right(v-model='event.multidate' :active-text="$t('multidate_explanation')")
|
||||
span(slot='label') {{$t('common.when')}} <v-icon name='clock'/>
|
||||
span {{event.multidate ? $t('event.dates_description') : $t('event.date_description')}}
|
||||
el-switch.float-right(v-model='event.multidate' :active-text="$t('event.multidate_description')")
|
||||
v-date-picker.mb-3(:mode='event.multidate ? "range" : "single"' v-model='date' is-inline
|
||||
is-expanded :min-date='new Date()' @input='date ? $refs.time_start.focus() : false')
|
||||
div {{$t('time_start_explanation')}}
|
||||
div {{$t('event.time_start_description')}}
|
||||
el-time-select.mb-3(ref='time_start'
|
||||
v-model="time.start"
|
||||
:picker-options="{ start: '00:00', step: '00:30', end: '24:00'}")
|
||||
div {{$t('time_end_explanation')}}
|
||||
div {{$t('event.time_end_description')}}
|
||||
el-time-select(v-model='time.end'
|
||||
:picker-options="{start: '00:00', step: '00:30', end: '24:00'}")
|
||||
el-button.float-right(@click='next' :disabled='!couldProceed') {{$t('Next')}}
|
||||
el-button.float-right(@click='next' :disabled='!couldProceed') {{$t('common.next')}}
|
||||
|
||||
//- WHAT
|
||||
el-tab-pane
|
||||
span(slot='label') {{$t('What')}} <v-icon name='file-alt'/>
|
||||
span {{$t('what_explanation')}}
|
||||
span(slot='label') {{$t('common.what')}} <v-icon name='file-alt'/>
|
||||
span {{$t('event.what_description')}}
|
||||
el-input.mb-3(v-model='event.title' ref='title')
|
||||
span {{$t('description_explanation')}}
|
||||
span {{$t('event.description_description')}}
|
||||
el-input.mb-3(v-model='event.description' type='textarea' :rows='9')
|
||||
span {{$t('tag_explanation')}}
|
||||
span {{$t('event.tag_description')}}
|
||||
br
|
||||
el-select(v-model='event.tags' multiple filterable allow-create
|
||||
default-first-option placeholder='Tag')
|
||||
el-option(v-for='tag in tags' :key='tag.tag'
|
||||
:label='tag' :value='tag')
|
||||
|
||||
el-button.float-right(@click.native='next' :disabled='!couldProceed') {{$t('Next')}}
|
||||
el-button.float-right(@click.native='next' :disabled='!couldProceed') {{$t('common.next')}}
|
||||
|
||||
el-tab-pane
|
||||
span(slot='label') {{$t('Media')}} <v-icon name='image'/>
|
||||
span {{$t('media_explanation')}}
|
||||
b-form-file.mb-2(v-model='event.image', :placeholder='$t("Poster")' accept='image/*')
|
||||
el-button.float-right(@click='done') {{edit?$t('Edit'):$t('Send')}}
|
||||
span(slot='label') {{$t('common.media')}} <v-icon name='image'/>
|
||||
span {{$t('event.media_description')}}
|
||||
b-form-file.mb-2(v-model='event.image', :placeholder='$t("common.poster")' accept='image/*')
|
||||
el-button.float-right(@click='done') {{edit?$t('common.edit'):$t('common.send')}}
|
||||
|
||||
|
||||
|
||||
@@ -121,6 +121,12 @@ export default {
|
||||
user: state => state.user,
|
||||
logged: state => state.logged
|
||||
}),
|
||||
disableAddress () {
|
||||
console.log('dentro disable Address')
|
||||
const ret = this.places_name.find(p => p.name === this.event.place.name)
|
||||
console.log(ret)
|
||||
return ret
|
||||
},
|
||||
couldProceed () {
|
||||
const t = this.logged ? -1 : 0
|
||||
switch(Number(this.activeTab)) {
|
||||
@@ -203,7 +209,7 @@ export default {
|
||||
this.updateMeta()
|
||||
this.sending = false
|
||||
this.$refs.modal.hide()
|
||||
Message({ type: 'success', message: this.logged ? this.$t('new_event_added') : this.$t('new_anon_event_added')})
|
||||
Message({ type: 'success', message: this.logged ? this.$t('event.added') : this.$t('event.added_anon')})
|
||||
} catch (e) {
|
||||
this.sending = false
|
||||
console.error(e)
|
||||
@@ -95,6 +95,7 @@ import { Message } from 'element-ui'
|
||||
|
||||
export default {
|
||||
name: 'Admin',
|
||||
middleware: ['auth'],
|
||||
data () {
|
||||
return {
|
||||
perPage: 10,
|
||||
@@ -116,18 +117,19 @@ export default {
|
||||
tab: "0",
|
||||
}
|
||||
},
|
||||
async mounted () {
|
||||
const code = this.$route.query.code
|
||||
if (code) {
|
||||
this.tab = "4"
|
||||
const instance = await api.setCode({code, is_admin: true})
|
||||
}
|
||||
// this.users = await api.getUsers()
|
||||
// this.events = await api.getUnconfirmedEvents()
|
||||
// this.settings = await api.getAdminSettings()
|
||||
this.mastodon_instance = this.settings.mastodon_auth && this.settings.mastodon_auth.instance
|
||||
},
|
||||
async asyncData ({ $axios, params }) {
|
||||
// async mounted () {
|
||||
// const code = this.$route.query.code
|
||||
// if (code) {
|
||||
// this.tab = "4"
|
||||
// const instance = await api.setCode({code, is_admin: true})
|
||||
// }
|
||||
// // this.users = await api.getUsers()
|
||||
// // this.events = await api.getUnconfirmedEvents()
|
||||
// // this.settings = await api.getAdminSettings()
|
||||
// this.mastodon_instance = this.settings.mastodon_auth && this.settings.mastodon_auth.instance
|
||||
// },
|
||||
async asyncData ({ $axios, params, store }) {
|
||||
console.log(store.state)
|
||||
const users = await $axios.$get('/users')
|
||||
return { users }
|
||||
},
|
||||
|
||||
133
pages/export.vue
Normal file
133
pages/export.vue
Normal file
@@ -0,0 +1,133 @@
|
||||
<template lang="pug">
|
||||
b-modal(ref='modal' @hidden='$router.replace("/")'
|
||||
:title='$t("Export")' :visible='true' size='lg' hide-footer)
|
||||
p {{$t('export_intro')}}
|
||||
|
||||
li(v-if='filters.tags.length') {{$t('Tags')}}:
|
||||
el-tag.ml-1(color='#409EFF' size='mini' v-for='tag in filters.tags' :key='tag.tag') {{tag}}
|
||||
li(v-if='filters.places.length') {{$t('Places')}}:
|
||||
el-tag.ml-1(color='#409EFF' size='mini' v-for='place in filters.places' :key='place.id') {{place}}
|
||||
el-tabs.mt-2(tabPosition='left' v-model='type')
|
||||
|
||||
el-tab-pane.pt-1(label='email' name='email')
|
||||
p(v-html='$t(`export_email_explanation`)')
|
||||
el-form(@submit.native.prevent)
|
||||
//- el-switch(v-model='notification.notify_on_add' :active-text="$t('notify_on_insert')")
|
||||
//- br
|
||||
//- el-switch.mt-2(v-model='notification.send_notification' :active-text="$t('send_notification')")
|
||||
el-input.mt-2(v-model='notification.email' :placeholder="$t('Insert your address')" ref='email')
|
||||
el-button.mt-2.float-right(native-type= 'submit' type='success' @click='add_notification') {{$t('Send')}}
|
||||
|
||||
el-tab-pane.pt-1(label='feed rss' name='feed')
|
||||
span(v-html='$t(`export_feed_explanation`)')
|
||||
el-input(v-model='link')
|
||||
el-button(slot='append' plain type="primary" icon='el-icon-document' v-clipboard:copy="link") {{$t("Copy")}}
|
||||
|
||||
el-tab-pane.pt-1(label='ics/ical' name='ics')
|
||||
p(v-html='$t(`export_ical_explanation`)')
|
||||
el-input(v-model='link')
|
||||
el-button(slot='append' plain type="primary" icon='el-icon-document' v-clipboard:copy="link") {{$t("Copy")}}
|
||||
|
||||
el-tab-pane.pt-1(label='list' name='list')
|
||||
p(v-html='$t(`export_list_explanation`)')
|
||||
el-card.mb-1(no-body header='Eventi')
|
||||
b-list-group#list(flush)
|
||||
b-list-group-item.flex-column.align-items-start(v-for="event in filteredEvents" :key='event.id'
|
||||
:to='`/event/${event.id}`')
|
||||
//- b-media
|
||||
img(v-if='event.image_path' slot="aside" :src="imgPath(event)" alt="Meia Aside" style='max-height: 60px')
|
||||
small.float-right {{event.start_datetime|datetime}}
|
||||
strong.mb-1 {{event.title}}
|
||||
br
|
||||
small.float-right {{event.place.name}}
|
||||
el-tag.mr-1(:color='tag.color || "grey"' size='mini' v-for='tag in event.tags' :key='tag.tag') {{tag.tag}}
|
||||
el-input.mb-1(type='textarea' v-model='script')
|
||||
el-button.float-right(plain type="primary" icon='el-icon-document' v-clipboard:copy="script") Copy
|
||||
|
||||
|
||||
el-tab-pane.pt-1(label='calendar' name='calendar')
|
||||
p(v-html='$t(`export_calendar_explanation`)')
|
||||
Calendar.mb-1
|
||||
el-input.mb-1(type='textarea' v-model='script')
|
||||
el-button.float-right(plain type="primary" icon='el-icon-document' v-clipboard:copy="script") Copy
|
||||
|
||||
</template>
|
||||
<script>
|
||||
import { mapState } from 'vuex'
|
||||
import path from 'path'
|
||||
// import filters from '../filters'
|
||||
import Calendar from '@/components/Calendar'
|
||||
import {intersection} from 'lodash'
|
||||
// import api from '@/api'
|
||||
import { Message } from 'element-ui'
|
||||
|
||||
export default {
|
||||
name: 'Export',
|
||||
components: { Calendar },
|
||||
data () {
|
||||
return {
|
||||
type: 'email',
|
||||
link: '',
|
||||
export_list: true,
|
||||
script: `<iframe>Ti piacerebbe</iframe>`,
|
||||
notification: { email: '' },
|
||||
}
|
||||
},
|
||||
// filters,
|
||||
mounted () {
|
||||
this.link = this.loadLink()
|
||||
},
|
||||
watch: {
|
||||
type (value) {
|
||||
this.link = this.loadLink()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async add_notification () {
|
||||
if (!this.notification.email){
|
||||
Message({message:'Inserisci una mail', type: 'error'})
|
||||
return this.$refs.email.focus()
|
||||
}
|
||||
await api.addNotification({ ...this.notification, filters: this.filters})
|
||||
this.$refs.modal.hide()
|
||||
Message({message: this.$t('email_notification_activated'), type: 'success'})
|
||||
},
|
||||
loadLink () {
|
||||
const tags = this.filters.tags.join(',')
|
||||
const places = this.filters.places.join(',')
|
||||
let query = ''
|
||||
if (tags || places) {
|
||||
query = '?'
|
||||
if (tags) {
|
||||
query += 'tags=' + tags
|
||||
if (places) { query += '&places=' + places }
|
||||
} else {
|
||||
query += 'places=' + places
|
||||
}
|
||||
}
|
||||
|
||||
return `${process.env.VUE_APP_API}/api/export/${this.type}${query}`
|
||||
},
|
||||
imgPath (event) {
|
||||
return event.image_path && event.image_path
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
...mapState(['filters', 'user', 'logged', 'events']),
|
||||
filteredEvents () {
|
||||
return this.$store.getters.filteredEvents.filter(e => !e.past)
|
||||
},
|
||||
showLink () {
|
||||
return (['feed', 'ics'].indexOf(this.type)>-1)
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
#list {
|
||||
max-height: 400px;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
<template lang='pug'>
|
||||
b-modal(@shown="$refs.email.focus()" :title='$t("Login")' hide-footer
|
||||
b-modal(@shown="$refs.email.focus()" :title='$t("common.login")' hide-footer
|
||||
@hidden='$router.replace("/")' :visible='true' ref='modal')
|
||||
el-form(v-loading='loading')
|
||||
p(v-html="$t('login_explanation')")
|
||||
el-input.mb-2(v-model='email' type='email' :placeholder='$t("Email")' autocomplete='email' ref='email')
|
||||
p(v-html="$t('login.description')")
|
||||
el-input.mb-2(v-model='email' type='email' :placeholder='$t("common.email")' autocomplete='email' ref='email')
|
||||
v-icon(name='user' slot='prepend')
|
||||
el-input.mb-1(v-model='password' @keyup.enter.native="submit" type='password' :placeholder='$t("Password")')
|
||||
el-input.mb-1(v-model='password' @keyup.enter.native="submit" type='password' :placeholder='$t("common.password")')
|
||||
v-icon(name="lock" slot='prepend')
|
||||
el-button.mr-1(plain type="success" @click='submit') {{$t('Login')}}
|
||||
el-button.mr-1(plain type="success" @click='submit') {{$t('common.login')}}
|
||||
router-link(to='/register')
|
||||
el-button.mt-1(plain type="primary") {{$t('Not registered?')}}
|
||||
a.float-right(href='#' @click='forgot') {{$t('Forgot password?')}}
|
||||
el-button.mt-1(plain type="primary") {{$t('login.not_registered')}}
|
||||
a.float-right(href='#' @click='forgot') {{$t('login.forgot_password')}}
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const Cookie = process.client ? require('js-cookie') : undefined
|
||||
import { mapActions } from 'vuex'
|
||||
import { Message } from 'element-ui'
|
||||
// import api from '@/plugins/api'
|
||||
@@ -31,29 +32,24 @@ export default {
|
||||
...mapActions(['login']),
|
||||
async forgot () {
|
||||
if (!this.email) {
|
||||
Message({ message: this.$t('Insert your email'), type: 'error' })
|
||||
Message({ message: this.$t('login.insert_email'), type: 'error' })
|
||||
this.$refs.email.focus()
|
||||
return
|
||||
}
|
||||
this.loading = true
|
||||
// await api.forgotPassword(this.email)
|
||||
this.loading = false
|
||||
Message({ message: this.$t('Check your email!'), type: 'success' })
|
||||
Message({ message: this.$t('login.check_email'), type: 'success' })
|
||||
},
|
||||
async submit (e) {
|
||||
e.preventDefault()
|
||||
try {
|
||||
this.loading = true
|
||||
const user = await this.$axios.$post('/login', { email: this.email, password: this.password })
|
||||
await this.$auth.loginWith('local', { data: { email: this.email, password: this.password } })
|
||||
this.loading = false
|
||||
if (!user) {
|
||||
Message({ message: this.$t('Login error'), type: 'error' })
|
||||
return;
|
||||
}
|
||||
this.login(user)
|
||||
Message({ message: this.$t('Logged'), type: 'success' })
|
||||
Message({ message: this.$t('login.ok'), type: 'success' })
|
||||
} catch (e) {
|
||||
Message({ message: this.$t('Login error'), type: 'error' })
|
||||
Message({ message: this.$t('login.error') + e, type: 'error' })
|
||||
this.loading = false
|
||||
return
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
<template lang='pug'>
|
||||
b-modal(hide-footer @hidden='$router.replace("/")' ref='modal'
|
||||
:title="$t('Register')" :visible='true' @shown='$refs.email.focus()')
|
||||
:title="$t('common.register')" :visible='true' @shown='$refs.email.focus()')
|
||||
el-form
|
||||
p(v-html="$t('register_explanation')")
|
||||
p(v-html="$t('register.description')")
|
||||
el-input.mb-2(ref='email' v-model='user.email' type='email'
|
||||
:placeholder='$t("Email")' autocomplete='email')
|
||||
:placeholder='$t("common.email")' autocomplete='email')
|
||||
span(slot='prepend') @
|
||||
|
||||
el-input.mb-2(v-model='user.password' type="password" placeholder="Password")
|
||||
v-icon(name='lock' slot='prepend')
|
||||
|
||||
el-input.mb-2(v-model='user.description' type="textarea" rows='3' :placeholder="$t('Description')")
|
||||
el-input.mb-2(v-model='user.description' type="textarea" rows='3' :placeholder="$t('common.description')")
|
||||
v-icon(name='envelope-open-text')
|
||||
|
||||
el-button.float-right(plain type="success" icon='el-icon-arrow-right' @click='register') {{$t('Send')}}
|
||||
el-button.float-right(plain type="success" icon='el-icon-arrow-right' @click='register') {{$t('common.send')}}
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -33,23 +33,15 @@ export default {
|
||||
...mapActions(['login']),
|
||||
async register () {
|
||||
try {
|
||||
const user = await this.$axios.$post('/user', this.user) //api.register(this.user)
|
||||
console.log(user)
|
||||
if (!user.is_admin) {
|
||||
this.$refs.modal.hide()
|
||||
Message({
|
||||
message: this.$t('registration_complete'),
|
||||
type: 'success'
|
||||
})
|
||||
} else {
|
||||
Message({
|
||||
message: this.$t('admin_registration_complete'),
|
||||
type: 'success'
|
||||
})
|
||||
}
|
||||
const user = await this.$axios.$post('/user', this.user)
|
||||
this.$refs.modal.hide()
|
||||
Message({
|
||||
message: this.$t(`register.${user.is_admin && 'admin_'}complete`),
|
||||
type: 'success'
|
||||
})
|
||||
} catch (e) {
|
||||
Message({
|
||||
message: e,
|
||||
message: this.$t('register.error') + e,
|
||||
type: 'error'
|
||||
})
|
||||
console.error(e)
|
||||
|
||||
60
pages/settings.vue
Normal file
60
pages/settings.vue
Normal file
@@ -0,0 +1,60 @@
|
||||
<template lang="pug">
|
||||
b-modal(:title="$t('common.settings')" hide-footer @hidden='$router.replace("/")' :visible='true')
|
||||
h5 {{user.name}}
|
||||
el-input(v-model="mastodon_instance" @enter.native='associate')
|
||||
span(slot='prepend') {{$t('settings.mastodon_instance')}}
|
||||
el-button(v-if='!user.mastodon_auth' slot='append' @click='associate' type='success') {{$t('settings.associate')}}
|
||||
el-button(v-else slot='append' @click='deassociate' variant='success') {{$t('settings.unassociate')}}
|
||||
el-input.mt-2(v-model='password' type='password')
|
||||
span(slot='prepend') {{$t('settings.change_password')}}
|
||||
el-button(slot='append' @click='change' type='success') {{$t('settings.change')}}
|
||||
</template>
|
||||
<script>
|
||||
import { mapState, mapActions } from 'vuex'
|
||||
export default {
|
||||
props: ['code'],
|
||||
data () {
|
||||
return {
|
||||
mastodon_instance: '',
|
||||
password: '',
|
||||
user: {}
|
||||
}
|
||||
},
|
||||
computed: mapState(['oauth', 'user']),
|
||||
async asyncData ({ $axios, params }) {
|
||||
// const code = this.$route.query.code
|
||||
// if (code) {
|
||||
// const res = await api.setCode({code})
|
||||
// }
|
||||
const user = await $axios.$get('/user')
|
||||
user.mastodon_auth = ''
|
||||
return { user } //, mastodon_instance: user.mastodon_auth.instance }
|
||||
// this.user = user
|
||||
// this.mastodon_instance = user.mastodon_auth.instance
|
||||
},
|
||||
methods: {
|
||||
async change () {
|
||||
if (!this.password) return
|
||||
const user = this.user
|
||||
user.password = this.password
|
||||
try {
|
||||
await api.updateUser(user)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
},
|
||||
async deassociate () {
|
||||
const user = this.user
|
||||
user.mastodon_auth = ''
|
||||
this.mastodon_instance = ''
|
||||
await api.updateUser(user)
|
||||
},
|
||||
async associate () {
|
||||
if (!this.mastodon_instance) return
|
||||
const url = await this.$axios.$post('/user/getauthurl', {instance: this.mastodon_instance})
|
||||
setTimeout( () => window.location.href=url, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user