Add more components + base for history
This commit is contained in:
+91
-49
@@ -1,6 +1,7 @@
|
||||
|
||||
{% include "vue/plugins.js" %}
|
||||
|
||||
Vue.config.devtools = true
|
||||
|
||||
Vue.use(VueRouter)
|
||||
Vue.use(Vuex)
|
||||
Vue.use(EncryptionPlugin)
|
||||
@@ -24,29 +25,13 @@ const routes = [
|
||||
{% endfor %}
|
||||
]
|
||||
|
||||
|
||||
const encryptionStore = new Vuex.Store({
|
||||
state: {
|
||||
aes_key: null,
|
||||
keyPair: null,
|
||||
},
|
||||
|
||||
mutations: {
|
||||
update_aes_key (state, key) {
|
||||
state.aes_key = key
|
||||
},
|
||||
|
||||
update_keyPair (state, keyPair) {
|
||||
state.keyPair = keyPair
|
||||
},
|
||||
}
|
||||
})
|
||||
{% include "vue/stores.js" %}
|
||||
|
||||
const router = new VueRouter({routes})
|
||||
const approuter = new Vue({
|
||||
router,
|
||||
vuetify: new Vuetify(),
|
||||
store: encryptionStore,
|
||||
store: store,
|
||||
el: "#main",
|
||||
data: {
|
||||
uuid: "{{ user_settings.id }}",
|
||||
@@ -54,7 +39,7 @@ const approuter = new Vue({
|
||||
|
||||
computed: {
|
||||
locked: function() {
|
||||
return this.$store.state.aes_key == null || this.$store.state.keyPair?.privateKey == null
|
||||
return this.$store.state.encryption.aes_key == null || this.$store.state.encryption.keyPair?.privateKey == null
|
||||
}
|
||||
},
|
||||
|
||||
@@ -62,56 +47,113 @@ const approuter = new Vue({
|
||||
|
||||
methods: {
|
||||
async load_keys (aes_key) {
|
||||
const response = await this.$http.get(Urls["users:keys"]())
|
||||
try {
|
||||
|
||||
const iv_private = `${this.uuid}--private`
|
||||
const iv_public = `${this.uuid}--public`
|
||||
const response = await this.$http.get(Urls["users:keys"]())
|
||||
|
||||
if (response.data.privateKey != null) {
|
||||
const iv_private = `${this.uuid}--private`
|
||||
const iv_public = `${this.uuid}--public`
|
||||
|
||||
if (response.data.privateKey != null) {
|
||||
|
||||
const keyPair = {
|
||||
privateKey: await this.unwrapKey(aes_key, response.data.privateKey, iv_private, ["decrypt"]),
|
||||
publicKey: await this.unwrapKey(aes_key, response.data.publicKey, iv_public, ["encrypt"]),
|
||||
}
|
||||
|
||||
this.$store.commit('encryption/updateKeyPair', keyPair)
|
||||
|
||||
Swal.fire({title: "Successfully loaded K356!", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000});
|
||||
|
||||
} else {
|
||||
|
||||
const keyPair = await this.generateKeyPair()
|
||||
|
||||
await this.$http.post(
|
||||
Urls["users:keys"](),
|
||||
{
|
||||
privateKey: await this.wrapKey(this.keyPair.privateKey, aes_key, iv_private),
|
||||
publicKey: await this.wrapKey(this.keyPair.publicKey, aes_key, iv_public),
|
||||
}
|
||||
)
|
||||
|
||||
this.$store.commit('encryption/updateKeyPair', keyPair)
|
||||
|
||||
Swal.fire({title: "Successfully created K356!", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000});
|
||||
|
||||
const keyPair = {
|
||||
privateKey: await this.unwrapKey(aes_key, response.data.privateKey, iv_private, ["decrypt"]),
|
||||
publicKey: await this.unwrapKey(aes_key, response.data.publicKey, iv_public, ["encrypt"]),
|
||||
}
|
||||
|
||||
this.$store.commit('update_keyPair', keyPair)
|
||||
this.load_items()
|
||||
this.load_properties()
|
||||
this.load_relations()
|
||||
|
||||
Swal.fire({title: "Successfully loaded K356!", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000});
|
||||
} catch (err) {
|
||||
|
||||
} else {
|
||||
|
||||
const keyPair = await this.generateKeyPair()
|
||||
|
||||
await this.$http.post(
|
||||
Urls["users:keys"](),
|
||||
{
|
||||
privateKey: await this.wrapKey(this.keyPair.privateKey, aes_key, iv_private),
|
||||
publicKey: await this.wrapKey(this.keyPair.publicKey, aes_key, iv_public),
|
||||
}
|
||||
)
|
||||
|
||||
this.$store.commit('update_keyPair', keyPair)
|
||||
|
||||
Swal.fire({title: "Successfully created K356!", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000});
|
||||
Swal.fire({title: "{{_('Error during unwrapping of private key.<br><br>Maybe your password is wrong?') | escapejs}}", icon: "error", showConfirmButton: false})
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
update_key: function(key) {
|
||||
this.$store.commit('update_aes_key', key)
|
||||
this.$store.commit('encryption/updateAesKey', key)
|
||||
|
||||
this.load_keys(key)
|
||||
},
|
||||
|
||||
lock_me: function() {
|
||||
this.$store.commit('update_keyPair', null)
|
||||
this.$store.commit('update_aes_key', null)
|
||||
}
|
||||
this.$store.commit('encryption/updateKeyPair', null)
|
||||
this.$store.commit('encryption/updateAesKey', null)
|
||||
|
||||
// Lock all stores
|
||||
this.$store.commit('encryption/lock')
|
||||
this.$store.commit('items/lock')
|
||||
this.$store.commit('types/lock')
|
||||
this.$store.commit('relations/lock')
|
||||
this.$store.commit('properties/lock')
|
||||
this.$store.commit('linkedProperties/lock')
|
||||
this.$store.commit('relationProperties/lock')
|
||||
},
|
||||
|
||||
async load_items () {
|
||||
|
||||
const response = await this.$http.get(Urls["items:list"]())
|
||||
|
||||
this.$store.state.items.headers = response.data.result.items_headers
|
||||
this.$store.state.types.headers = response.data.result.types_headers
|
||||
|
||||
this.$store.dispatch("items/setItems", { self: this, items: response.data.result.items })
|
||||
this.$store.dispatch("types/setItems", { self: this, items: response.data.result.types })
|
||||
|
||||
},
|
||||
|
||||
async load_properties () {
|
||||
|
||||
const response = await this.$http.get(Urls["items:property.list"]())
|
||||
|
||||
this.$store.state.properties.headers = response.data.result.properties_headers
|
||||
this.$store.state.linkedProperties.headers = response.data.result.linked_properties_headers
|
||||
this.$store.state.relationProperties.headers = response.data.result.relation_properties_headers
|
||||
|
||||
this.$store.dispatch("properties/setItems", { self: this, items: response.data.result.properties })
|
||||
this.$store.dispatch("linkedProperties/setItems", { self: this, items: response.data.result.linked_properties })
|
||||
this.$store.dispatch("relationProperties/setItems", { self: this, items: response.data.result.relation_properties })
|
||||
|
||||
},
|
||||
|
||||
async load_relations () {
|
||||
|
||||
const response = await this.$http.get(Urls["items:relation.list"]())
|
||||
|
||||
this.$store.state.relations.headers = response.data.result.headers
|
||||
|
||||
this.$store.dispatch("relations/setItems", { self: this, items: response.data.result.relations })
|
||||
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
// Prevent from routing if key is not present.
|
||||
// Prevent from routing when locked or loading.
|
||||
next(!approuter.locked)
|
||||
})
|
||||
|
||||
@@ -105,7 +105,7 @@ const EncryptionPlugin = {
|
||||
|
||||
return btoa(arrayBufferToString(await operations.encrypt(
|
||||
{ name: "RSA-OAEP" },
|
||||
this.$store.state.keyPair.publicKey,
|
||||
this.$store.state.encryption.keyPair.publicKey,
|
||||
stringToArrayBuffer(data),
|
||||
)))
|
||||
|
||||
@@ -115,7 +115,7 @@ const EncryptionPlugin = {
|
||||
|
||||
return arrayBufferToString(await operations.decrypt(
|
||||
{ name: "RSA-OAEP" },
|
||||
this.$store.state.keyPair.privateKey,
|
||||
this.$store.state.encryption.keyPair.privateKey,
|
||||
stringToArrayBuffer(atob(armored_data))
|
||||
))
|
||||
|
||||
@@ -153,6 +153,42 @@ const EncryptionPlugin = {
|
||||
}))
|
||||
|
||||
return newobj
|
||||
},
|
||||
|
||||
Vue.prototype.object_edit = async function (url_edit, url_create, type, method, obj) {
|
||||
|
||||
let url = null
|
||||
|
||||
if (obj.id == undefined || obj.id == null) {
|
||||
url = Urls[url_create]()
|
||||
} else {
|
||||
url = Urls[url_edit](obj.id)
|
||||
}
|
||||
|
||||
const efields = this.$store.getters[`${type}/encryptedFields`]
|
||||
|
||||
try {
|
||||
|
||||
const newobj = await this.encryptObject(efields, obj)
|
||||
const response = await this.$http[method](url, newobj)
|
||||
|
||||
if (method != "delete") {
|
||||
return await this.decryptObject(efields, response.data.object)
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
let msg = "{{_('Error during edition') | escapejs}}"
|
||||
if (method == "delete") {
|
||||
msg = "{{_('Error during deletion') | escapejs}}"
|
||||
}
|
||||
|
||||
Swal.fire({title: msg, icon: "error", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
throw err
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
const encryptionStore = {
|
||||
namespaced: true,
|
||||
state: () => (
|
||||
{
|
||||
aes_key: null,
|
||||
keyPair: null,
|
||||
}
|
||||
),
|
||||
|
||||
mutations: {
|
||||
lock (state) {
|
||||
state.aes_key = null
|
||||
state.keyPair = null
|
||||
},
|
||||
|
||||
updateAesKey (state, key) {
|
||||
state.aes_key = key
|
||||
},
|
||||
|
||||
updateKeyPair (state, keyPair) {
|
||||
state.keyPair = keyPair
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const storeMixin = {
|
||||
state: () => (
|
||||
{
|
||||
items: [],
|
||||
headers: [],
|
||||
}
|
||||
),
|
||||
|
||||
mutations: {
|
||||
lock (state) {
|
||||
state.items = []
|
||||
},
|
||||
|
||||
addItem (state, item) {
|
||||
state.items.push(item)
|
||||
},
|
||||
|
||||
removeItem (state, id) {
|
||||
state.items = state.items.filter(i => i.id != id)
|
||||
|
||||
Swal.fire({title: "{{_('Successfully deleted!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
},
|
||||
|
||||
editItem (state, item_edited) {
|
||||
state.items = state.items.map(i => {
|
||||
if (i.id == item_edited.id) {
|
||||
return item_edited
|
||||
}
|
||||
|
||||
return i
|
||||
})
|
||||
|
||||
Swal.fire({title: "{{_('Successfully edited') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
},
|
||||
},
|
||||
|
||||
getters: {
|
||||
encryptedFields (state) {
|
||||
return state.headers.filter(e => e.encrypted).map(e => e.value)
|
||||
},
|
||||
|
||||
getById: (state) => (id) => {
|
||||
return state.items.find(e => e.id == id)
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
async setItems ({ commit, getters }, payload) {
|
||||
return payload.items.map(async item => {
|
||||
const new_item = await payload.self.decryptObject(getters.encryptedFields, item)
|
||||
|
||||
return await commit('addItem', new_item)
|
||||
})
|
||||
},
|
||||
|
||||
async addItem ({ getters, commit }, payload) {
|
||||
|
||||
const new_item = await payload.self.decryptObject(getters.encryptedFields, payload.item)
|
||||
|
||||
return await commit('addItem', new_item)
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const itemStore = {__proto__: storeMixin, namespaced: true}
|
||||
const typeStore = {__proto__: storeMixin, namespaced: true}
|
||||
const relationStore = {__proto__: storeMixin, namespaced: true}
|
||||
const propertyStore = {__proto__: storeMixin, namespaced: true}
|
||||
const linkedPropertyStore = {__proto__: storeMixin, namespaced: true}
|
||||
const relationPropertyStore = {__proto__: storeMixin, namespaced: true}
|
||||
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
encryption: encryptionStore,
|
||||
items: itemStore,
|
||||
types: typeStore,
|
||||
relations: relationStore,
|
||||
properties: propertyStore,
|
||||
linkedProperties: linkedPropertyStore,
|
||||
relationProperties: relationPropertyStore,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user