mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-25 20:16:53 +01:00
-Updates:
-Remove 'state' on unneeded actions -Encrypt IndexedDb for security reasons, must be HTTPS or localhost
This commit is contained in:
parent
0d50cad313
commit
fef4171070
1
.gitignore
vendored
1
.gitignore
vendored
@ -45,3 +45,4 @@ www/
|
|||||||
#Hide connection file
|
#Hide connection file
|
||||||
/src/js/api/ConnectionMode.js
|
/src/js/api/ConnectionMode.js
|
||||||
/src/js/api/key.js
|
/src/js/api/key.js
|
||||||
|
/src/_to-ignore/
|
||||||
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -3090,6 +3090,11 @@
|
|||||||
"which": "^2.0.1"
|
"which": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"crypto-js": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg=="
|
||||||
|
},
|
||||||
"crypto-random-string": {
|
"crypto-random-string": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
|
"crypto-js": "^4.0.0",
|
||||||
"dom7": "^3.0.0",
|
"dom7": "^3.0.0",
|
||||||
"framework7": "^6.0.16",
|
"framework7": "^6.0.16",
|
||||||
"framework7-icons": "^4.0.2",
|
"framework7-icons": "^4.0.2",
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import { url, dbConfig } from './key';
|
import { url } from './key';
|
||||||
|
import { localForage } from './encrypt';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import * as localForage from "localforage";
|
|
||||||
|
|
||||||
const http = axios.create({
|
const http = axios.create({
|
||||||
baseURL: `${url}`,
|
baseURL: `${url}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
localForage.config(dbConfig);
|
|
||||||
|
|
||||||
async function checkToken (){
|
async function checkToken (){
|
||||||
let token = await localForage.getItem('token');
|
let token = await localForage.getItem('token');
|
||||||
if (token != null){
|
if (token != null){
|
||||||
|
49
src/js/api/encrypt.js
Normal file
49
src/js/api/encrypt.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { dbConfig } from './key';
|
||||||
|
import * as localforage from "localforage";
|
||||||
|
import CryptoJS from 'crypto-js';
|
||||||
|
|
||||||
|
localforage.config(dbConfig);
|
||||||
|
|
||||||
|
const localForage = {
|
||||||
|
/**
|
||||||
|
* Set object in storage
|
||||||
|
* @param {string} key object identifier
|
||||||
|
* @param {any} data object to store
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
async setItem(key, data) {
|
||||||
|
data = CryptoJS.AES.encrypt(JSON.stringify(data), dbConfig.key).toString();
|
||||||
|
return localforage.setItem(key, data);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get object from storage
|
||||||
|
* @param {string} key object identifier
|
||||||
|
* @return {any}
|
||||||
|
*/
|
||||||
|
async getItem(key) {
|
||||||
|
const data = await localforage.getItem(key);
|
||||||
|
if (data == null){
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
const bytes = CryptoJS.AES.decrypt(data, dbConfig.key);
|
||||||
|
return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete object from storage
|
||||||
|
* @param {string} key object identifier
|
||||||
|
*/
|
||||||
|
async deleteItem(key) {
|
||||||
|
return localforage.removeItem(key);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear storage
|
||||||
|
*/
|
||||||
|
async deleteAll() {
|
||||||
|
return localforage.clear();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { localForage };
|
@ -12,18 +12,18 @@ const theme = createStore({
|
|||||||
state.name = name;
|
state.name = name;
|
||||||
},
|
},
|
||||||
//End mutations
|
//End mutations
|
||||||
async checkTheme({ state, dispatch }, selector){
|
async checkTheme({ dispatch }, selector){
|
||||||
let theme = await localForage.getItem('theme');
|
let theme = await localForage.getItem('theme');
|
||||||
if (theme != 'theme-dark'){ $(selector).removeClass('theme-dark'); }
|
if (theme != 'theme-dark'){ $(selector).removeClass('theme-dark'); }
|
||||||
dispatch('changeTheme', theme);
|
dispatch('changeTheme', theme);
|
||||||
},
|
},
|
||||||
async initTheme({state, dispatch}, selector){
|
async initTheme({ dispatch }, selector){
|
||||||
let item = await localForage.getItem('theme');
|
let item = await localForage.getItem('theme');
|
||||||
if (item != null){
|
if (item != null){
|
||||||
await dispatch('checkTheme', selector);
|
await dispatch('checkTheme', selector);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async setTheme({ state, dispatch }, name){
|
async setTheme({ dispatch }, name){
|
||||||
await localForage.setItem('theme', name);
|
await localForage.setItem('theme', name);
|
||||||
dispatch('changeTheme', name);
|
dispatch('changeTheme', name);
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,7 @@ const user = createStore({
|
|||||||
await dispatch('getBasicData');
|
await dispatch('getBasicData');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async logIn({ state, dispatch }, data){
|
async logIn({ dispatch }, data){
|
||||||
dispatch('auth_request');
|
dispatch('auth_request');
|
||||||
try {
|
try {
|
||||||
const response = await http.post('/user/login', data);
|
const response = await http.post('/user/login', data);
|
||||||
@ -52,7 +52,7 @@ const user = createStore({
|
|||||||
throw new error;
|
throw new error;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async logOut({ state, dispatch }){
|
async logOut({ dispatch }){
|
||||||
dispatch('logout');
|
dispatch('logout');
|
||||||
await dispatch('clearBasicData');
|
await dispatch('clearBasicData');
|
||||||
delete http.defaults.headers.common['Authorization'];
|
delete http.defaults.headers.common['Authorization'];
|
||||||
|
Loading…
Reference in New Issue
Block a user