Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
InvestCustomer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Giang Tran
InvestCustomer
Commits
9716afe7
Commit
9716afe7
authored
Jun 11, 2021
by
Giang Tran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code
parent
003c63ae
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
196 additions
and
207 deletions
+196
-207
Login.js
src/Screens/Authen/Login.js
+2
-3
helpers.js
src/apis/helpers.js
+193
-203
url.js
src/apis/url.js
+1
-1
No files found.
src/Screens/Authen/Login.js
View file @
9716afe7
...
...
@@ -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
)
{
...
...
src/apis/helpers.js
View file @
9716afe7
...
...
@@ -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'
);
}
src/apis/url.js
View file @
9716afe7
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'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment