|
|
@ -1,22 +1,23 @@
|
|
|
|
import md5 from 'js-md5';
|
|
|
|
import md5 from 'js-md5';
|
|
|
|
import {getStore, removeStore, setStore} from '@/util/store'
|
|
|
|
import {getStore, removeStore, setStore} from '@/util/store'
|
|
|
|
import {removeTokenCookies, removeUserCookies, setTokenCookies, setUserCookies} from '@/util/auth'
|
|
|
|
import {getTokenCookies, removeTokenCookies, setTokenCookies} from '@/util/auth'
|
|
|
|
import {cancelToken, generateSalt, generateToken} from '@/api/user'
|
|
|
|
import {cancelToken, generateSalt, generateToken} from '@/api/user'
|
|
|
|
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
const user = {
|
|
|
|
state: {
|
|
|
|
state: {
|
|
|
|
user: getStore({name: 'user'}) || [],
|
|
|
|
user: getStore({name: 'user'}) || '',
|
|
|
|
token: getStore({name: 'token'}) || '',
|
|
|
|
token: getTokenCookies() || '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
actions: {
|
|
|
|
GenerateSalt(_, name) {
|
|
|
|
GenerateSalt({commit}, name) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
generateSalt(name).then(res => {
|
|
|
|
generateSalt(name).then(res => {
|
|
|
|
|
|
|
|
commit('SET_USER', name);
|
|
|
|
resolve(res.data);
|
|
|
|
resolve(res.data);
|
|
|
|
}).catch(error => {
|
|
|
|
}).catch(error => {
|
|
|
|
reject(error);
|
|
|
|
reject(error);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
GenerateToken({commit}, form) {
|
|
|
|
GenerateToken({commit}, form) {
|
|
|
|
let user = {
|
|
|
|
let user = {
|
|
|
@ -26,46 +27,41 @@ const user = {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
generateToken(user).then(res => {
|
|
|
|
generateToken(user).then(res => {
|
|
|
|
const data = res.data;
|
|
|
|
const data = res.data;
|
|
|
|
commit('SET_USER', user.name);
|
|
|
|
|
|
|
|
commit('SET_TOKEN', data);
|
|
|
|
commit('SET_TOKEN', data);
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
}).catch(error => {
|
|
|
|
}).catch(error => {
|
|
|
|
reject(error);
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ClearToken({commit}, name) {
|
|
|
|
ClearToken({commit}) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
cancelToken(name).then((res) => {
|
|
|
|
cancelToken(getStore({name: 'user'})).then((res) => {
|
|
|
|
commit('REMOVE_TOKEN');
|
|
|
|
|
|
|
|
commit('REMOVE_USER');
|
|
|
|
commit('REMOVE_USER');
|
|
|
|
|
|
|
|
commit('REMOVE_TOKEN');
|
|
|
|
resolve(res);
|
|
|
|
resolve(res);
|
|
|
|
}).catch(error => {
|
|
|
|
}).catch(error => {
|
|
|
|
reject(error);
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
mutations: {
|
|
|
|
SET_USER: (state, user) => {
|
|
|
|
SET_USER: (state, user) => {
|
|
|
|
setUserCookies(user);
|
|
|
|
|
|
|
|
state.user = user;
|
|
|
|
state.user = user;
|
|
|
|
setStore({name: 'user', content: state.user, type: 'session'})
|
|
|
|
setStore({name: 'user', content: state.user});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
REMOVE_USER: (state) => {
|
|
|
|
REMOVE_USER: (state) => {
|
|
|
|
removeUserCookies();
|
|
|
|
|
|
|
|
state.user = '';
|
|
|
|
state.user = '';
|
|
|
|
removeStore({name: 'user', type: 'session'});
|
|
|
|
removeStore({name: 'user'});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SET_TOKEN: (state, token) => {
|
|
|
|
SET_TOKEN: (state, token) => {
|
|
|
|
setTokenCookies(token);
|
|
|
|
|
|
|
|
state.token = token;
|
|
|
|
state.token = token;
|
|
|
|
setStore({name: 'token', content: state.token, type: 'session'})
|
|
|
|
setTokenCookies(token);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
REMOVE_TOKEN: (state) => {
|
|
|
|
REMOVE_TOKEN: (state) => {
|
|
|
|
removeTokenCookies();
|
|
|
|
|
|
|
|
state.token = '';
|
|
|
|
state.token = '';
|
|
|
|
removeStore({name: 'token', type: 'session'});
|
|
|
|
removeTokenCookies();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|