Commit 9716afe7 by Giang Tran

update code

parent 003c63ae
......@@ -18,7 +18,7 @@ import {
FORGOTPASSWORD,
CONFIRMEMAIL,
} from '../../routers/ScreenNames';
import {checkFormatArray} from '../../Config/Functions';
import {checkFormatArray, encryptRSAString} from '../../Config/Functions';
import {loginApi} from '../../apis/Functions/users';
import KEY from '../../assets/AsynStorage';
import AsyncStorage from '@react-native-community/async-storage';
......@@ -75,12 +75,11 @@ const Login = (props) => {
props.showLoading();
const res = await loginApi({
email,
password: pass,
password: encryptRSAString(pass),
platform: Platform.OS,
device_token: firebase,
account_type: 'CUSTOMER',
});
props.hideLoading();
if (res.data) {
if (res.data.code == 200 && res.data.data) {
......
......@@ -8,179 +8,169 @@ import {DeviceEventEmitter} from 'react-native';
axios.defaults.timeout = 10000;
export async function GetData(url, data) {
const token = await AsyncStorage.getItem(KEY.TOKEN);
let myRequest = {
method: 'get',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
params: {
...data,
},
timeout: 30 * 1000,
// withCredentials: true,
};
console.log('My request', myRequest);
return await axios(myRequest)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
const token = await AsyncStorage.getItem(KEY.TOKEN);
let myRequest = {
method: 'get',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
params: {
...data,
},
timeout: 30 * 1000,
// withCredentials: true,
};
console.log('My request', myRequest);
return await axios(myRequest)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
}
export async function PostLogin(url, json) {
let myRequest = {
method: 'post',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
timeout: 30 * 1000,
data: JSON.stringify(json),
};
console.log('post data mobile', myRequest);
return await axios(myRequest)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
let myRequest = {
method: 'post',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
timeout: 30 * 1000,
data: JSON.stringify(json),
};
console.log('post data mobile', myRequest);
return await axios(myRequest)
.then((response) => {
return response;
})
.then((response) => {
return response;
})
.catch((error) => {
console.log(error);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
}
export async function PostData(url, json, isAuth = true) {
const token = await AsyncStorage.getItem(KEY.TOKEN);
console.log(token);
let myRequest = {
method: 'post',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
timeout: 30 * 1000,
data: JSON.stringify(json),
};
console.log('post data mobile', myRequest);
return await axios(myRequest)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
const token = await AsyncStorage.getItem(KEY.TOKEN);
console.log(token);
let myRequest = {
method: 'post',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
timeout: 30 * 1000,
data: JSON.stringify(json),
};
console.log('post data mobile', myRequest);
return await axios(myRequest)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
}
export async function PostFormData(url, data) {
const token = await AsyncStorage.getItem(KEY.TOKEN);
const source = axios.CancelToken.source();
const timeout = setTimeout(() => {
source.cancel();
// Timeout Logic
}, 60000);
console.log(token);
let myRequest = {
method: 'post',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
Authorization: 'Bearer ' + token,
},
timeout: 60000,
data: data,
cancelToken: source.token,
};
console.log('post data mobile', myRequest.data);
return await axios(myRequest)
.then((response) => {
clearTimeout(timeout);
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
clearTimeout(timeout);
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
clearTimeout(timeout);
console.log('errorTimeout', error);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
const token = await AsyncStorage.getItem(KEY.TOKEN);
const source = axios.CancelToken.source();
const timeout = setTimeout(() => {
source.cancel();
// Timeout Logic
}, 60000);
console.log(token);
let myRequest = {
method: 'post',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
Authorization: 'Bearer ' + token,
},
timeout: 60000,
data: data,
cancelToken: source.token,
};
console.log('post data mobile', myRequest.data);
return await axios(myRequest)
.then((response) => {
clearTimeout(timeout);
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
clearTimeout(timeout);
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
clearTimeout(timeout);
console.log('errorTimeout', error);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
}
/**
......@@ -190,46 +180,46 @@ export async function PostFormData(url, data) {
* @param {*} isAuth is state auth
*/
export async function PutData(url, json, isAuth = true) {
const token = await AsyncStorage.getItem(KEY.TOKEN);
let myRequest = {
method: 'put',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
data: JSON.stringify(json),
};
console.log('PutData', myRequest);
return await axios(myRequest)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
const token = await AsyncStorage.getItem(KEY.TOKEN);
let myRequest = {
method: 'put',
url,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
data: JSON.stringify(json),
};
console.log('PutData', myRequest);
return await axios(myRequest)
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.then((response) => {
if (response.data?.code === 401) {
logout();
return;
} else {
return response;
}
})
.catch((error) => {
console.log(error.request);
const err = {
message: 'error',
status: error.request.status,
};
return err;
});
}
export function logout() {
showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('LoginSessionEnd'));
DeviceEventEmitter.emit('logout');
showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('LoginSessionEnd'));
DeviceEventEmitter.emit('logout');
}
export const root = 'http://services.dcvinvest.com/';
export default {
urllogin: root + 'api/auth/customer-login',
urllogin: root + 'api/v2/auth/customer-login',
urlRegistor: root + 'api/auth/customer-register',
urlGetListMethod: root + 'api/v1/payments/get-list-deposit-method',
urlGetOTP: root + 'api/auth/customer-get-otp',
......
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