Skip to content

Commit e560978

Browse files
gideonairexCMCDragonkai
authored andcommitted
chore: refactor
1 parent d5b1401 commit e560978

File tree

20 files changed

+764
-344
lines changed

20 files changed

+764
-344
lines changed

src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ body {
44

55
.app-content {
66
height: 100vh;
7+
/* padding: 10px; */
78
}

src/renderer/App.vue

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,50 @@
2222
* Chore:
2323
* 1. Login not used yet
2424
*/
25-
import { defineComponent } from 'vue'
25+
import { defineComponent, watchEffect } from 'vue'
26+
import { useRouter } from 'vue-router'
2627
import Alert from './components/alerts/Alert.vue'
2728
import AppBar from './components/navigation/AppBar.vue'
2829
import Drawer from './components/navigation/Drawer.vue'
29-
// import Footer from './components/navigation/Footer.vue'
30-
// import NewVault from './components/vaults/NewVault.vue'
31-
// import Login from './components/navigation/Login.vue';
3230
3331
import useModule from '@/store/useModule'
3432
33+
const noop = () => {}
34+
3535
export default defineComponent({
3636
components: {
3737
Alert,
3838
AppBar,
3939
Drawer
40-
// Footer
41-
// Login
4240
},
4341
setup() {
44-
const alertModule = useModule('Alert')
45-
console.log(alertModule.state)
46-
alertModule.dispatch('toggle')
42+
const router = useRouter()
43+
const userStore = useModule('User')
44+
watchEffect(() => {
45+
/** Watch the status here for redirection */
46+
const userStatus = userStore.state.userStatus
47+
const isUnlocked = userStore.state.isUnlocked
48+
if (isUnlocked) {
49+
return noop()
50+
}
51+
switch (userStatus) {
52+
case 'RegisterNode':
53+
router.replace('/Configuration/RegisterNode')
54+
break
55+
case 'NewNode':
56+
router.replace('/Configuration/NewKeyNode')
57+
break
58+
case 'UnlockNode':
59+
router.replace('/Configuration/UnlockKeyNode')
60+
break
61+
default:
62+
break
63+
}
64+
})
65+
/**
66+
* Check user if isUnclocked if not need to run the polykeyclient
67+
*/
68+
userStore.dispatch('checkUserStatus')
4769
}
4870
})
4971
</script>

src/renderer/components/configuration/Configuration.vue

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<v-icon>fas fa-file</v-icon>
2222
</v-list-item-icon>
2323

24-
<v-list-item-title>{{item}}</v-list-item-title>
24+
<v-list-item-title>{{ item }}</v-list-item-title>
2525

2626
<v-spacer></v-spacer>
2727
<v-btn link icon x-small color="warning" @click="deleteVault(item)">
@@ -31,57 +31,51 @@
3131
</v-list-item-group>
3232
</v-list>
3333
</v-col>
34-
<v-col class="main-panel fill-parent-height">
35-
<!-- <v-card color="FloralWhite" style="position: relative" width="100%">
36-
<v-form v-model="valid" ref="newVaultForm">
37-
<v-container>
38-
<h2>New KeyNode</h2>
39-
<span>Use this form to initialize a new keynode state</span>
40-
<v-row>
41-
<v-col>
42-
<v-list outlined>
43-
<v-text-field
44-
v-model="secretName"
45-
:rules="secretNameRules"
46-
label="Full Name"
47-
counter="100"
48-
required
49-
outlined
50-
style="padding-left: 10px; padding-right: 10px"
51-
placeholder="Enter your full name"
52-
/>
53-
54-
<v-textarea
55-
v-model="secretContent"
56-
label="Secret Content"
57-
required
58-
outlined
59-
style="padding-left: 10px; padding-right: 10px"
60-
placeholder="Enter the content of the secret"
61-
></v-textarea>
62-
</v-list>
63-
</v-col>
64-
</v-row>
65-
</v-container>
66-
67-
<v-card-actions>
68-
<v-btn @click="cancel">Cancel</v-btn>
69-
<v-btn color="warning" @click="resetValidation">Clear</v-btn>
70-
<v-spacer></v-spacer>
71-
<v-btn color="success" @click="newSecret">Create</v-btn>
72-
</v-card-actions>
73-
</v-form>
74-
</v-card> -->
75-
</v-col>
7634
</v-row>
7735
</v-container>
7836
</template>
7937

8038
<script lang="ts">
8139
import { defineComponent } from 'vue'
40+
import PolykeyClient from '@/store/PolykeyClient'
8241
8342
export default defineComponent({
84-
setup () {
43+
setup() {
44+
// // try to start polykey
45+
// try {
46+
// const pid: number = PolykeyClient.StartAgent()
47+
// console.log(`Agent has been started with a pid of: ${pid}`)
48+
// // prompt user to unlock polykey node
49+
50+
// /** Ask for passphrase or popup*/
51+
// const { passphrase } = user.prompt()
52+
53+
// await PolykeyClient.RegisterNode(passphrase)
54+
55+
// console.log('new node is unlocked and ready to go')
56+
// /** Then just close it and user can freely navigate */
57+
58+
// } catch (error) {
59+
60+
// if (error.message.includes('not been initialized')) {
61+
// // need to prompt user for new node details
62+
// const { userId, passphrase, nbits } = user.prompt()
63+
// /** By default 1024 nbits */
64+
// /** So only ask for the userId and passphrase */
65+
// await PolykeyClient.NewNode({ userId, passphrase, nbits })
66+
// console.log('new node is unlocked and ready to go')
67+
68+
// } else if (error.message.includes('already running')) {
69+
// // polykey agent is already running, prompt for passphrase to unlock
70+
// const { passphrase } = user.prompt()
71+
// /** popup also */
72+
// await PolykeyClient.UnlockNode({ passphrase })
73+
// console.log('new node is unlocked and ready to go')
74+
// } else {
75+
// // some other error
76+
// throw Error(`something else went wrong: ${error.message}`)
77+
// }
78+
// }
8579
return {
8680
newKeyNode: () => {},
8781
deleteVault: () => {}
Lines changed: 39 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,48 @@
11
<template>
2-
<v-card color="FloralWhite" style="margin: 10px;">
3-
<v-form width="100%" v-model="valid" ref="newKeyNodeForm">
4-
<v-container fluid width="100%">
5-
<h2>New KeyNode</h2>
6-
<span>Use this form to initialize a new keynode state</span>
7-
<v-row>
8-
<v-col>
9-
<v-list outlined>
10-
<v-text-field
11-
v-model="fullName"
12-
:rules="nameRules"
13-
label="Full Name"
14-
counter="100"
15-
required
16-
outlined
17-
style="padding-left: 10px; padding-right: 10px"
18-
placeholder="Enter your full name"
19-
/>
20-
21-
<v-text-field
22-
v-model="email"
23-
:rules="emailRules"
24-
label="Email"
25-
counter="100"
26-
required
27-
outlined
28-
style="padding-left: 10px; padding-right: 10px"
29-
placeholder="Enter your email"
30-
/>
31-
32-
<v-text-field
33-
v-model="passphrase"
34-
:rules="passphraseRules"
35-
label="Passphrase"
36-
counter="100"
37-
required
38-
type="password"
39-
outlined
40-
style="padding-left: 10px; padding-right: 10px"
41-
placeholder="Enter a passphrase to secure your private key"
42-
/>
43-
44-
<v-text-field
45-
v-model="nodePath"
46-
:rules="nodePathRules"
47-
label="New Key Node Path"
48-
required
49-
outlined
50-
style="padding-left: 10px; padding-right: 10px"
51-
placeholder="Provide the path to the new key node directory"
52-
>
53-
<template v-slot:append>
54-
<v-btn icon small @click.native="openFileDialog()">
55-
<v-icon>fas fa-folder-open</v-icon>
56-
</v-btn>
57-
</template>
58-
</v-text-field>
59-
</v-list>
60-
</v-col>
61-
</v-row>
62-
</v-container>
63-
64-
<v-card-actions>
65-
<v-btn @click="cancel">Cancel</v-btn>
66-
<v-btn color="warning" @click="resetValidation">Clear</v-btn>
67-
<v-spacer></v-spacer>
68-
<v-btn color="success" @click="newKeyNode">Create</v-btn>
69-
</v-card-actions>
70-
</v-form>
71-
</v-card>
2+
<ui-form nowrap>
3+
<h2>New Keynode</h2>
4+
<ui-form-field>
5+
<ui-textfield v-model="userId" placeholder="UserId">UserId</ui-textfield>
6+
</ui-form-field>
7+
<ui-form-field>
8+
<ui-textfield v-model="passphrase" placeholder="Passphrase">Passphrase</ui-textfield>
9+
</ui-form-field>
10+
<ui-form-field>
11+
<ui-textfield v-model="nbits" placeholder="Nbits">nbits</ui-textfield>
12+
</ui-form-field>
13+
<br />
14+
<ui-form-field>
15+
<ui-button @click="createKeyNode" raised>Create</ui-button>
16+
</ui-form-field>
17+
</ui-form>
7218
</template>
7319

7420
<script lang="ts">
75-
import { defineComponent } from 'vue'
21+
import { defineComponent, ref } from 'vue'
22+
import PolykeyClient from '@/store/PolykeyClient'
23+
import useModule from '@/store/useModule'
7624
7725
export default defineComponent({
78-
setup () {
26+
setup() {
27+
const userStore = useModule('User')
28+
const userId = ref('')
29+
const passphrase = ref('')
30+
const nbits = ref(1024)
31+
const createKeyNode = async () => {
32+
const result = await PolykeyClient.NewNode({
33+
userid: userId.value,
34+
passphrase: passphrase.value,
35+
nbits: nbits.value
36+
})
37+
if (result) {
38+
userStore.dispatch('userIsUnlocked')
39+
}
40+
}
7941
return {
80-
openFileDialog: () => {}
42+
userId,
43+
passphrase,
44+
nbits,
45+
createKeyNode
8146
}
8247
}
8348
})
@@ -154,5 +119,4 @@ export default defineComponent({
154119
// }
155120
</script>
156121

157-
<style scoped>
158-
</style>
122+
<style scoped></style>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<ui-form nowrap>
3+
<h2>Register Node</h2>
4+
<ui-form-field>
5+
<ui-textfield v-model="passphrase" placeholder="Passphrase">Passphrase</ui-textfield>
6+
</ui-form-field>
7+
<br />
8+
<ui-form-field>
9+
<ui-button @click="registerNode" raised>Register</ui-button>
10+
</ui-form-field>
11+
</ui-form>
12+
</template>
13+
14+
<script lang="ts">
15+
import { defineComponent, ref } from 'vue'
16+
import PolykeyClient from '@/store/PolykeyClient'
17+
import useModule from '@/store/useModule'
18+
import { useRouter } from 'vue-router'
19+
20+
export default defineComponent({
21+
setup() {
22+
const router = useRouter()
23+
const userStore = useModule('User')
24+
const passphrase = ref('')
25+
const registerNode = async () => {
26+
try {
27+
/** this seems to be funky how will I know that this user has already registered a node */
28+
await PolykeyClient.RegisterNode(passphrase.value)
29+
userStore.dispatch('userIsUnlocked')
30+
/** Reroute on vaults by default */
31+
router.push('/Vaults')
32+
} catch (error) {
33+
if (error.message.includes('not been initialized')) {
34+
userStore.dispatch('setUserStatus', 'NewNode')
35+
} else if (error.message.includes('already running')) {
36+
userStore.dispatch('setUserStatus', 'UnlockNode')
37+
} else if (error.message.includes('node is already unlocked')) {
38+
/** There should be a way to know if done registration on node */
39+
userStore.dispatch('userIsUnlocked')
40+
/** Reroute on vaults by default */
41+
router.push('/Vaults')
42+
}
43+
}
44+
}
45+
return {
46+
passphrase,
47+
registerNode
48+
}
49+
}
50+
})
51+
</script>
52+
53+
<style scoped></style>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<template>
2+
<ui-form nowrap>
3+
<h2>Unlock Key Node</h2>
4+
<ui-form-field>
5+
<ui-textfield v-model="passphrase" placeholder="Passphrase">Passphrase</ui-textfield>
6+
</ui-form-field>
7+
<br />
8+
<ui-form-field>
9+
<ui-button @click="unlockKeyNode" raised>Unlock Key Node</ui-button>
10+
</ui-form-field>
11+
</ui-form>
12+
</template>
13+
14+
<script lang="ts">
15+
import { defineComponent, ref } from 'vue'
16+
17+
export default defineComponent({
18+
setup() {
19+
const passphrase = ref('')
20+
const unlockKeyNode = () => {}
21+
return {
22+
passphrase,
23+
unlockKeyNode
24+
}
25+
}
26+
})
27+
</script>
28+
29+
<style scoped></style>

0 commit comments

Comments
 (0)