Commit 9716afe7 by Giang Tran

update code

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