From 3b80dd5f73b3327bcd9a40f672647428daddcd64 Mon Sep 17 00:00:00 2001 From: les Date: Fri, 26 Apr 2019 23:14:43 +0200 Subject: [PATCH] auth.nuxt.js plugin --- .vscode/vscode-kanban.json | 142 +++++++++++++++++++++++++++++++ components/Nav.vue | 28 +++--- layouts/default.vue | 14 --- locales/it.json | 46 ++++++++++ nuxt.config.js | 18 +++- package.json | 4 + pages/{new_event.vue => add.vue} | 56 ++++++------ pages/admin.vue | 26 +++--- pages/export.vue | 133 +++++++++++++++++++++++++++++ pages/{Login.vue => login.vue} | 30 +++---- pages/register.vue | 32 +++---- pages/settings.vue | 60 +++++++++++++ plugins/i18n.js | 20 ++--- server/api/auth.js | 1 - server/api/controller/event.js | 2 +- server/api/controller/user.js | 24 ++++-- server/api/index.js | 12 ++- server/api/models/user.js | 2 +- server/index.js | 3 +- store/index.js | 24 ++---- 20 files changed, 528 insertions(+), 149 deletions(-) create mode 100644 .vscode/vscode-kanban.json create mode 100644 locales/it.json rename pages/{new_event.vue => add.vue} (80%) create mode 100644 pages/export.vue rename pages/{Login.vue => login.vue} (58%) create mode 100644 pages/settings.vue diff --git a/.vscode/vscode-kanban.json b/.vscode/vscode-kanban.json new file mode 100644 index 00000000..47a6e887 --- /dev/null +++ b/.vscode/vscode-kanban.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/components/Nav.vue b/components/Nav.vue index 892755e5..67a682e2 100644 --- a/components/Nav.vue +++ b/components/Nav.vue @@ -4,21 +4,21 @@ b-navbar-brand(to='/') b-collapse#nav_collapse(is-nav) b-navbar-nav - b-nav-item(v-if='!logged' to='/login' v-b-tooltip :title='$t("Login")') - span.d-md-none {{$t('User')}} - b-nav-item(to='/new_event' v-b-tooltip :title='$t("Add Event")' ) - span.d-md-none {{$t('Add Event')}} - b-nav-item(v-if='logged' to='/settings' v-b-tooltip :title='$t("Settings")') - span.d-md-none {{$t('Settings')}} - b-nav-item(v-if='user.is_admin' to='/admin' v-b-tooltip :title='$t("Admin")') - span.d-md-none {{$t('Admin')}} - b-nav-item(to='/export' v-b-tooltip :title='$t("Export")') - span.d-md-none {{$t('Export')}} - b-nav-item(v-if='logged' @click='logout' v-b-tooltip :title='$t("Logout")') - span.d-md-none {{$t('Logout')}} + b-nav-item(v-if='!$auth.loggedIn' to='/login' v-b-tooltip :title='$t("common.login")') + span.d-md-none {{$t('common.login')}} + b-nav-item(to='/add' v-b-tooltip :title='$t("common.add_event")' ) + span.d-md-none {{$t('common.add_event')}} + b-nav-item(v-if='$auth.loggedIn' to='/settings' v-b-tooltip :title='$t("common.settings")') + span.d-md-none {{$t('common.settings')}} + b-nav-item(v-if='$auth.hasScope(`admin`)' to='/admin' v-b-tooltip :title='$t("common.admin")') + span.d-md-none {{$t('common.admin')}} + b-nav-item(to='/export' v-b-tooltip :title='$t("common.export")') + span.d-md-none {{$t('common.export')}} + b-nav-item(v-if='auth.loggedIn' @click='logout' v-b-tooltip :title='$t("common.logout")') + span.d-md-none {{$t('common.logout')}} b-navbar-nav.ml-auto b-nav-item(to='/about') - span {{$t('Info')}} + span {{$t('common.info')}} diff --git a/locales/it.json b/locales/it.json new file mode 100644 index 00000000..efa952cb --- /dev/null +++ b/locales/it.json @@ -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.
Questo è un dono per voi, usatelo solo per eventi non commerciali e ovviamente antifascisti, antisessisti, antirazzisti.
Prima di poter pubblicare dobbiamo approvare l'account, considera che dietro questo sito ci sono delle persone 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)" + } +} + diff --git a/nuxt.config.js b/nuxt.config.js index e89df3e1..29c34492 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -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 */ diff --git a/package.json b/package.json index 729e4b36..ecb78137 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pages/new_event.vue b/pages/add.vue similarity index 80% rename from pages/new_event.vue rename to pages/add.vue index e0c9bf23..ae5c2ac1 100644 --- a/pages/new_event.vue +++ b/pages/add.vue @@ -1,62 +1,62 @@