From fa945e45c95ede1826d00ffb9d90468dbb7b9fab Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Fri, 18 Dec 2020 20:34:47 +0100 Subject: [PATCH] - Fixed my revert hahaha :) --- api/repositories/user-repository.js | 11 +- .../src/components/global/navbar/navbar.vue | 99 ++++++------ client/src/main.js | 35 +---- client/src/pages/user/login-page.vue | 141 +++++++++--------- client/src/pages/user/profile-page.vue | 24 +-- client/src/routes.js | 140 ++++++++--------- 6 files changed, 215 insertions(+), 235 deletions(-) diff --git a/api/repositories/user-repository.js b/api/repositories/user-repository.js index 88c7046..631b8c7 100644 --- a/api/repositories/user-repository.js +++ b/api/repositories/user-repository.js @@ -116,7 +116,8 @@ class UserRepository { .then(newUser => { resolve({ "message": "Account successfully created !", - "user": newUser, + "code": 201, + "token": newUser.uuid, }) }) .catch(err => { @@ -146,11 +147,13 @@ class UserRepository { if (match) { resolve({ "message": "User successfully logged in !", - "user": fetchedUser, + "code": 200, + "token": fetchedUser.uuid, }) } else { reject({ - "message": "Les informations de connexion sont erronées.", + "message": "Authentification attempt failed ; credentials are incorrect.", + "code": 400, }) } }) @@ -166,7 +169,7 @@ class UserRepository { this.getOneByEmail(mail, false) .then(() => { reject({ - "message": "L'email est déjà utilisé par un autre utilisateur.", + "message": "This email is already linked to an account.", "code": 403 }) }) diff --git a/client/src/components/global/navbar/navbar.vue b/client/src/components/global/navbar/navbar.vue index aac51ae..8ae82e0 100644 --- a/client/src/components/global/navbar/navbar.vue +++ b/client/src/components/global/navbar/navbar.vue @@ -1,60 +1,61 @@ diff --git a/client/src/main.js b/client/src/main.js index d92181e..eeadef3 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -1,9 +1,10 @@ // Core import Vue from 'vue' -import Vuex from 'vuex' import VueRouter from 'vue-router' import App from './app.vue' +import store from './store' + import Globals from './global-components.js' Globals.forEach(component => { Vue.component(component.name, component) @@ -55,38 +56,6 @@ Vue.filter('truncate', filter) import router from './routes' Vue.use(VueRouter) -// Store -Vue.use(Vuex) -let user = Vue.$cookies.get('U_') - -const store = new Vuex.Store({ - state: user ? - { status: { loggedIn: true }, user } - : { status: { loggedIn: false }, user: null }, - mutations: { - loginSucceed (state, user) { - state.status.loggedIn = true - state.user = user - }, - loginFail (state) { - state.status.loggedIn = false - state.user = null - }, - logout(state) { - state.status.loggedIn = false; - state.user = null; - }, - registerSucceed (state, user) { - state.status.loggedIn = true - state.user = user - }, - registerFail (state) { - state.status.loggedIn = false - state.user = null - }, - } -}) - // Mount Vue const app = new Vue({ render: h => h(App), diff --git a/client/src/pages/user/login-page.vue b/client/src/pages/user/login-page.vue index 5317808..0399ded 100644 --- a/client/src/pages/user/login-page.vue +++ b/client/src/pages/user/login-page.vue @@ -1,92 +1,93 @@ \ No newline at end of file diff --git a/client/src/pages/user/profile-page.vue b/client/src/pages/user/profile-page.vue index 61d836c..1aa4071 100644 --- a/client/src/pages/user/profile-page.vue +++ b/client/src/pages/user/profile-page.vue @@ -1,24 +1,25 @@ \ No newline at end of file diff --git a/client/src/routes.js b/client/src/routes.js index fa1f340..9c0a412 100644 --- a/client/src/routes.js +++ b/client/src/routes.js @@ -1,5 +1,5 @@ -import Vue from 'vue' import VueRouter from 'vue-router' +import store from './store' // Pages import Index from "~/pages/index-page" @@ -18,80 +18,84 @@ import Profile from "~/pages/user/profile-page" // Routes const routes = [ - { - path: "*", - redirect: "/", - }, - { - path: '/', - component: Index, - }, - { - path: '/connexion', - component: Login, - meta: { - antiAuthGuard: true - } - }, - { - path: '/inscription', - component: Register, - meta: { - antiAuthGuard: true - } - }, - { - path: '/sorts', - component: Spells, - }, - { - path: '/sorts/:id', - component: SpellSingle, - props: true, - }, - { - path: '/ecoles', - component: Schools, - }, - { - path: '/ecoles/:id', - component: SchoolSingle, - props: true, - }, - { - path: '/ages', - component: Timeline, - }, - { - path: '/profil', - component: Profile, - props: true, - meta: { - authGuard: true, - } - }, + { + path: "*", + redirect: "/", + }, + { + path: '/', + component: Index, + }, + { + path: '/connexion', + component: Login, + meta: { + loginFilter: true + } + }, + { + path: '/inscription', + component: Register, + meta: { + loginFilter: true + } + }, + { + path: '/sorts', + component: Spells, + }, + { + path: '/sorts/:id', + component: SpellSingle, + props: true, + }, + { + path: '/ecoles', + component: Schools, + }, + { + path: '/ecoles/:id', + component: SchoolSingle, + props: true, + }, + { + path: '/ages', + component: Timeline, + }, + { + path: '/profil', + component: Profile, + props: true, + meta: { + logoutFilter: true, + } + }, ] const router = new VueRouter({ - mode: 'history', - routes, - linkActiveClass: "", - linkExactActiveClass: "active", + mode: 'history', + routes, + linkActiveClass: "", + linkExactActiveClass: "active", }) router.beforeEach((to, from, next) => { - if (to.matched.some(record => record.meta.authGuard)) { - if (Vue.$cookies.get('U_') == null) { - next({ - path: '/connexion', - params: { nextUrl: to.fullPath }, - }) - } else { - next() - } - } else { - next() + if (to.matched.some(record => record.meta.loginFilter)) { + if (store.getters.getUserToken) { + next({ + path: '/', + }); } + next(); + } else if (to.matched.some(record => record.meta.logoutFilter)) { + if (!store.getters.getUserToken) { + next({ + path: '/connexion', + }); + } + next(); + } + next(); }) export default router; \ No newline at end of file