Explorar el Código

Add auto-login vue template and route

pull/5/head
Svitlana hace 4 años
padre
commit
10836e7b2b
Se han modificado 2 ficheros con 76 adiciones y 0 borrados
  1. +2
    -0
      src/_helpers/router.js
  2. +74
    -0
      src/account/AppLoginPage.vue

+ 2
- 0
src/_helpers/router.js Ver fichero

@@ -13,6 +13,7 @@ import LoginPage from '../auth/LoginPage'
import LogoutPage from '../auth/LogoutPage'
import ForgotPasswordPage from '../auth/ForgotPasswordPage'
import MultifactorAuthPage from '../auth/MultifactorAuthPage'
import AppLoginPage from '../account/AppLoginPage'
import DashboardPage from '../account/DashboardPage'
import ProfilePage from '../account/profile/ProfilePage'
import ActionPage from '../account/profile/ActionPage'
@@ -107,6 +108,7 @@ export const router = new Router({
{ path: '/login', component: LoginPage },
{ path: '/logout', component: LogoutPage },
{ path: '/forgotPassword', component: ForgotPasswordPage },
{ path: '/applogin', component: AppLoginPage },

{ path: '/admin/accounts', component: AccountsPage },
{ path: '/admin/new_account', component: ProfilePage },


+ 74
- 0
src/account/AppLoginPage.vue Ver fichero

@@ -0,0 +1,74 @@
<!-- Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ -->
<template>
<div>
<div>
<hr/>
<router-link :to="linkPrefix+'/me'">{{messages.link_label_account}}</router-link>
<hr/>
<router-link :to="linkPrefix+'/'">{{messages.link_label_bubble}}</router-link>
<router-view></router-view>
</div>
</div>
</template>

<script>
import { mapState, mapGetters, mapActions } from 'vuex'
import { util } from '../_helpers'

export default {
data() {
return {
linkPrefix: null,
user: util.currentUser()
}
},
computed: {
...mapState('account', {
currentUser: state => state.user
}),
...mapState('users', ['user']),
...mapState('system', ['messages', 'configs']),
},
created () {
linkPrefix = this.$route.path;
if (user !== null && (typeof user.token !== 'undefined' && user.token !== null)) {
if (this.$route.path !== '' || this.$route.path !== '/'){
if (this.$route.path === '/applogin') {
this.$route.path = '/';
} else {
console.warn('AppLoginPage.created: route path is not empty, sending to login page');
this.$router.push('/login');
return;
}
}
} else {
console.warn('AppLoginPage.created: no currentUser, sending to login page');
this.$router.push('/login');
return;
}
},
beforeRouteUpdate (to, from, next) {
// TODO add /me verification

if (user !== null && (typeof user.token !== 'undefined' && user.token !== null)) {
next();
} else {
next('/login');
}
},
methods: {
...mapActions('account', ['checkSession', 'validateAccount']),
...mapActions('system', ['loadSystemConfigs', 'loadMessages'])
},
watch: {
user (u) {
if (u !== null && (typeof u.token !== 'undefined' && u.token !== null)) {
this.checkSession({messages: this.messages, errors: this.errors});
this.$router.replace('/');
} else {
this.$router.replace('/login');
}
}
}
};
</script>

Cargando…
Cancelar
Guardar