- Fixed my revert hahaha :)
This commit is contained in:
@@ -116,7 +116,8 @@ class UserRepository {
|
|||||||
.then(newUser => {
|
.then(newUser => {
|
||||||
resolve({
|
resolve({
|
||||||
"message": "Account successfully created !",
|
"message": "Account successfully created !",
|
||||||
"user": newUser,
|
"code": 201,
|
||||||
|
"token": newUser.uuid,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
@@ -146,11 +147,13 @@ class UserRepository {
|
|||||||
if (match) {
|
if (match) {
|
||||||
resolve({
|
resolve({
|
||||||
"message": "User successfully logged in !",
|
"message": "User successfully logged in !",
|
||||||
"user": fetchedUser,
|
"code": 200,
|
||||||
|
"token": fetchedUser.uuid,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
reject({
|
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)
|
this.getOneByEmail(mail, false)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
reject({
|
reject({
|
||||||
"message": "L'email est déjà utilisé par un autre utilisateur.",
|
"message": "This email is already linked to an account.",
|
||||||
"code": 403
|
"code": 403
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
<router-link :to="link.url" class="nav-link">{{ link.text }}</router-link>
|
<router-link :to="link.url" class="nav-link">{{ link.text }}</router-link>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div v-if="user" class="navbar-nav">
|
<div v-if="user_token" class="navbar-nav">
|
||||||
<router-link :to="'/profil'" class="nav-link">{{ user.name }}</router-link>
|
<router-link :to="'/profil'" class="nav-link">{{ user_token }}</router-link>
|
||||||
<div @click="logoutUser()" class="nav-link">Deconnexion</div>
|
<div @click="logoutUser()" class="nav-link">Deconnexion</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="navbar-nav">
|
<div v-else class="navbar-nav">
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
|
||||||
|
export default {
|
||||||
name: 'navbar',
|
name: 'navbar',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -43,18 +44,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
user() {
|
user_token() {
|
||||||
return this.$store.state.user
|
return this.$store.getters.getUserToken
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
logoutUser() {
|
logoutUser() {
|
||||||
this.$cookies.remove('U_')
|
this.$store.dispatch('user_logout');
|
||||||
this.$store.commit('logout')
|
this.$router.push('/');
|
||||||
this.$router.push('/')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss"></style>
|
<style lang="scss"></style>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
// Core
|
// Core
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
|
||||||
import VueRouter from 'vue-router'
|
import VueRouter from 'vue-router'
|
||||||
import App from './app.vue'
|
import App from './app.vue'
|
||||||
|
|
||||||
|
import store from './store'
|
||||||
|
|
||||||
import Globals from './global-components.js'
|
import Globals from './global-components.js'
|
||||||
Globals.forEach(component => {
|
Globals.forEach(component => {
|
||||||
Vue.component(component.name, component)
|
Vue.component(component.name, component)
|
||||||
@@ -55,38 +56,6 @@ Vue.filter('truncate', filter)
|
|||||||
import router from './routes'
|
import router from './routes'
|
||||||
Vue.use(VueRouter)
|
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
|
// Mount Vue
|
||||||
const app = new Vue({
|
const app = new Vue({
|
||||||
render: h => h(App),
|
render: h => h(App),
|
||||||
|
|||||||
@@ -34,9 +34,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// API
|
|
||||||
import { RepositoryFactory } from "~/api/repositories"
|
|
||||||
const Users = RepositoryFactory.get('users')
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'login-page',
|
name: 'login-page',
|
||||||
@@ -52,27 +49,25 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async logUser(e) {
|
async logUser(e) {
|
||||||
e.preventDefault()
|
|
||||||
|
|
||||||
Users.login({
|
let userInput = {
|
||||||
"mail": this.email,
|
"mail": this.email,
|
||||||
"password": this.password
|
"password": this.password
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$store.dispatch('user_login', userInput)
|
||||||
|
.then(() => {
|
||||||
|
this.$router.push('/profil');
|
||||||
})
|
})
|
||||||
.then(v => {
|
|
||||||
let user = v.data.user
|
e.preventDefault();
|
||||||
this.$cookies.set("U_", user, 60 * 60 * 24 * 30)
|
|
||||||
this.$store.commit('loginSucceed', user)
|
|
||||||
this.$router.push('/profil')
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.$store.commit('loginFailed')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
||||||
section {
|
section {
|
||||||
min-height: calc(100vh - 56px);
|
min-height: calc(100vh - 56px);
|
||||||
main {
|
main {
|
||||||
@@ -84,9 +79,15 @@ section {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 600px) {
|
@media only screen and (max-width: 600px) {
|
||||||
|
section {
|
||||||
|
main {
|
||||||
.title {
|
.title {
|
||||||
font-size: 3.5rem;
|
font-size: 3.5rem;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="container-fluid p-4" id="spell-container">
|
<div class="container-fluid p-4" id="spell-container">
|
||||||
<div class="display-3 font-display mb-3">
|
<div class="display-3 font-display mb-3">
|
||||||
<span class="username">{{ user.name }}</span>
|
<span class="username">{{ user_token }}</span>
|
||||||
<span v-if="user.verified" class="verified"><i class="mad">check_circle</i></span>
|
<!-- <span v-if="user.verified" class="verified"><i class="mad">check_circle</i></span> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -11,14 +11,15 @@
|
|||||||
export default {
|
export default {
|
||||||
name: 'profile-page',
|
name: 'profile-page',
|
||||||
computed: {
|
computed: {
|
||||||
user() {
|
user_token() {
|
||||||
return this.$store.state.user
|
return this.$store.getters.getUserToken
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 5rem;
|
font-size: 5rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
@@ -28,4 +29,5 @@ export default {
|
|||||||
font-size: 3.5rem;
|
font-size: 3.5rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import VueRouter from 'vue-router'
|
import VueRouter from 'vue-router'
|
||||||
|
import store from './store'
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
import Index from "~/pages/index-page"
|
import Index from "~/pages/index-page"
|
||||||
@@ -30,14 +30,14 @@ const routes = [
|
|||||||
path: '/connexion',
|
path: '/connexion',
|
||||||
component: Login,
|
component: Login,
|
||||||
meta: {
|
meta: {
|
||||||
antiAuthGuard: true
|
loginFilter: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/inscription',
|
path: '/inscription',
|
||||||
component: Register,
|
component: Register,
|
||||||
meta: {
|
meta: {
|
||||||
antiAuthGuard: true
|
loginFilter: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -67,7 +67,7 @@ const routes = [
|
|||||||
component: Profile,
|
component: Profile,
|
||||||
props: true,
|
props: true,
|
||||||
meta: {
|
meta: {
|
||||||
authGuard: true,
|
logoutFilter: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -80,18 +80,22 @@ const router = new VueRouter({
|
|||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
if (to.matched.some(record => record.meta.authGuard)) {
|
if (to.matched.some(record => record.meta.loginFilter)) {
|
||||||
if (Vue.$cookies.get('U_') == null) {
|
if (store.getters.getUserToken) {
|
||||||
|
next({
|
||||||
|
path: '/',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
} else if (to.matched.some(record => record.meta.logoutFilter)) {
|
||||||
|
if (!store.getters.getUserToken) {
|
||||||
next({
|
next({
|
||||||
path: '/connexion',
|
path: '/connexion',
|
||||||
params: { nextUrl: to.fullPath },
|
});
|
||||||
})
|
|
||||||
} else {
|
|
||||||
next()
|
|
||||||
}
|
}
|
||||||
} else {
|
next();
|
||||||
next()
|
|
||||||
}
|
}
|
||||||
|
next();
|
||||||
})
|
})
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
Reference in New Issue
Block a user