happyDomain/htdocs/src/App.vue

176 lines
5.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="/" style="font-family: 'Fortheenas01';font-weight:bold;">
happy<span style="font-family: 'Fortheenas01 Bold';margin-left:.1em;">DNS</span>
</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 />
<b-toaster name="b-toaster-content-right" style="position: fixed; top: 70px; right: 0; z-index: 10; min-width: 30vw;" />
<footer class="pt-2 pb-2 bg-dark text-light">
<b-container>
<b-row>
<b-col md="12" lg="6">
&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
</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'
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: {
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>