auth.nuxt.js plugin

This commit is contained in:
les 2019-04-26 23:14:43 +02:00
parent eed3896396
commit 3b80dd5f73
20 changed files with 528 additions and 149 deletions

142
.vscode/vscode-kanban.json vendored Normal file
View file

@ -0,0 +1,142 @@
{
"done": [],
"in-progress": [],
"testing": [
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:47:35.777Z",
"id": "5",
"prio": 3,
"references": [],
"title": "server side auth"
}
],
"todo": [
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:50:00.973Z",
"id": "7",
"prio": 1,
"references": [],
"title": "export page",
"type": "bug"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:55:59.993Z",
"id": "10",
"prio": 1,
"references": [],
"title": "gestione errori form aggiungi evento",
"type": "bug"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:50:55.458Z",
"id": "8",
"prio": 1,
"references": [],
"title": "rivedere ux / messaggi utente",
"type": "bug"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:56:46.263Z",
"id": "11",
"prio": 1,
"references": [],
"title": "get comments / media from mastodon"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:45:27.613Z",
"description": {
"content": "probabilmente devo far diventare il campo senza timezone",
"mime": "text/markdown"
},
"id": "2",
"prio": 0,
"references": [],
"title": "check date timezone",
"type": "bug"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:48:54.407Z",
"description": {
"content": "probabilmente lato client dovrei aggiungere una classe css al body per capire se js e' attivo o meno e poi lavorare di css",
"mime": "text/markdown"
},
"id": "6",
"prio": 0,
"references": [],
"title": "risolvere le modali quando il js e' disabilitato",
"type": "bug"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:46:46.332Z",
"id": "3",
"prio": 0,
"references": [],
"title": "export lista"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:44:56.705Z",
"id": "1",
"references": [],
"title": "popup sul calendario"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:47:10.704Z",
"id": "4",
"prio": 0,
"references": [],
"title": "traduzione in inglese"
},
{
"assignedTo": {
"name": "lesion"
},
"category": "feature",
"creation_time": "2019-04-23T19:51:05.917Z",
"id": "9",
"prio": -1,
"references": [],
"title": "documentare sorgenti",
"type": "bug"
}
]
}

View file

@ -4,21 +4,21 @@
b-navbar-brand(to='/') <img id='logo' src='gancio_logo.svg'/>
b-collapse#nav_collapse(is-nav)
b-navbar-nav
b-nav-item(v-if='!logged' to='/login' v-b-tooltip :title='$t("Login")') <v-icon color='lightgreen' name='lock' />
span.d-md-none {{$t('User')}}
b-nav-item(to='/new_event' v-b-tooltip :title='$t("Add Event")' ) <v-icon color='lightgreen' name='plus'/>
span.d-md-none {{$t('Add Event')}}
b-nav-item(v-if='logged' to='/settings' v-b-tooltip :title='$t("Settings")') <v-icon color='orange' name='cog'/>
span.d-md-none {{$t('Settings')}}
b-nav-item(v-if='user.is_admin' to='/admin' v-b-tooltip :title='$t("Admin")') <v-icon color='lightblue' name='tools'/>
span.d-md-none {{$t('Admin')}}
b-nav-item(to='/export' v-b-tooltip :title='$t("Export")') <v-icon name='file-export' color='yellow'/>
span.d-md-none {{$t('Export')}}
b-nav-item(v-if='logged' @click='logout' v-b-tooltip :title='$t("Logout")') <v-icon color='red' name='sign-out-alt'/>
span.d-md-none {{$t('Logout')}}
b-nav-item(v-if='!$auth.loggedIn' to='/login' v-b-tooltip :title='$t("common.login")') <v-icon color='lightgreen' name='lock' />
span.d-md-none {{$t('common.login')}}
b-nav-item(to='/add' v-b-tooltip :title='$t("common.add_event")' ) <v-icon color='lightgreen' name='plus'/>
span.d-md-none {{$t('common.add_event')}}
b-nav-item(v-if='$auth.loggedIn' to='/settings' v-b-tooltip :title='$t("common.settings")') <v-icon color='orange' name='cog'/>
span.d-md-none {{$t('common.settings')}}
b-nav-item(v-if='$auth.hasScope(`admin`)' to='/admin' v-b-tooltip :title='$t("common.admin")') <v-icon color='lightblue' name='tools'/>
span.d-md-none {{$t('common.admin')}}
b-nav-item(to='/export' v-b-tooltip :title='$t("common.export")') <v-icon name='file-export' color='yellow'/>
span.d-md-none {{$t('common.export')}}
b-nav-item(v-if='auth.loggedIn' @click='logout' v-b-tooltip :title='$t("common.logout")') <v-icon color='red' name='sign-out-alt'/>
span.d-md-none {{$t('common.logout')}}
b-navbar-nav.ml-auto
b-nav-item(to='/about')
span {{$t('Info')}} <v-icon color='#ff9fc4' name='question-circle'/>
span {{$t('common.info')}} <v-icon color='#ff9fc4' name='question-circle'/>
</template>
<script>
@ -26,7 +26,7 @@ import {mapState, mapActions} from 'vuex'
export default {
name: 'Nav',
computed: {
...mapState(['logged', 'user','filters']),
...mapState(['filters', 'auth']),
filters_tags: {
set (value) {
this.setSearchTags(value)

View file

@ -3,29 +3,15 @@
Nav
Home
transition(name="fade" mode="out-in")
//- router-view(name='modal')
nuxt
</template>
<script>
// import moment from 'dayjs'
// import api from './api'
// import { mapActions } from 'vuex';
// import Register from './components/Register.vue'
// import Login from './components/Login.vue'
// import Settings from './components/Settings.vue'
// import newEvent from './components/newEvent.vue'
// import eventDetail from './components/EventDetail.vue'
import Home from '~/components/Home.vue'
import Nav from '~/components/Nav.vue'
export default {
name: 'App',
// mounted () {
// this.updateMeta()
// },
// methods: mapActions(['updateMeta']),
// components: { Nav, Register, Login, Home, Settings, newEvent, eventDetail },
components: { Nav, Home },
}
</script>

46
locales/it.json Normal file
View file

@ -0,0 +1,46 @@
{
"common": {
"login": "Entra",
"email": "Email",
"password": "Password",
"register": "Registrati",
"send": "Invia",
"description": "Descrizione",
"info": "Info",
"add_event": "Aggiungi evento",
"export": "Esporta",
"settings": "Impostazioni",
"admin": "Amministra",
"logout": "Esci",
"where": "Dove",
"when": "Quando",
"next": "Avanti",
"what": "Cosa",
"address": "Indirizzo",
"media": "Media"
},
"login": {
"description": "Entrando puoi pubblicare nuovi eventi.",
"not_registered": "Non sei registrata?",
"forgot_password": "Ho dimenticato la password",
"insert_email": "Inserisci la mail",
"check_email": "Controlla la tua casella di posta (anche la cartella spam)",
"error": "Errore nel login"
},
"register": {
"description": "I movimenti hanno bisogno di organizzarsi e autofinanziarsi. <br/>Questo è un dono per voi, usatelo solo per eventi non commerciali e ovviamente antifascisti, antisessisti, antirazzisti. <br/>Prima di poter pubblicare <strong>dobbiamo approvare l'account</strong>, considera che <strong>dietro questo sito ci sono delle persone</strong> di carne e sangue, scrivici quindi due righe per farci capire che eventi vorresti pubblicare.",
"complete": "",
"admin_complete": ""
},
"event": {
"anon": "",
"anon_description": "",
"where_description" : "Dov'è il gancio? Se è un luogo fisico, scrivi il suo nome del per esteso (tipo 'Mezcal Squat'), se è una Piazza/Via metti quella (tipo 'Piazza Castello, Torino'). Se trovi già il luogo dell'evento premilo e l'indirizzo verrà autocompletato.",
"address_description": "",
"tag_description": "Puoi inserire un tag (es. concerto, corteo)"
}
}

View file

@ -15,7 +15,7 @@ module.exports = {
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
},
serverMiddleware: [
{ path: '/api', handler: '@/server/api/index.js' }
],
@ -50,7 +50,8 @@ module.exports = {
*/
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios'
'@nuxtjs/axios',
'@nuxtjs/auth'
],
/*
** Axios module configuration
@ -61,6 +62,19 @@ module.exports = {
// See https://github.com/nuxt-community/axios-module#options
},
auth: {
strategies: {
local: {
endpoints: {
login: { url: '/auth/login', method: 'post', propertyName: 'token' },
logout: { url: '/auth/logout', method: 'post' },
user: { url: '/auth/user', method: 'get', propertyName: 'user' }
},
// tokenRequired: true,
// tokenType: 'bearer',
}
}
},
/*
** Build configuration
*/

View file

@ -13,18 +13,22 @@
"precommit": "npm run lint"
},
"dependencies": {
"@nuxtjs/auth": "^4.5.3",
"@nuxtjs/axios": "^5.4.1",
"axios": "^0.18.0",
"bcrypt": "^3.0.5",
"body-parser": "^1.18.3",
"bootstrap-vue": "^2.0.0-rc.16",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"cross-env": "^5.2.0",
"dayjs": "^1.8.11",
"element-ui": "^2.4.11",
"email-templates": "^5.0.4",
"express": "^4.16.4",
"express-jwt": "^5.3.1",
"ics": "^2.13.2",
"js-cookie": "^2.2.0",
"jsonwebtoken": "^8.5.1",
"mastodon-api": "^1.3.0",
"morgan": "^1.9.1",

View file

@ -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)

View file

@ -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
View 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>

View file

@ -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
}

View file

@ -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
View 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>

View file

@ -8,18 +8,18 @@ export default ({ app, store }) => {
// This way we can use it in middleware and pages asyncData/fetch
app.i18n = new VueI18n({
locale: store.state.locale,
fallbackLocale: 'en'
// messages: {
// 'en': require('~/locales/en.json'),
fallbackLocale: 'it',
messages: {
'it': require('~/locales/it.json')
// 'fr': require('~/locales/fr.json')
// }
}
})
app.i18n.path = (link) => {
if (app.i18n.locale === app.i18n.fallbackLocale) {
return `/${link}`
}
// app.i18n.path = (link) => {
// if (app.i18n.locale === app.i18n.fallbackLocale) {
// return `/${link}`
// }
return `/${app.i18n.locale}/${link}`
}
// return `/${app.i18n.locale}/${link}`
// }
}

View file

@ -21,7 +21,6 @@ const Auth = {
(req.body && req.body.token) ||
req.params.token ||
req.headers.authorization
console.error('sono dentro isAuth ', token, req.headers)
if (!token) return res.status(403).send({ message: 'Token not found' })
jwt.verify(token, config.secret, async (err, decoded) => {
if (err) {

View file

@ -160,7 +160,7 @@ const eventController = {
// { model: Place, required: false }
// ]
})
console.log(events)
// console.log(events)
res.json(events)
}

View file

@ -4,7 +4,7 @@ const crypto = require('crypto')
const jwt = require('jsonwebtoken')
const Mastodon = require('mastodon-api')
const { Op } = require('sequelize')
const jsonwebtoken = require('jsonwebtoken')
const User = require('../models/user')
const config = require('../config')
const mail = require('../mail')
@ -27,18 +27,24 @@ const userController = {
} else {
// if user is found and password is right
// create a token
const payload = { email: user.email }
const token = jwt.sign(payload, config.secret)
res.json({
success: true,
message: 'Enjoy your token!',
token,
user
})
const accessToken = jsonwebtoken.sign({ user:
{
id: user.id,
email: user.email,
scope: [user.is_admin ? 'admin' : 'user']
}},
config.secret
)
res.json({token: accessToken})
}
}
},
async logout(req, res) {
},
async setToken(req, res) {
req.user.mastodon_auth = req.body
await req.user.save()

View file

@ -5,8 +5,10 @@ const eventController = require('./controller/event')
const exportController = require('./controller/export')
const userController = require('./controller/user')
const settingsController = require('./controller/settings')
const config = require('./config')
// const botController = require('./controller/bot')
const jwt = require('express-jwt')({secret: config.secret})
const storage = require('./storage')({
destination: 'uploads/'
@ -14,8 +16,12 @@ const storage = require('./storage')({
const upload = multer({ storage })
const api = express.Router()
// login
api.post('/login', userController.login)
// AUTH
api.post('/auth/login', userController.login)
api.post('/auth/logout', userController.logout)
api.get('/auth/user', jwt, userController.current)
api.post('/user/recover', userController.forgotPassword)
api.post('/user/check_recover_code', userController.checkRecoverCode)
api.post('/user/recover_password', userController.updatePasswordWithRecoverCode)
@ -25,7 +31,7 @@ api
// register
.post(userController.register)
// get current user
.get(isAuth, userController.current)
// .get(isAuth, userController.current)
// update user (eg. confirm)
.put(isAuth, isAdmin, userController.update)

View file

@ -1,6 +1,6 @@
const Sequelize = require('sequelize')
const bcrypt = require('bcrypt')
const db = require('../db')
const Sequelize = require('sequelize')
const User = db.define('user', {
email: {

View file

@ -2,6 +2,7 @@ const express = require('express')
const consola = require('consola')
const morgan = require('morgan')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const cors = require('cors')
@ -31,7 +32,7 @@ async function start() {
// Give nuxt middleware to express
app.use(cors(corsConfig))
app.use(morgan('dev'))
// app.set('views', path.join)
app.use(cookieParser())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(nuxt.render)

View file

@ -1,19 +1,11 @@
import moment from 'dayjs'
import { intersection } from 'lodash'
import api from '~/plugins/api'
import Vue from 'vue'
Vue.config.errorHandler = function (err, vm, info) {
// handle error
// `info` is a Vue-specific error info, e.g. which lifecycle hook
// the error was found in. Only available in 2.2.0+
console.error(err)
console.error(info)
}
export const state = () => ({
events: [],
user: {},
locale: 'it',
logged: false,
token: '',
tags: [],
@ -109,18 +101,20 @@ export const actions = {
// get current month's event
async nuxtServerInit({ commit }, { req }) {
// set user if logged! TODO
const now = new Date()
// const events = await api.getAllEvents(now.getMonth() - 1, now.getFullYear())
const events = await this.$axios.$get(`/event/${now.getMonth() - 1}/${now.getFullYear()}`)
commit('setEvents', events)
},
async updateEvents({ commit }, page) {
const events = await this.$axios.$get(`/event/${page.month}/${page.year}`)
commit('setEvents', events)
},
async updateMeta({ commit }) {
const { tags, places } = await this.$axios.$get('/event/meta')
commit('update', { tags, places })
},
async addEvent({ commit }, formData) {
console.log('ciao addEvent')
const event = await this.$axios.$post('/user/event', formData) // .addEvent(formData)
if (this.state.logged) {
commit('addEvent', event)
@ -133,14 +127,6 @@ export const actions = {
delEvent({ commit }, eventId) {
commit('delEvent', eventId)
},
login({ commit }, user) {
this.$axios.setToken(user.token)
commit('login', user)
},
logout({ commit }) {
this.$axios.setToken(false)
commit('logout')
},
// search
addSearchTag({ commit }, tag) {
commit('addSearchTag', tag)