Skip to content

Commit 603d7f5

Browse files
committed
Init login page. Updated router, store, login and logout features.
1 parent a1dd619 commit 603d7f5

File tree

7 files changed

+114
-41
lines changed

7 files changed

+114
-41
lines changed

src/css/app.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import url('https://fonts.googleapis.com/css?family=Source+Code+Pro&display=swap');
2+
23
.code {
34
font-family: 'Source Code Pro', monospace;
45
}

src/pages/Index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
</q-banner> -->
3737
<q-btn color="vgreen" class="text-vdark q-mx-xs" label="Get the vDex node" @click=getInstaller />
3838
<q-btn color="vdark" class="text-vgrey q-mx-xs" label="Chat" @click="chatDialog=true" />
39+
<q-btn color="vdark" class="text-vgrey q-mx-xs" label="Logout" @click="$utils.logout()" />
3940
</div>
4041
</div>
4142
</div>

src/pages/Login.vue

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<template>
2+
<q-layout>
3+
<q-page-container>
4+
<q-page class="bg-vblack">
5+
<q-icon name="fas fa-angle-right" class="text-vgreen fixed-center" style="font-size: 5rem;" />
6+
<div class="row">
7+
<div class="col bg-vblack window-height q-pa-xl text-center">
8+
<q-img src="statics/icons/icon-512x512.png" spinner-color="vgrey" style="height: 150px; max-width: 150px" />
9+
<div class="text-h5 text-vgrey"><span class="text-weight-bolder">vDexNode</span> dashboard</div>
10+
<div class="text-subtitle1 text-vgrey">Rent your computer to earn VTX</div>
11+
</div>
12+
<div class="col bg-vgrey window-height q-pa-xl">
13+
<div class="text-h5">Import private key</div>
14+
<div class="text-subtitle2">Please enter your private key below to start working with vDexNode Dashboard. We will never save or transmit your your key.</div>
15+
<q-input dense v-model="privateKey" :type="isPwd ? 'password' : 'text'" counter color="vdark" ref="input" @keyup.enter="updatePrivate" >
16+
<template v-slot:append>
17+
<q-icon :name="isPwd ? 'visibility_off' : 'visibility'" class="cursor-pointer" @click="isPwd = !isPwd" />
18+
</template>
19+
</q-input>
20+
<q-btn color="black" unelevated rounded outline class="full-width q-mt-md" label="Continue" @click="login" />
21+
</div>
22+
</div>
23+
</q-page>
24+
</q-page-container>
25+
</q-layout>
26+
</template>
27+
28+
<script>
29+
export default {
30+
data () {
31+
return {
32+
privateKey: '',
33+
isPwd: true
34+
}
35+
},
36+
mounted () {
37+
this.$refs.input.focus()
38+
},
39+
methods: {
40+
login () {
41+
this.$utils.login(this.privateKey)
42+
this.privateKey = ''
43+
}
44+
}
45+
}
46+
</script>

src/router/index.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import Vue from 'vue'
22
import VueRouter from 'vue-router'
3-
3+
import store from '../store'
44
import routes from './routes'
55

66
Vue.use(VueRouter)
77

8-
/*
9-
* If not building with SSR mode, you can
10-
* directly export the Router instantiation
11-
*/
12-
13-
export default function (/* { store, ssrContext } */) {
14-
const Router = new VueRouter({
15-
scrollBehavior: () => ({ x: 0, y: 0 }),
16-
routes,
8+
const router = new VueRouter({
9+
scrollBehavior: () => ({ x: 0, y: 0 }),
10+
routes,
11+
mode: process.env.VUE_ROUTER_MODE,
12+
base: process.env.VUE_ROUTER_BASE
13+
})
1714

18-
// Leave these as is and change from quasar.conf.js instead!
19-
// quasar.conf.js -> build -> vueRouterMode
20-
// quasar.conf.js -> build -> publicPath
21-
mode: process.env.VUE_ROUTER_MODE,
22-
base: process.env.VUE_ROUTER_BASE
23-
})
15+
router.beforeEach((to, from, next) => {
16+
if (to.matched.some(record => record.meta.requiresAuth)) {
17+
if (store.getters.isLoggedIn) {
18+
next()
19+
return
20+
}
21+
next('/login')
22+
} else {
23+
next()
24+
}
25+
})
2426

25-
return Router
26-
}
27+
export default router

src/router/routes.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
const routes = [
33
{
44
path: '/',
5-
component: () => import('pages/Index.vue')
5+
component: () => import('pages/Index.vue'),
6+
meta: {
7+
requiresAuth: true
8+
}
9+
},
10+
{
11+
path: '/login',
12+
component: () => import('pages/Login.vue')
613
}
714
]
815

src/store/index.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,43 @@ Vue.use(Vuex)
1111

1212
function initialState () {
1313
return {
14-
loggedIn: false
14+
loggedIn: false,
15+
identity: {}
1516
}
1617
}
1718

1819
const store = new Vuex.Store({
1920
// plugins: [vuexPersist.plugin],
2021
state: initialState,
2122
getters: {
22-
getLoggedIn: state => {
23-
return state.loggedIn
24-
}
23+
isLoggedIn: state => state.loggedIn,
24+
getIdentity: state => state.identity
2525
},
2626
mutations: {
27-
resetState: (state) => {
27+
logout: (state) => {
2828
Object.assign(state, initialState())
2929
},
30+
login: (state, privateKey) => {
31+
state.identity.privateKey = privateKey
32+
},
3033
setLoggedIn: state => {
3134
state.loggedIn = true
3235
}
3336
},
3437
actions: {
35-
// logout: (context) => {
36-
// return new Promise((resolve, reject) => {
37-
// context.commit('resetState')
38-
// resolve()
39-
// })
40-
// },
41-
// login: ({ context }, privateKey, publicKey, accountName) => {
42-
// console.log(privateKey, publicKey, accountName)
43-
// return new Promise((resolve, reject) => {
44-
// context.commit('setLoggedIn')
45-
// context.commit('setPrivateKey', privateKey)
46-
// context.commit('setPublicKey', publicKey)
47-
// context.commit('setAccountName', accountName)
48-
// resolve()
49-
// })
50-
// }
38+
login ({ commit }, privateKey) {
39+
return new Promise((resolve, reject) => {
40+
commit('login', privateKey)
41+
commit('setLoggedIn')
42+
resolve()
43+
})
44+
},
45+
logout ({ commit }) {
46+
return new Promise((resolve, reject) => {
47+
commit('logout')
48+
resolve()
49+
})
50+
}
5151
}
5252
})
5353

src/util/utils.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { shell } from 'electron'
22
import store from '@/store'
3+
import router from '@/router'
34

45
/**
56
* Function returns an array with removed duplicates by any field in the object
@@ -66,10 +67,26 @@ function formatBytes (bytes, decimals) {
6667
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
6768
}
6869

70+
function login (privateKey) {
71+
store.dispatch('login', { privateKey }).then(() => {
72+
router.push('/')
73+
}).catch(err => {
74+
console.log(err)
75+
})
76+
}
77+
78+
function logout () {
79+
store.dispatch('logout').then(() => {
80+
router.push('/login')
81+
})
82+
}
83+
6984
export {
7085
getUnique,
7186
sortByKey,
7287
openExternal,
7388
formatBytes,
74-
getUniqueLocations
89+
getUniqueLocations,
90+
login,
91+
logout
7592
}

0 commit comments

Comments
 (0)