happyDomain/htdocs/src/App.vue

211 lines
6.9 KiB
Vue
Raw Normal View History

2020-05-04 14:58:02 +00:00
<!--
Copyright or © or Copr. happyDNS (2020)
contact@happydns.org
This software is a computer program whose purpose is to provide a modern
interface to interact with DNS systems.
This software is governed by the CeCILL license under French law and abiding
by the rules of distribution of free software. You can use, modify and/or
redistribute the software under the terms of the CeCILL license as
circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy, modify
and redistribute granted by the license, users are provided only with a
limited warranty and the software's author, the holder of the economic
rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated with
loading, using, modifying and/or developing or reproducing the software by
the user in light of its specific status of free software, that may mean
that it is complicated to manipulate, and that also therefore means that it
is reserved for developers and experienced professionals having in-depth
computer knowledge. Users are therefore encouraged to load and test the
software's suitability as regards their requirements in conditions enabling
the security of their systems and/or data to be ensured and, more generally,
to use and operate it in the same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
-->
2019-09-09 15:03:10 +00:00
<template>
2020-05-07 11:18:04 +00:00
<div id="app">
<b-navbar :class="loggedUser?'p-0':''">
<b-container>
<b-navbar-brand class="navbar-brand" to="/">
<h-logo height="25" />
2020-05-07 11:18:04 +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" />
</button>
<b-navbar-toggle target="nav-collapse" />
<b-navbar-nav class="ml-auto">
<b-nav-item-dropdown v-if="loggedUser" right>
<template slot="button-content">
<b-button size="sm" variant="dark">
<b-icon icon="person" aria-hidden="true" /> {{ loggedUser.email }}
</b-button>
</template>
<b-dropdown-item to="/domains/">
My domains
</b-dropdown-item>
<b-dropdown-item to="/sources/">
My sources
</b-dropdown-item>
<b-dropdown-divider />
<b-dropdown-item to="/tools/client">
DNS client
</b-dropdown-item>
<b-dropdown-divider />
<b-dropdown-item @click="logout()">
Logout
</b-dropdown-item>
</b-nav-item-dropdown>
<b-button v-if="!loggedUser" variant="outline-dark" to="/join">
<b-icon icon="person-plus-fill" aria-hidden="true" /> Sign up
</b-button>
<b-button v-if="!loggedUser" variant="primary" class="ml-2" to="/login">
<b-icon icon="person-check" aria-hidden="true" /> Sign in
</b-button>
</b-navbar-nav>
</b-container>
</b-navbar>
<router-view style="min-height: 80vh" />
2020-05-07 11:18:04 +00:00
2020-07-07 15:09:30 +00:00
<b-toaster name="b-toaster-content-right" style="position: fixed; top: 70px; right: 0; z-index: 1042; min-width: 30vw;" />
2020-05-07 11:18:04 +00:00
<footer class="pt-2 pb-2 bg-dark text-light">
<b-container>
<b-row>
<b-col md="12" lg="6">
&copy;
<h-logo color="#fff" height="17" />
2019-2020 All rights reserved
2020-05-07 11:18:04 +00:00
</b-col>
<b-col md="6" lg="3" />
<b-col md="6" lg="3" />
</b-row>
</b-container>
</footer>
</div>
2019-09-09 15:03:10 +00:00
</template>
2019-09-10 18:08:22 +00:00
<script>
import axios from 'axios'
export default {
data: function () {
return {
loggedUser: null
2019-09-10 18:08:22 +00:00
}
},
mounted () {
if (sessionStorage.loggedUser) {
this.loggedUser = JSON.parse(sessionStorage.loggedUser)
}
this.updateSession()
2020-03-08 18:26:45 +00:00
this.$on('login', this.login)
setInterval(function (vm) { vm.checkForUpdate() }, 360000, this)
this.checkForUpdate()
2019-09-10 18:08:22 +00:00
},
methods: {
logout () {
axios
2020-05-22 13:49:56 +00:00
.post('/api/auth/logout')
.then(
(response) => {
delete sessionStorage.loggedUser
this.loggedUser = null
this.updateSession()
this.$router.push('/')
},
(error) => {
this.$bvToast.toast(
'An error occurs when trying to logout: ' + error.response.data.errmsg, {
title: 'Logout error',
autoHideDelay: 5000,
toaster: 'b-toaster-content-right'
}
)
}
)
},
updateSession () {
2020-05-22 13:49:56 +00:00
axios.get('/api/auth')
.then(
(response) => {
sessionStorage.loggedUser = JSON.stringify(response.data)
this.loggedUser = response.data
},
(error) => {
2020-05-22 09:09:39 +00:00
if (sessionStorage.loggedUser) {
delete sessionStorage.loggedUser
this.loggedUser = null
this.$root.$bvToast.toast(
'Invalid session, your have been logged out: ' + error.response.data.errmsg + '. Please login again.', {
title: 'Authentication timeout',
autoHideDelay: 5000,
variant: 'danger',
toaster: 'b-toaster-content-right'
}
)
this.$router.replace('/login')
}
}
)
2019-09-10 18:08:22 +00:00
},
checkForUpdate () {
if (sessionStorage.getItem('happyUpdate')) {
this.$bvToast.toast(
'A new version of happyDNS is already available. To enable it, please click here to refresh the page.', {
title: 'An update is available!',
variant: 'primary',
autoHideDelay: 360000,
href: window.location.pathname,
toaster: 'b-toaster-content-right'
}
)
}
},
2019-09-10 18:08:22 +00:00
login (email, password) {
axios
2020-05-22 13:49:56 +00:00
.post('/api/auth', {
2020-04-17 15:04:11 +00:00
email: email,
password: password
2019-09-10 18:08:22 +00:00
})
.then(
(response) => {
sessionStorage.loggedUser = JSON.stringify(response.data)
this.loggedUser = response.data
2019-09-10 18:08:22 +00:00
this.$router.push('/')
},
(error) => {
delete sessionStorage.loggedUser
this.loggedUser = null
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>