modal implementation #12

Merged
vincent merged 10 commits from dev into master 2019-05-11 14:21:09 +00:00
3 changed files with 8 additions and 84 deletions
Showing only changes of commit 483124e57c - Show all commits

View File

@ -73,17 +73,23 @@
</div> </div>
</div> </div>
</div> </div>
<modalLogin v-bind:class="{'is-active': showModalLogin}" @close="showModalLogin = false"/>
</div> </div>
</template> </template>
<script> <script>
import { putparsechaine } from '../api'; import { putparsechaine } from '../api';
import modalLogin from './modalLogin'
export default { export default {
name: 'chainetv', name: 'chainetv',
components: {
modalLogin
},
data() { data() {
return { return {
chaine: '', chaine: '',
showModalLogin: false,
}; };
}, },
methods: { methods: {
@ -110,7 +116,7 @@ export default {
}, },
parsechaine() { parsechaine() {
if (!this.$store.getters.isAuthenticated) { if (!this.$store.getters.isAuthenticated) {
this.$router.push('/login'); this.showModalLogin=true;
} else { } else {
return putparsechaine(this.$store.state.jwt.token) return putparsechaine(this.$store.state.jwt.token)
.then((res) => { .then((res) => {

View File

@ -1,76 +0,0 @@
<!-- components/Login.vue -->
<template>
<div>
<section class="hero is-success">
<div class="hero-body">
<div class="container has-text-centered">
<h2 class="title">Login </h2>
<p class="subtitle error-msg">{{ errorMsg }}</p>
</div>
</div>
</section>
<section class="section">
<div class="container">
<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">
<a class="button is-large is-success" @click="authenticate">Login</a>
</div>
</div>
</section>
</div>
</template>
<script>
import { EventBus } from '../utils';
export default {
data() {
return {
name: '',
password: '',
errorMsg: '',
};
},
methods: {
authenticate() {
this.$store.dispatch('login', { name: this.name, password: this.password })
.then(() => {
if (this.$store.getters.isAuthenticated) {
this.$router.push('/');
}
},
);
},
register() {
this.$store.dispatch('register', { name: this.name, password: this.password })
.then(() => this.$router.push('/'));
},
},
mounted() {
EventBus.$on('failedRegistering', (msg) => {
this.errorMsg = msg;
});
EventBus.$on('failedAuthentication', (msg) => {
this.errorMsg = msg;
});
},
beforeDestroy() {
EventBus.$off('failedRegistering');
EventBus.$off('failedAuthentication');
},
};
</script>

View File

@ -2,7 +2,6 @@ import Vue from 'vue';
import Router from 'vue-router'; import Router from 'vue-router';
import ping from '@/components/ping'; import ping from '@/components/ping';
import chainetv from '@/components/chainetv'; import chainetv from '@/components/chainetv';
import login from '@/components/login';
import store from '@/store'; import store from '@/store';
Vue.use(Router); Vue.use(Router);
@ -13,18 +12,13 @@ export default new Router({
name: 'chaineTV', name: 'chaineTV',
component: chainetv, component: chainetv,
}, },
{
path: '/login',
name: 'Login',
component: login,
},
{ {
path: '/ping', path: '/ping',
name: 'ping', name: 'ping',
component: ping, component: ping,
beforeEnter(to, from, next) { beforeEnter(to, from, next) {
if (!store.getters.isAuthenticated) { if (!store.getters.isAuthenticated) {
next('/login'); next('/');
} else { } else {
next(); next();
} }