happyDomain/htdocs/src/App.vue

134 lines
4.3 KiB
Vue
Raw Normal View History

2019-09-09 15:03:10 +00:00
<template>
<div id="app">
2020-04-28 09:10:44 +00:00
<b-navbar style="border-bottom: 3px solid #aee64e; box-shadow: 0 0 12px 0 #08334833; z-index:2">
2020-04-20 14:29:09 +00:00
<b-navbar-brand class="navbar-brand" to="/" style="font-family: 'Fortheenas01';font-weight:bold;">
happy<span style="font-family: 'Fortheenas01 Bold';margin-left:.1em;">DNS</span>
2019-09-09 15:03:10 +00:00
</b-navbar-brand>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#adminMenu" aria-controls="adminMenu" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<b-navbar-toggle target="nav-collapse"></b-navbar-toggle>
<b-navbar-nav class="ml-auto">
2019-09-10 18:08:22 +00:00
<b-nav-item-dropdown right v-if="loggedUser">
2020-03-08 18:26:45 +00:00
<template slot="button-content"><div class="btn btn-sm btn-secondary"><b-icon icon="person" aria-hidden="true"></b-icon> {{ loggedUser.email }}</div></template>
2020-04-27 10:16:24 +00:00
<b-dropdown-item to="/domains/">My domains</b-dropdown-item>
2020-04-27 17:38:00 +00:00
<b-dropdown-item to="/sources/">My sources</b-dropdown-item>
2020-04-28 10:57:03 +00:00
<b-dropdown-divider></b-dropdown-divider>
<b-dropdown-item to="/tools/client">DNS client</b-dropdown-item>
2020-03-08 18:26:45 +00:00
<b-dropdown-divider></b-dropdown-divider>
2019-09-10 18:08:22 +00:00
<b-dropdown-item @click="logout()">Logout</b-dropdown-item>
2019-09-09 15:03:10 +00:00
</b-nav-item-dropdown>
2020-03-08 18:26:45 +00:00
<b-button v-if="!loggedUser" variant="outline-success" @click="signup()"><b-icon icon="person-fill" aria-hidden="true"></b-icon> Sign up</b-button>
<b-button v-if="!loggedUser" variant="primary" class="ml-2" @click="signin()"><b-icon icon="person-fill" aria-hidden="true"></b-icon> Sign in</b-button>
2019-09-09 15:03:10 +00:00
</b-navbar-nav>
</b-navbar>
<router-view/>
2020-03-08 18:26:45 +00:00
2020-03-08 18:34:49 +00:00
<b-toaster name="b-toaster-content-right" style="position: fixed; top: 70px; right: 0; z-index: 10; min-width: 30vw;"></b-toaster>
2020-04-28 09:10:44 +00:00
<div class="pt-3 pb-5 bg-dark text-light" style="border-top: 3px solid #aee64e; box-shadow: 0 0 12px 0 #08334833; z-index: 2">
2020-03-08 18:26:45 +00:00
<b-container>
<b-row>
<b-col md="4">
2020-04-20 14:29:09 +00:00
&copy; <span style="font-family: 'Fortheenas01';font-weight:bold;">happy<span style="font-family: 'Fortheenas01 Bold';margin-left:.1em;">DNS</span></span> 2019-2020 All rights reserved
2020-03-08 18:26:45 +00:00
</b-col>
<b-col md="4">
</b-col>
<b-col md="4">
</b-col>
</b-row>
</b-container>
</div>
2019-09-09 15:03:10 +00:00
</div>
</template>
2019-09-10 18:08:22 +00:00
<script>
import axios from 'axios'
function updateSession (t) {
if (sessionStorage.token !== undefined) {
t.session = sessionStorage.token
2020-04-17 15:04:11 +00:00
axios.defaults.headers.common.Authorization = 'Bearer '.concat(sessionStorage.token)
axios.get('/api/users/auth')
2019-09-10 18:08:22 +00:00
.then(
(response) => {
t.loggedUser = response.data
},
(error) => {
2020-04-04 07:50:33 +00:00
t.$bvToast.toast(
2020-04-17 15:04:11 +00:00
'Invalid session, your have been logged out: ' + error.response.data.errmsg + '. Please login again.', {
2020-04-04 07:50:33 +00:00
title: 'Authentication timeout',
autoHideDelay: 5000,
variant: 'danger',
toaster: 'b-toaster-content-right'
}
)
2019-09-10 18:08:22 +00:00
t.session = null
t.loggedUser = null
2020-03-08 18:26:45 +00:00
delete sessionStorage.token
2020-04-04 07:50:33 +00:00
t.$router.replace('/login')
2019-09-10 18:08:22 +00:00
}
)
}
}
export default {
data: function () {
return {
loggedUser: null,
session: null
}
},
mounted () {
updateSession(this)
2020-03-08 18:26:45 +00:00
this.$on('login', this.login)
2019-09-10 18:08:22 +00:00
},
methods: {
signin () {
this.$router.push('/login')
},
signup () {
this.$router.push('/join')
},
logout () {
sessionStorage.token = undefined
updateSession(this)
this.$router.push('/')
2019-09-10 18:08:22 +00:00
},
login (email, password) {
axios
.post('/api/users/auth', {
2020-04-17 15:04:11 +00:00
email: email,
password: password
2019-09-10 18:08:22 +00:00
})
.then(
(response) => {
if (response.data.id_session) {
sessionStorage.token = response.data.id_session
}
updateSession(this)
this.$router.push('/')
},
(error) => {
2020-03-08 18:34:49 +00:00
this.$bvToast.toast(
2020-04-17 15:04:11 +00:00
'An error occurs when trying to login: ' + error.response.data.errmsg, {
2020-03-08 18:34:49 +00:00
title: 'Login error',
autoHideDelay: 5000,
toaster: 'b-toaster-content-right'
}
)
2019-09-10 18:08:22 +00:00
}
)
}
}
}
</script>