Commit 6203cc03 authored by rocosen's avatar rocosen

1

parent d6751b33
import Controller from './controller';
import store from '../reduxs/store';
import { setRequest } from '../reduxs/actions';
import qs from "qs";
import qs from 'qs';
import API from '../../commons/utils/api_manager';
import { Constants } from '../../commons/utils/constants';
import axios from 'axios';
......@@ -34,22 +34,22 @@ class Axios {
res,
};
} catch (error) {
if(error.response.data.errorCode=== '100003'){
if (error.response.data.errorCode === '100003') {
let reLoad = await Axios.request_reLoad();
if (reLoad['access_token']) {
localStorage.setItem(Constants.TOKEN_KEY, JSON.stringify(data))
localStorage.setItem(
Constants.TOKEN_KEY,
JSON.stringify(data)
);
window.location.reload();
}else{
} else {
setTimeout(() => {
localStorage.removeItem(Constants.TEMPORARY_TOKEN_KEY);
localStorage.removeItem(Constants.TOKEN_KEY);
}, 3000);
}
}
return;
}
actions && store.dispatch(setRequest(error));
if (!actions) {
return {
......@@ -62,17 +62,29 @@ class Axios {
}
static request_reLoad() {
let token = localStorage.getItem(Constants.TOKEN_KEY) && JSON.parse(localStorage.getItem(Constants.TOKEN_KEY)).refresh_token
let data = qs.stringify({ 'scope': 'ui', 'grant_type': 'refresh_token', 'refresh_token': token});
let token =
localStorage.getItem(Constants.TOKEN_KEY) &&
JSON.parse(localStorage.getItem(Constants.TOKEN_KEY)).refresh_token;
let data = qs.stringify({
scope: 'ui',
grant_type: 'refresh_token',
refresh_token: token,
});
return new Promise((resolve, reject) => {
axios.post(API.API_USER_LOGIN, data, {
axios
.post(API.API_USER_LOGIN, data, {
headers: {
'Authorization': 'Basic YnJvd3Nlcjo=',
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function (response) { resolve(response.data) })
.catch(function (error) { reject(error) })
Authorization: 'Basic YnJvd3Nlcjo=',
'Content-Type': 'application/x-www-form-urlencoded',
},
})
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
}
export default Axios;
......@@ -64,10 +64,17 @@ export default (props) => {
const [usernameError, setUsernameError] = useState(false);
const [password, setPassword] = useState('');
const [passwordError, setPasswordError] = useState(false);
const [checked, setChecked] = useState(localStorage.getItem('stay') && localStorage.getItem('stay') === "1" ? true :false );
const [checked, setChecked] = useState(
localStorage.getItem('stay') && localStorage.getItem('stay') === '1'
? true
: false
);
useEffect(() => {
if(localStorage.getItem(Constants.TOKEN_KEY) && localStorage.getItem('stay') === "1" ){
if (
localStorage.getItem(Constants.TOKEN_KEY) &&
localStorage.getItem('stay') === '1'
) {
getUserData();
}
if (!localStorage.getItem('Preferences')) {
......@@ -77,22 +84,14 @@ export default (props) => {
);
}
if(!localStorage.getItem('stay')){
localStorage.setItem(
'stay',
'1'
);
if (!localStorage.getItem('stay')) {
localStorage.setItem('stay', '1');
}
}, []);
const handleChange = (event) => {
setChecked(event.target.checked);
localStorage.setItem(
'stay',
event.target.checked ? '1':"2"
);
localStorage.setItem('stay', event.target.checked ? '1' : '2');
};
const login = async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment