Merge remote-tracking branch 'origin' into dev

This commit is contained in:
Marco Realacci 2022-12-22 16:30:20 +01:00
commit ec0b06affc
4 changed files with 26 additions and 13 deletions

View file

@ -1,23 +1,23 @@
{ {
"hash": "80447977", "hash": "0c3e4771",
"browserHash": "b98131b5", "browserHash": "01248067",
"optimized": { "optimized": {
"axios": { "axios": {
"src": "../../axios/index.js", "src": "../../axios/index.js",
"file": "axios.js", "file": "axios.js",
"fileHash": "6b5eae63", "fileHash": "d8d02cf0",
"needsInterop": true "needsInterop": true
}, },
"vue": { "vue": {
"src": "../../vue/dist/vue.runtime.esm-bundler.js", "src": "../../vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js", "file": "vue.js",
"fileHash": "de50261f", "fileHash": "f8034b26",
"needsInterop": false "needsInterop": false
}, },
"vue-router": { "vue-router": {
"src": "../../vue-router/dist/vue-router.mjs", "src": "../../vue-router/dist/vue-router.mjs",
"file": "vue-router.js", "file": "vue-router.js",
"fileHash": "4cad12d6", "fileHash": "b4ca170f",
"needsInterop": false "needsInterop": false
} }
}, },

View file

@ -5,16 +5,26 @@ export default {
return { return {
modalTitle: "Modal Title", modalTitle: "Modal Title",
modalMsg: "Modal Message", modalMsg: "Modal Message",
logged_in: true,
} }
}, },
methods: { methods: {
showModal(title, message) { showModal(title, message) {
this.modalTitle = title; this.modalTitle = title
this.modalMsg = message; this.modalMsg = message
// Simulate a click on the hidden modal button to open it // Simulate a click on the hidden modal button to open it
this.$refs.openModal.click(); this.$refs.openModal.click()
}, },
setLoggedIn() {
this.logged_in = true
},
logout() {
localStorage.removeItem("token")
sessionStorage.removeItem("token")
this.logged_in = false
this.$router.push({ path: "/login" })
}
}, },
mounted() { mounted() {
@ -30,6 +40,7 @@ export default {
// If the response is 401, redirect to /login // If the response is 401, redirect to /login
if (error.response.status === 401) { if (error.response.status === 401) {
this.$router.push({ path: '/login' }) this.$router.push({ path: '/login' })
this.logged_in = false;
return; return;
} }
@ -53,13 +64,14 @@ export default {
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<main class="mb-5"> <main>
<!-- The view is rendered here --> <!-- The view is rendered here -->
<RouterView /> <RouterView />
<div v-if="logged_in" class="mb-5 pb-3"></div> <!-- Empty div to avoid hiding items under the navbar. todo: find a better way to do this -->
</main> </main>
<!-- Bottom navigation buttons --> <!-- Bottom navigation buttons -->
<nav id="global-nav" class="navbar fixed-bottom navbar-light bg-light row"> <nav v-if="logged_in" id="global-nav" class="navbar fixed-bottom navbar-light bg-light">
<div class="collapse navbar-collapse" id="navbarNav"></div> <div class="collapse navbar-collapse" id="navbarNav"></div>
<RouterLink to="/" class="col-4 text-center"> <RouterLink to="/" class="col-4 text-center">
<i class="bi bi-house text-dark" style="font-size: 2em"></i> <i class="bi bi-house text-dark" style="font-size: 2em"></i>

View file

@ -23,9 +23,7 @@ export default {
}, },
methods: { methods: {
logout() { logout() {
localStorage.removeItem("token"); this.$root.logout()
sessionStorage.removeItem("token");
this.$router.push({ path: "/login" });
}, },
visit() { visit() {
this.$router.push({ path: "/profile/" + this.user_id }); this.$router.push({ path: "/profile/" + this.user_id });

View file

@ -29,6 +29,8 @@ export default {
sessionStorage.setItem("token", response.data["user_id"]); sessionStorage.setItem("token", response.data["user_id"]);
localStorage.removeItem("token"); localStorage.removeItem("token");
} }
// Tell the root view to enable the navbar
this.$root.setLoggedIn();
// Update the header // Update the header
this.$axiosUpdate(); this.$axiosUpdate();
@ -86,6 +88,7 @@ export default {
<button style="width: 100%" type="button" class="btn btn-primary btn-block mb-4" @click="login">Sign in</button> <button style="width: 100%" type="button" class="btn btn-primary btn-block mb-4" @click="login">Sign in</button>
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg> <ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
<LoadingSpinner :loading="loading" /> <LoadingSpinner :loading="loading" />
<i class="text-center text-secondary d-flex flex-column">repeat after me: "best password is no password"</i>
</form> </form>
</div> </div>
</div> </div>