Merge pull request #4 from askotx/appserv

-Updates
This commit is contained in:
Juan Carlos Ruvalcaba 2021-05-03 19:10:08 -07:00 committed by GitHub
commit 9160f3a8f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 9 deletions

1
.gitignore vendored
View File

@ -45,3 +45,4 @@ www/
#Hide connection file
/src/js/api/ConnectionMode.js
/src/js/api/key.js
/src/_to-ignore/

5
package-lock.json generated
View File

@ -3090,6 +3090,11 @@
"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": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",

View File

@ -28,6 +28,7 @@
],
"dependencies": {
"axios": "^0.21.1",
"crypto-js": "^4.0.0",
"dom7": "^3.0.0",
"framework7": "^6.0.16",
"framework7-icons": "^4.0.2",

View File

@ -1,13 +1,11 @@
import { url, dbConfig } from './key';
import { url } from './key';
import { localForage } from './encrypt';
import axios from 'axios';
import * as localForage from "localforage";
const http = axios.create({
baseURL: `${url}`,
});
localForage.config(dbConfig);
async function checkToken (){
let token = await localForage.getItem('token');
if (token != null){

49
src/js/api/encrypt.js Normal file
View 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 };

View File

@ -12,18 +12,18 @@ const theme = createStore({
state.name = name;
},
//End mutations
async checkTheme({ state, dispatch }, selector){
async checkTheme({ dispatch }, selector){
let theme = await localForage.getItem('theme');
if (theme != 'theme-dark'){ $(selector).removeClass('theme-dark'); }
dispatch('changeTheme', theme);
},
async initTheme({state, dispatch}, selector){
async initTheme({ dispatch }, selector){
let item = await localForage.getItem('theme');
if (item != null){
await dispatch('checkTheme', selector);
}
},
async setTheme({ state, dispatch }, name){
async setTheme({ dispatch }, name){
await localForage.setItem('theme', name);
dispatch('changeTheme', name);
},

View File

@ -34,7 +34,7 @@ const user = createStore({
await dispatch('getBasicData');
}
},
async logIn({ state, dispatch }, data){
async logIn({ dispatch }, data){
dispatch('auth_request');
try {
const response = await http.post('/user/login', data);
@ -52,7 +52,7 @@ const user = createStore({
throw new error;
}
},
async logOut({ state, dispatch }){
async logOut({ dispatch }){
dispatch('logout');
await dispatch('clearBasicData');
delete http.defaults.headers.common['Authorization'];