add modal windows revues struct login

This commit is contained in:
vincent 2019-05-10 13:55:36 +02:00
parent 316cb4d375
commit d5d869c738
4 changed files with 66 additions and 45 deletions

View File

@ -74,28 +74,34 @@
</div> </div>
</div> </div>
<modalLogin v-bind:class="{'is-active': showModalLogin}" @close="showModalLogin = false"/> <modalLogin v-bind:class="{'is-active': showModalLogin}" @close="showModalLogin = false"/>
<modal v-bind:class="{'is-active': showModal}" @close="showModal = false">{{modalmessage}}</modal>
</div> </div>
</template> </template>
<script> <script>
import { putparsechaine } from '../api'; import { putparsechaine } from '../api';
import modalLogin from './modalLogin' import modalLogin from './modalLogin'
import modal from './modal'
export default { export default {
name: 'chainetv', name: 'chainetv',
components: { components: {
modalLogin modalLogin,
modal,
}, },
data() { data() {
return { return {
chaine: '', chaine: '',
showModalLogin: false, showModalLogin: false,
showModal: false,
modalmessage:''
}; };
}, },
methods: { methods: {
checkchaine() { checkchaine() {
if (this.chaine === '') { if (this.chaine === '') {
alert('rentrer un numéro'); this.modalmessage='rentrer un numéro de chaine';
this.showModal=true;
return; return;
} }
this.$store.state.arrayresultchaines = []; this.$store.state.arrayresultchaines = [];
@ -121,13 +127,15 @@ export default {
return putparsechaine(this.$store.state.jwt.token) return putparsechaine(this.$store.state.jwt.token)
.then((res) => { .then((res) => {
if (res.data === 'OK') { if (res.data === 'OK') {
alert('update database OK'); this.modalmessage='update database OK';
this.showModal=true;
} }
}) })
.catch((error) => { .catch((error) => {
// eslint-disable-next-line // eslint-disable-next-line
if (error.response) { if (error.response) {
alert(error.response.data.message); this.modalmessage=error.response.data.message;
this.showModal=true;
} else { } else {
console.error(error); console.error(error);
} }

View File

@ -0,0 +1,16 @@
<template>
<div class="modal">
<div class="modal-background"></div>
<button class="modal-close is-large" aria-label="close" @click="$emit('close')"></button>
<div class="modal-content box">
<slot></slot>
</div>
</div>
</template>
<script>
export default {
};
</script>

View File

@ -2,77 +2,74 @@
<template> <template>
<div class="modal"> <div class="modal">
<div class="modal-background"></div> <div class="modal-background"></div>
<button class="modal-close is-large" aria-label="close"></button> <button class="modal-close is-large" aria-label="close" @click="$emit('close')"></button>
<div class="modal-content"> <div class="modal-content box">
<section class="hero is-success"> <div class="section is-success">
<div class="hero-body"> <div class="has-text-centered">
<div class="container has-text-centered"> <h2 class="title">Login</h2>
<h2 class="title">Login </h2>
<p class="subtitle error-msg">{{ errorMsg }}</p> <p class="subtitle error-msg">{{ errorMsg }}</p>
</div> </div>
</div> </div>
</section> <section class="section">
<section class="section"> <div class="field">
<div class="container"> <label class="label" for="name">Name:</label>
<div class="field">
<label class="label is-large" for="name">Name:</label>
<div class="control">
<input type="name" class="input is-large" id="email" v-model="name">
</div>
</div>
<div class="field">
<label class="label is-large" for="password">Password:</label>
<div class="control">
<input type="password" class="input is-large" id="password" v-model="password">
</div>
</div>
<div class="control"> <div class="control">
<a class="button is-large is-success" @click="authenticate">Login</a> <input type="name" class="input" id="email" v-model="name">
</div> </div>
</div> </div>
</section> <div class="field">
<label class="label" for="password">Password:</label>
<div class="control">
<input type="password" class="input" id="password" v-model="password">
</div>
</div>
<div class="control">
<a class="button is-success is-large" @click="authenticate">Login</a>
</div>
</section>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { EventBus } from '../utils'; import { EventBus } from "../utils";
export default { export default {
data() { data() {
return { return {
name: '', name: "",
password: '', password: "",
errorMsg: '', errorMsg: ""
}; };
}, },
methods: { methods: {
authenticate() { authenticate() {
this.$store.dispatch('login', { name: this.name, password: this.password }) this.$store
.dispatch("login", { name: this.name, password: this.password })
.then(() => { .then(() => {
if (this.$store.getters.isAuthenticated) { if (this.$store.getters.isAuthenticated) {
this.$router.push('/'); this.$emit("close");
} }
}, });
);
}, },
register() { register() {
this.$store.dispatch('register', { name: this.name, password: this.password }) this.$store
.then(() => this.$router.push('/')); .dispatch("register", { name: this.name, password: this.password })
}, .then(() => this.$router.push("/"));
}
}, },
mounted() { mounted() {
EventBus.$on('failedRegistering', (msg) => { EventBus.$on("failedRegistering", msg => {
this.errorMsg = msg; this.errorMsg = msg;
}); });
EventBus.$on('failedAuthentication', (msg) => { EventBus.$on("failedAuthentication", msg => {
this.errorMsg = msg; this.errorMsg = msg;
}); });
}, },
beforeDestroy() { beforeDestroy() {
EventBus.$off('failedRegistering'); EventBus.$off("failedRegistering");
EventBus.$off('failedAuthentication'); EventBus.$off("failedAuthentication");
}, }
}; };
</script> </script>

View File

@ -18,7 +18,7 @@ export default new Router({
component: ping, component: ping,
beforeEnter(to, from, next) { beforeEnter(to, from, next) {
if (!store.getters.isAuthenticated) { if (!store.getters.isAuthenticated) {
next('/'); next('/')
} else { } else {
next(); next();
} }