Merge branch 'develop/vue/store' into dev
This commit is contained in:
@@ -31,7 +31,7 @@ class UserRepository {
|
||||
})
|
||||
.catch(() => {
|
||||
reject({
|
||||
"message": "Database error, couldn't get all users.",
|
||||
"message": "Erreur de base de données, les utilisateurs n'ont pas pu être récupérés.",
|
||||
"code": 500
|
||||
})
|
||||
})
|
||||
@@ -48,7 +48,7 @@ class UserRepository {
|
||||
})
|
||||
.catch(err => {
|
||||
reject({
|
||||
"message": "User with this UUID was not found.",
|
||||
"message": "L'utilisateur avec cet UUID n'a pas été trouvé.",
|
||||
"code": 404
|
||||
})
|
||||
})
|
||||
@@ -65,7 +65,7 @@ class UserRepository {
|
||||
})
|
||||
.catch(() => {
|
||||
reject({
|
||||
"message": "User with this email was not found.",
|
||||
"message": "L'utilisateur avec cet email n'a pas été trouvé.",
|
||||
"code": 404
|
||||
})
|
||||
})
|
||||
@@ -77,17 +77,17 @@ class UserRepository {
|
||||
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
||||
if (isEmptyObject(u)) {
|
||||
reject({
|
||||
"message": "Request body cannot be empty.",
|
||||
"message": "Le corps de requête ne peut être vide.",
|
||||
"code": 403
|
||||
})
|
||||
} else if (!v.validate(u, UserValidation).valid) {
|
||||
reject({
|
||||
"message": "Schema is not valid - " + v.validate(u, UserValidation).errors,
|
||||
"message": "Structure de la requête invalide - " + v.validate(u, UserValidation).errors,
|
||||
"code": 403
|
||||
})
|
||||
} else if (isXSSAttempt(u.name) || isXSSAttempt(u.password) || isXSSAttempt(u.mail)) {
|
||||
reject({
|
||||
"message": "Injection attempt detected, aborting the request.",
|
||||
"message": "Essai d'injection détecté, avortement de la requête.",
|
||||
"code": 403
|
||||
})
|
||||
} else {
|
||||
@@ -115,13 +115,14 @@ class UserRepository {
|
||||
})
|
||||
.then(newUser => {
|
||||
resolve({
|
||||
"message": "Account successfully created !",
|
||||
"message": `Compte utilisateur #${newUser.id} créé avec succès.`,
|
||||
"code": 201,
|
||||
"user": newUser,
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
resolve({
|
||||
"message": "An error has occured while creating your account.",
|
||||
"message": "Une erreur s'est produite en créant votre compte. Veuillez réessayer ultérieurement ou contactez l'administrateur.",
|
||||
"code": 500,
|
||||
})
|
||||
})
|
||||
@@ -145,12 +146,14 @@ class UserRepository {
|
||||
|
||||
if (match) {
|
||||
resolve({
|
||||
"message": "User successfully logged in !",
|
||||
"message": `L'utilisateur #${fetchedUser.id} s'est connecté.`,
|
||||
"code": 200,
|
||||
"user": fetchedUser,
|
||||
})
|
||||
} else {
|
||||
reject({
|
||||
"message": "Les informations de connexion sont erronées.",
|
||||
"message": "Les informations de connexions sont erronées.",
|
||||
"code": 400,
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -163,17 +166,33 @@ class UserRepository {
|
||||
// Check if one user already has that email
|
||||
checkIfEmailAvailable(mail) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (!this.validateEmail(mail)) {
|
||||
reject({
|
||||
"message": "La requête n'est pas un email valide.",
|
||||
"code": 400,
|
||||
})
|
||||
}
|
||||
|
||||
this.getOneByEmail(mail, false)
|
||||
.then(() => {
|
||||
reject({
|
||||
"message": "L'email est déjà utilisé par un autre utilisateur.",
|
||||
"code": 403
|
||||
"message": "Cet email est déjà lié à un compte.",
|
||||
"code": 409
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
resolve(true)
|
||||
resolve({
|
||||
"message": "Cet email est disponible.",
|
||||
"code": 200
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
validateEmail(email) {
|
||||
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test(String(email).toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ const Users = new UserRepository();
|
||||
const getUsers = () => {
|
||||
return Users.getAll()
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
@@ -38,11 +37,10 @@ router.get('/', async (req, res) => {
|
||||
})
|
||||
|
||||
|
||||
// GET ONE FORM UUID ------------------
|
||||
// GET ONE FROM UUID ------------------
|
||||
const getUserByUUID = (uuid) => {
|
||||
return Users.getOneByUUID(uuid)
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
@@ -63,11 +61,34 @@ router.get('/:uuid/', async (req, res) => {
|
||||
})
|
||||
|
||||
|
||||
// CHECK IF MAIL IS AVAILABLE ------------------
|
||||
const checkIfEmailAvailable = (mail) => {
|
||||
return Users.checkIfEmailAvailable(mail)
|
||||
.catch(err => {
|
||||
throw err
|
||||
})
|
||||
}
|
||||
router.get('/available/:mail/', async (req, res) => {
|
||||
checkIfEmailAvailable(req.params.mail)
|
||||
.then(v => {
|
||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||
res.end(JSON.stringify(v))
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(err.code).send(JSON.stringify(
|
||||
{
|
||||
"error": err.message,
|
||||
"code": err.code
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// LOG A USER ------------------
|
||||
const logUser = (mail, password) => {
|
||||
return Users.logUser(mail, password)
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,12 @@ import api from './api'
|
||||
const resource = "/users"
|
||||
|
||||
export default {
|
||||
getOneFromUUID(uuid) {
|
||||
return api.get(`${resource}/${uuid}`,)
|
||||
},
|
||||
checkEmailAvailable(mail) {
|
||||
return api.get(`${resource}/available/${mail}`)
|
||||
},
|
||||
login(data) {
|
||||
return api.post(`${resource}/login`, data)
|
||||
},
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
|
||||
export default {
|
||||
name: 'navbar',
|
||||
data() {
|
||||
return {
|
||||
@@ -44,17 +45,17 @@
|
||||
},
|
||||
computed: {
|
||||
user() {
|
||||
return this.$store.state.user
|
||||
return this.$store.getters.getUserProfile
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
logoutUser() {
|
||||
this.$cookies.remove('U_')
|
||||
this.$store.commit('logout')
|
||||
this.$router.push('/')
|
||||
}
|
||||
this.$store.dispatch('user_logout');
|
||||
this.$router.push('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss"></style>
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
|
||||
<template v-slot:modal-footer="{ close }">
|
||||
<button type="button" class="btn btn-danger" data-dismiss="modal" @click="close()">Fermer</button>
|
||||
<!-- <input type="button" class="btn btn-success" value="Enregistrer comme nouveau" @click="cloneSpell()"> -->
|
||||
<input type="submit" class="btn btn-primary" value="Enregistrer" form="update-spell">
|
||||
</template>
|
||||
</b-modal>
|
||||
|
||||
@@ -90,7 +90,7 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
user() {
|
||||
return this.$store.state.user
|
||||
return this.$store.getters.getUserProfile
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -109,7 +109,8 @@ export default {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.spell-card {
|
||||
|
||||
.spell-card {
|
||||
footer {
|
||||
a {
|
||||
cursor: pointer;
|
||||
@@ -146,5 +147,6 @@ export default {
|
||||
@include colorschool(vocamancie,#247864);
|
||||
@include colorschool(somamancie,#976c67);
|
||||
@include colorschool(antimancie,#ad95c1);
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -1,17 +1,18 @@
|
||||
// Core
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import VueRouter from 'vue-router'
|
||||
import App from './app.vue'
|
||||
|
||||
// Environment
|
||||
require('dotenv').config()
|
||||
|
||||
import store from './store'
|
||||
|
||||
import Globals from './global-components.js'
|
||||
Globals.forEach(component => {
|
||||
Vue.component(component.name, component)
|
||||
});
|
||||
|
||||
// Environment
|
||||
require('dotenv').config()
|
||||
|
||||
// Cookies
|
||||
import VueCookies from 'vue-cookies'
|
||||
Vue.use(VueCookies)
|
||||
@@ -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),
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
export default {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
<template>
|
||||
<div class="container-fluid p-4" id="spell-container">
|
||||
<h1 class="display-3 font-display mb-3">Chronologie</h1>
|
||||
<timeline/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Timeline from '~/components/timeline/timeline'
|
||||
|
||||
export default {
|
||||
name: 'timeline-page',
|
||||
components: {
|
||||
'timeline': Timeline,
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
<section class="d-flex justify-content-center align-items-center">
|
||||
<main>
|
||||
<div class="title font-display mb-3">Connexion</div>
|
||||
|
||||
<form @submit="logUser">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Addresse mail</label>
|
||||
<input
|
||||
@@ -11,10 +13,26 @@
|
||||
type="email"
|
||||
id="email"
|
||||
class="form-control"
|
||||
:class="{
|
||||
'is-invalid': errors.email || errors.login,
|
||||
'is-valid': submitted && !errors.email }"
|
||||
placeholder="john.doe@gmail.com"
|
||||
autocomplete="email">
|
||||
<small class="form-text text-muted">Votre addresse mail nous servira principalement à vous identifier et à retrouver votre compte si vous oubliez vos informations de connexion.</small>
|
||||
|
||||
<small
|
||||
v-if="!errors.email"
|
||||
class="form-text text-muted"
|
||||
>
|
||||
Votre addresse mail nous servira principalement à vous identifier et à retrouver votre compte si vous oubliez vos informations de connexion.
|
||||
</small>
|
||||
<small
|
||||
v-if="errors.email"
|
||||
class="form-text text-danger"
|
||||
>
|
||||
{{ errors.email }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Mot de passe</label>
|
||||
<input
|
||||
@@ -22,11 +40,44 @@
|
||||
type="password"
|
||||
id="password"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.password || errors.login }"
|
||||
autocomplete="current-password">
|
||||
<small
|
||||
v-if="!errors.password"
|
||||
class="form-text text-muted"
|
||||
>
|
||||
Nous vous conseillons d'utiliser un mot de passe unique pour cette application seulement.
|
||||
</small>
|
||||
<small
|
||||
v-if="errors.password"
|
||||
class="form-text text-danger"
|
||||
>
|
||||
{{ errors.password }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
v-model="remember_me"
|
||||
id="remember-me"
|
||||
class="form-check-input">
|
||||
<label
|
||||
class="form-check-label"
|
||||
for="remember-me"
|
||||
>
|
||||
Rester connecté
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<small v-if="errors.login" class="text-danger">{{ errors.login }}</small>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Connexion</button>
|
||||
<router-link :to="'/inscription'" class="btn btn-dark">Inscription</router-link>
|
||||
<small class="form-text text-muted">Vous avez oublié votre mot de passe ? Cliquez-ici pour le changer !</small>
|
||||
<small class="form-text text-muted">Mot de passe oublié ? <a href="#">Vous pouvez le changer ici !</a></small>
|
||||
|
||||
</form>
|
||||
</main>
|
||||
</section>
|
||||
@@ -34,9 +85,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// API
|
||||
import { RepositoryFactory } from "~/api/repositories"
|
||||
const Users = RepositoryFactory.get('users')
|
||||
|
||||
export default {
|
||||
name: 'login-page',
|
||||
@@ -44,35 +92,65 @@ export default {
|
||||
return {
|
||||
email: "",
|
||||
password: "",
|
||||
remember_me: false,
|
||||
submitted: false,
|
||||
|
||||
errors: {
|
||||
login: ""
|
||||
email: "",
|
||||
password: "",
|
||||
login: "",
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async logUser(e) {
|
||||
e.preventDefault()
|
||||
e.preventDefault();
|
||||
|
||||
Users.login({
|
||||
// Resets old errors if any
|
||||
for (const o in this.errors) {
|
||||
this.errors[o] = ""
|
||||
}
|
||||
this.submitted = true;
|
||||
|
||||
let userInput = {
|
||||
"mail": this.email,
|
||||
"password": this.password
|
||||
})
|
||||
.then(v => {
|
||||
let user = v.data.user
|
||||
this.$cookies.set("U_", user, 60 * 60 * 24 * 30)
|
||||
this.$store.commit('loginSucceed', user)
|
||||
};
|
||||
|
||||
if (!userInput.mail) {
|
||||
this.errors.email = "Vous devez renseigner une addresse mail."
|
||||
}
|
||||
if (!userInput.password) {
|
||||
this.errors.password = "Vous devez renseigner un mot de passe."
|
||||
}
|
||||
|
||||
// Stops the method if any errors exist
|
||||
for (const o in this.errors) {
|
||||
if (this.errors[o] != "") {
|
||||
this.submitted = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.submitted) {
|
||||
this.$store.dispatch('user_login', userInput)
|
||||
.then(() => {
|
||||
this.$router.push('/profil')
|
||||
})
|
||||
.catch(() => {
|
||||
this.$store.commit('loginFailed')
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.status === 404) {
|
||||
this.errors.email = err.data.error;
|
||||
} else {
|
||||
this.errors.login = "Une erreur inconnue est survenue, rééssayez plus tard.";
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
section {
|
||||
min-height: calc(100vh - 56px);
|
||||
main {
|
||||
@@ -84,9 +162,15 @@ section {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
section {
|
||||
main {
|
||||
.title {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -1,24 +1,40 @@
|
||||
<template>
|
||||
<div class="container-fluid p-4" id="spell-container">
|
||||
<div class="display-3 font-display mb-3">
|
||||
<div
|
||||
v-if="user"
|
||||
class="container-fluid p-4"
|
||||
id="spell-container"
|
||||
>
|
||||
<h2 class="display-3 font-display mb-3">
|
||||
<span class="username">{{ user.name }}</span>
|
||||
<span v-if="user.verified" class="verified"><i class="mad">check_circle</i></span>
|
||||
</div>
|
||||
<span
|
||||
v-if="user.verified"
|
||||
class="verified"
|
||||
>
|
||||
<i class="mad">check_circle</i>
|
||||
</span>
|
||||
</h2>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'profile-page',
|
||||
computed: {
|
||||
user() {
|
||||
return this.$store.state.user
|
||||
data() {
|
||||
return {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
user() {
|
||||
return this.$store.getters.getUserProfile
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
.title {
|
||||
font-size: 5rem;
|
||||
font-weight: 700;
|
||||
@@ -28,4 +44,5 @@ export default {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -4,8 +4,9 @@
|
||||
<main>
|
||||
<div class="title font-display mb-3">Inscription</div>
|
||||
<form @submit="registerUser">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Pseudo</label>
|
||||
<label for="email">Nom d'utilisateur</label>
|
||||
<input
|
||||
v-model="name"
|
||||
:class="{
|
||||
@@ -16,11 +17,23 @@
|
||||
class="form-control"
|
||||
placeholder="John Doe"
|
||||
autocomplete="username">
|
||||
<small v-if="!errors.name" class="form-text text-muted">Vous pouvez changer votre pseudo à tout moment.</small>
|
||||
<small v-if="errors.name" class="text-danger">{{ errors.name }}</small>
|
||||
<small
|
||||
v-if="!errors.name"
|
||||
class="form-text text-muted"
|
||||
>
|
||||
Vous pouvez changer votre pseudo à tout moment.
|
||||
</small>
|
||||
|
||||
<small
|
||||
v-if="errors.name"
|
||||
class="form-text text-danger"
|
||||
>
|
||||
{{ errors.name }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Addresse mail</label>
|
||||
<label for="email">Adresse mail</label>
|
||||
<input
|
||||
v-model="email"
|
||||
:class="{
|
||||
@@ -31,9 +44,21 @@
|
||||
class="form-control"
|
||||
placeholder="john.doe@gmail.com"
|
||||
autocomplete="email">
|
||||
<small v-if="!errors.email" class="form-text text-muted">Votre addresse mail nous servira principalement à vous identifier et à retrouver votre compte si vous oubliez vos informations de connexion.</small>
|
||||
<small v-if="errors.email" class="text-danger">{{ errors.email }}</small>
|
||||
<small
|
||||
v-if="!errors.email"
|
||||
class="form-text text-muted"
|
||||
>
|
||||
Votre addresse mail nous servira principalement à vous identifier et à retrouver votre compte si vous oubliez vos informations de connexion.
|
||||
</small>
|
||||
|
||||
<small
|
||||
v-if="errors.email"
|
||||
class="form-text text-danger"
|
||||
>
|
||||
{{ errors.email }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Mot de passe</label>
|
||||
<input
|
||||
@@ -46,6 +71,7 @@
|
||||
class="form-control"
|
||||
autocomplete="password">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password_check">Confirmer le mot de passe</label>
|
||||
<input
|
||||
@@ -57,10 +83,31 @@
|
||||
id="password_check"
|
||||
class="form-control"
|
||||
autocomplete="password-verification">
|
||||
<small v-if="!errors.password && !errors.password_check" class="form-text text-muted">Votre mot de passe doit idéalement contenir des symboles ainsi que des lettres et des chiffres.</small>
|
||||
<small v-if="errors.password" class="text-danger">{{ errors.password }}</small>
|
||||
<small v-if="errors.password_check" class="text-danger">{{ errors.password_check }}</small>
|
||||
<small
|
||||
v-if="!errors.password && !errors.password_check"
|
||||
class="form-text text-muted"
|
||||
>
|
||||
Votre mot de passe doit idéalement contenir des symboles ainsi que des lettres et des chiffres.
|
||||
</small>
|
||||
|
||||
<small
|
||||
v-if="errors.password"
|
||||
class="form-text text-danger"
|
||||
>
|
||||
{{ errors.password }}
|
||||
</small>
|
||||
<small
|
||||
v-if="errors.password_check"
|
||||
class="form-text text-danger"
|
||||
>
|
||||
{{ errors.password_check }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<small v-if="errors.register" class="text-danger">{{ errors.register }}</small>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-dark">Inscription</button>
|
||||
</form>
|
||||
</main>
|
||||
@@ -69,10 +116,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// API
|
||||
import { RepositoryFactory } from "~/api/repositories"
|
||||
const Users = RepositoryFactory.get('users')
|
||||
|
||||
export default {
|
||||
name: 'register-page',
|
||||
data() {
|
||||
@@ -87,55 +130,62 @@ export default {
|
||||
email: "",
|
||||
password: "",
|
||||
password_check: "",
|
||||
register: "",
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async registerUser(e) {
|
||||
e.preventDefault()
|
||||
e.preventDefault();
|
||||
|
||||
// Resets old errors if any
|
||||
for (const o in this.errors) {
|
||||
this.errors[o] = ""
|
||||
}
|
||||
this.submitted = true
|
||||
this.submitted = true;
|
||||
|
||||
if (!this.name) {
|
||||
let userInput = {
|
||||
"name": this.name,
|
||||
"mail": this.email,
|
||||
"password": this.password
|
||||
}
|
||||
|
||||
if (!userInput.name) {
|
||||
this.errors.name = "Vous devez renseigner un pseudonyme."
|
||||
}
|
||||
if (!this.email) {
|
||||
|
||||
if (!userInput.mail) {
|
||||
this.errors.email = "Vous devez renseigner une addresse mail."
|
||||
}
|
||||
if (!this.password) {
|
||||
|
||||
if (!userInput.password) {
|
||||
this.errors.password = "Vous devez renseigner un mot de passe."
|
||||
}
|
||||
if ((this.password.localeCompare(this.password_check)) != 0) {
|
||||
|
||||
if ((userInput.password.localeCompare(this.password_check)) != 0) {
|
||||
this.errors.password_check = "Les mots de passe ne correspondent pas."
|
||||
}
|
||||
|
||||
// Stops the method if any errors exist
|
||||
for (const o in this.errors) {
|
||||
if (this.errors[o]) {
|
||||
return true
|
||||
if (this.errors[o] != "") {
|
||||
this.submitted = false;
|
||||
}
|
||||
}
|
||||
|
||||
Users.register({
|
||||
"name": this.name,
|
||||
"mail": this.email,
|
||||
"password": this.password
|
||||
})
|
||||
.then(v => {
|
||||
let user = v.data.user
|
||||
this.$cookies.set("U_", user, 60 * 60 * 24 * 30)
|
||||
this.$store.commit('registerSucceed', user)
|
||||
this.$router.push('/profil')
|
||||
if (this.submitted) {
|
||||
this.$store.dispatch('user_register', userInput)
|
||||
.then(() => {
|
||||
this.$router.push('/');
|
||||
})
|
||||
.catch(err => {
|
||||
let error = err.response.data.error
|
||||
this.errors.email = error
|
||||
this.$store.commit('registerFail')
|
||||
})
|
||||
if (err.status === 409) {
|
||||
this.errors.email = err.data.error;
|
||||
} else {
|
||||
this.errors.register = "Une erreur inconnue est survenue, rééssayez plus tard.";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
|
||||
// import store from './store'
|
||||
|
||||
// Pages
|
||||
import Index from "~/pages/index-page"
|
||||
|
||||
@@ -30,14 +31,14 @@ const routes = [
|
||||
path: '/connexion',
|
||||
component: Login,
|
||||
meta: {
|
||||
antiAuthGuard: true
|
||||
loginFilter: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/inscription',
|
||||
component: Register,
|
||||
meta: {
|
||||
antiAuthGuard: true
|
||||
loginFilter: true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -67,7 +68,7 @@ const routes = [
|
||||
component: Profile,
|
||||
props: true,
|
||||
meta: {
|
||||
authGuard: true,
|
||||
logoutFilter: true,
|
||||
}
|
||||
},
|
||||
]
|
||||
@@ -79,19 +80,23 @@ const router = new VueRouter({
|
||||
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()
|
||||
}
|
||||
})
|
||||
// router.beforeEach((to, from, next) => {
|
||||
// if (to.matched.some(record => record.meta.loginFilter)) {
|
||||
// if (store.getters.getUserProfile) {
|
||||
// next({
|
||||
// path: '/',
|
||||
// });
|
||||
// }
|
||||
// next();
|
||||
// } else if (to.matched.some(record => record.meta.logoutFilter)) {
|
||||
// if (!store.getters.getUserProfile) {
|
||||
// next({
|
||||
// path: '/connexion',
|
||||
// });
|
||||
// }
|
||||
// next();
|
||||
// }
|
||||
// next();
|
||||
// })
|
||||
|
||||
export default router;
|
||||
19
client/src/store/index.js
Normal file
19
client/src/store/index.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
|
||||
import VueCookies from 'vue-cookies';
|
||||
Vue.use(VueCookies);
|
||||
Vue.$cookies.config('30d','','');
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
import user from './modules/user.store';
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
user
|
||||
},
|
||||
strict: debug
|
||||
});
|
||||
23
client/src/store/modules/spell.store.js
Normal file
23
client/src/store/modules/spell.store.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const state = {
|
||||
|
||||
}
|
||||
|
||||
const getters = {
|
||||
|
||||
}
|
||||
|
||||
const actions = {
|
||||
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations,
|
||||
}
|
||||
88
client/src/store/modules/user.store.js
Normal file
88
client/src/store/modules/user.store.js
Normal file
@@ -0,0 +1,88 @@
|
||||
// import cookie from 'vue-cookies';
|
||||
|
||||
// API
|
||||
import { RepositoryFactory } from "~/api/repositories";
|
||||
const Users = RepositoryFactory.get('users');
|
||||
|
||||
export const namespaced = true;
|
||||
|
||||
const state = {
|
||||
status: {
|
||||
logged: false,
|
||||
profile: null,
|
||||
}
|
||||
};
|
||||
|
||||
const getters = {
|
||||
|
||||
getUserProfile: state => {
|
||||
if (state.status.logged) {
|
||||
return state.status.profile
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
loginUser(state, user) {
|
||||
state.status.profile = user;
|
||||
state.status.logged = true;
|
||||
},
|
||||
|
||||
logoutUser(state) {
|
||||
state.status.profile = null;
|
||||
state.status.logged = false;
|
||||
},
|
||||
|
||||
registerUser() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const actions = {
|
||||
user_login ({ commit }, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
Users.login(data)
|
||||
.then(v => {
|
||||
let user = v.data.user;
|
||||
// cookie.set('user_token', user.uuid);
|
||||
commit('loginUser', user);
|
||||
resolve(user);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err.response);
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
user_logout ({ commit }) {
|
||||
// cookie.remove('user_token');
|
||||
commit('logoutUser');
|
||||
},
|
||||
|
||||
user_register ({ commit }, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
Users.register(data)
|
||||
.then(() => {
|
||||
commit('registerUser');
|
||||
resolve();
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err.response);
|
||||
});
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
// Check if a cookie with user token exists
|
||||
// if (cookie.get('user_token')) {
|
||||
// mutations.loginUser(state, cookie.get('user_token'));
|
||||
// }
|
||||
|
||||
export default {
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations,
|
||||
};
|
||||
Reference in New Issue
Block a user