2018-08-28 20:50:22 +00:00
|
|
|
<template>
|
2019-11-03 12:44:40 +00:00
|
|
|
<div>
|
2020-11-01 16:13:45 +00:00
|
|
|
<template v-if="online">
|
2019-11-03 12:44:40 +00:00
|
|
|
<!-- This is a workaround to get the sw to "see" the to-be-cached version of the offline background image -->
|
|
|
|
<div class="offline" style="height: 0;width: 0;"></div>
|
2020-11-01 16:41:20 +00:00
|
|
|
<top-navigation v-if="authUser"/>
|
|
|
|
<content-auth v-if="authUser"/>
|
|
|
|
<content-link-share v-else-if="authLinkShare"/>
|
2020-11-01 16:13:45 +00:00
|
|
|
<content-no-auth v-else/>
|
2020-03-02 20:19:26 +00:00
|
|
|
<notification/>
|
2020-11-01 16:13:45 +00:00
|
|
|
</template>
|
2019-11-03 12:44:40 +00:00
|
|
|
<div class="app offline" v-else>
|
|
|
|
<div class="offline-message">
|
|
|
|
<h1>You are offline.</h1>
|
|
|
|
<p>Please check your network connection and try again.</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-07-25 14:52:04 +00:00
|
|
|
|
|
|
|
<transition name="fade">
|
2020-11-01 16:03:06 +00:00
|
|
|
<keyboard-shortcuts v-if="keyboardShortcutsActive"/>
|
2020-07-25 14:52:04 +00:00
|
|
|
</transition>
|
2019-11-03 12:44:40 +00:00
|
|
|
</div>
|
2018-08-28 20:50:22 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-05 20:35:52 +00:00
|
|
|
import {mapState} from 'vuex'
|
2019-09-09 17:55:43 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
import authTypes from './models/authTypes'
|
2018-09-07 06:42:17 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
import Notification from './components/misc/notification'
|
2020-11-01 16:38:09 +00:00
|
|
|
import {KEYBOARD_SHORTCUTS_ACTIVE, ONLINE} from './store/mutation-types'
|
2020-09-05 20:35:52 +00:00
|
|
|
import KeyboardShortcuts from './components/misc/keyboard-shortcuts'
|
2020-11-01 16:03:06 +00:00
|
|
|
import TopNavigation from '@/components/home/topNavigation'
|
2020-11-01 16:06:37 +00:00
|
|
|
import ContentAuth from '@/components/home/contentAuth'
|
2020-11-01 16:08:51 +00:00
|
|
|
import ContentLinkShare from '@/components/home/contentLinkShare'
|
2020-11-01 16:13:45 +00:00
|
|
|
import ContentNoAuth from '@/components/home/contentNoAuth'
|
2019-12-18 21:30:20 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
export default {
|
|
|
|
name: 'app',
|
|
|
|
components: {
|
2020-11-01 16:13:45 +00:00
|
|
|
ContentNoAuth,
|
2020-11-01 16:08:51 +00:00
|
|
|
ContentLinkShare,
|
2020-11-01 16:06:37 +00:00
|
|
|
ContentAuth,
|
2020-11-01 16:03:06 +00:00
|
|
|
TopNavigation,
|
2020-09-05 20:35:52 +00:00
|
|
|
KeyboardShortcuts,
|
|
|
|
Notification,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
currentDate: new Date(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount() {
|
|
|
|
// Check if the user is offline, show a message then
|
|
|
|
this.$store.commit(ONLINE, navigator.onLine)
|
|
|
|
window.addEventListener('online', () => this.$store.commit(ONLINE, navigator.onLine))
|
|
|
|
window.addEventListener('offline', () => this.$store.commit(ONLINE, navigator.onLine))
|
2019-10-16 21:27:21 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
// Password reset
|
|
|
|
if (this.$route.query.userPasswordReset !== undefined) {
|
|
|
|
localStorage.removeItem('passwordResetToken') // Delete an eventually preexisting old token
|
|
|
|
localStorage.setItem('passwordResetToken', this.$route.query.userPasswordReset)
|
2020-11-01 16:42:52 +00:00
|
|
|
this.$router.push({name: 'user.password-reset.reset'})
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
|
|
|
// Email verification
|
|
|
|
if (this.$route.query.userEmailConfirm !== undefined) {
|
|
|
|
localStorage.removeItem('emailConfirmToken') // Delete an eventually preexisting old token
|
|
|
|
localStorage.setItem('emailConfirmToken', this.$route.query.userEmailConfirm)
|
2020-11-01 16:42:52 +00:00
|
|
|
this.$router.push({name: 'user.login'})
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeCreate() {
|
|
|
|
this.$store.dispatch('config/update')
|
|
|
|
this.$store.dispatch('auth/checkAuth')
|
|
|
|
.then(() => {
|
|
|
|
// Check if the user is already logged in, if so, redirect them to the homepage
|
|
|
|
if (
|
|
|
|
!this.userAuthenticated &&
|
|
|
|
this.$route.name !== 'user.login' &&
|
|
|
|
this.$route.name !== 'user.password-reset.request' &&
|
|
|
|
this.$route.name !== 'user.password-reset.reset' &&
|
|
|
|
this.$route.name !== 'user.register' &&
|
|
|
|
this.$route.name !== 'link-share.auth'
|
|
|
|
) {
|
2020-11-01 16:42:52 +00:00
|
|
|
this.$router.push({name: 'user.login'})
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
created() {
|
2019-12-18 21:30:20 +00:00
|
|
|
|
2020-10-08 20:17:41 +00:00
|
|
|
// Make sure to always load the home route when running with electron
|
2020-11-01 16:03:06 +00:00
|
|
|
if (this.$route.fullPath.endsWith('frontend/index.html')) {
|
2020-10-08 20:17:41 +00:00
|
|
|
this.$router.push({name: 'home'})
|
|
|
|
}
|
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
// Try renewing the token every time vikunja is loaded initially
|
|
|
|
// (When opening the browser the focus event is not fired)
|
|
|
|
this.$store.dispatch('auth/renewToken')
|
2020-06-12 18:02:32 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
// Check if the token is still valid if the window gets focus again to maybe renew it
|
|
|
|
window.addEventListener('focus', () => {
|
2020-06-12 18:11:23 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
if (!this.userAuthenticated) {
|
|
|
|
return
|
|
|
|
}
|
2020-06-12 18:11:23 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
const expiresIn = this.userInfo.exp - +new Date() / 1000
|
2020-06-12 18:11:23 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
// If the token expiry is negative, it is already expired and we have no choice but to redirect
|
|
|
|
// the user to the login page
|
|
|
|
if (expiresIn < 0) {
|
|
|
|
this.$store.dispatch('auth/checkAuth')
|
2020-11-01 16:42:52 +00:00
|
|
|
this.$router.push({name: 'user.login'})
|
2020-09-05 20:35:52 +00:00
|
|
|
return
|
|
|
|
}
|
2020-06-12 18:11:23 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
// Check if the token is valid for less than 60 hours and renew if thats the case
|
|
|
|
if (expiresIn < 60 * 3600) {
|
|
|
|
this.$store.dispatch('auth/renewToken')
|
|
|
|
console.log('renewed token')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2020-11-01 16:41:20 +00:00
|
|
|
computed: {
|
|
|
|
authUser() {
|
|
|
|
return this.userAuthenticated && (this.userInfo && this.userInfo.type === authTypes.USER)
|
|
|
|
},
|
|
|
|
authLinkShare() {
|
|
|
|
return this.userAuthenticated && (this.userInfo && this.userInfo.type === authTypes.LINK_SHARE)
|
|
|
|
},
|
|
|
|
...mapState({
|
|
|
|
userInfo: state => state.auth.info,
|
|
|
|
userAuthenticated: state => state.auth.authenticated,
|
|
|
|
online: ONLINE,
|
|
|
|
keyboardShortcutsActive: KEYBOARD_SHORTCUTS_ACTIVE,
|
|
|
|
}),
|
|
|
|
},
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
2018-08-28 20:50:22 +00:00
|
|
|
</script>
|