Commit 02afb8c4 by Giang Tran

update code

parent 9716afe7
...@@ -20,17 +20,15 @@ import JSEncrypt from 'jsencrypt'; ...@@ -20,17 +20,15 @@ import JSEncrypt from 'jsencrypt';
export const encryptRSAString = (val) => { export const encryptRSAString = (val) => {
var encrypt = new JSEncrypt(); var encrypt = new JSEncrypt();
encrypt.setPublicKey(MY_RSA_KEY.publicKey); encrypt.setPublicKey(RSA_KEY.publicKey);
var encrypted = encrypt.encrypt(val); var encrypted = encrypt.encrypt(val);
console.log('Ma hoa', encrypted);
return encrypted; return encrypted;
}; };
export const decryptRSAString = (val) => { export const decryptRSAString = (val) => {
var decrypt = new JSEncrypt(); var decrypt = new JSEncrypt();
decrypt.setPrivateKey(RSA_KEY.privateKey); decrypt.setPrivateKey(MY_RSA_KEY.privateKey);
var uncrypted = decrypt.decrypt(val); var uncrypted = decrypt.decrypt(val);
console.log('giai hoa', uncrypted);
return uncrypted; return uncrypted;
}; };
......
...@@ -20,6 +20,7 @@ import I18n from '../../helper/i18/i18n'; ...@@ -20,6 +20,7 @@ import I18n from '../../helper/i18/i18n';
import {showLoading, hideLoading} from '../../actions/loadingAction'; import {showLoading, hideLoading} from '../../actions/loadingAction';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {showAlert, TYPE} from '../../components/DropdownAlert'; import {showAlert, TYPE} from '../../components/DropdownAlert';
import {encryptRSAString} from '../../Config/Functions';
const NewPassword = (props) => { const NewPassword = (props) => {
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
...@@ -36,8 +37,8 @@ const NewPassword = (props) => { ...@@ -36,8 +37,8 @@ const NewPassword = (props) => {
const res = await forgotPasswordApi({ const res = await forgotPasswordApi({
receiver_name: email, receiver_name: email,
otp, otp,
password, password: encryptRSAString(password),
password_confirmation: cfPassword, password_confirmation: encryptRSAString(cfPassword),
platform: Platform.OS, platform: Platform.OS,
}); });
props.hideLoading(); props.hideLoading();
......
...@@ -16,7 +16,13 @@ import { ...@@ -16,7 +16,13 @@ import {
useBlurOnFulfill, useBlurOnFulfill,
useClearByFocusCell, useClearByFocusCell,
} from 'react-native-confirmation-code-field'; } from 'react-native-confirmation-code-field';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions'; import {
getFontXD,
HEIGHTXD,
WIDTHXD,
encryptRSAString,
decryptRSAString,
} from '../../Config/Functions';
import R from '../../assets/R'; import R from '../../assets/R';
import {NEWPASSWORD} from '../../routers/ScreenNames'; import {NEWPASSWORD} from '../../routers/ScreenNames';
import {verifyOTPApi, registorApi, getOTPApi} from '../../apis/Functions/users'; import {verifyOTPApi, registorApi, getOTPApi} from '../../apis/Functions/users';
...@@ -52,7 +58,7 @@ const ConfirmOTP = (propsa) => { ...@@ -52,7 +58,7 @@ const ConfirmOTP = (propsa) => {
const res = await verifyOTPApi({ const res = await verifyOTPApi({
platform: Platform.OS, platform: Platform.OS,
receiver_name: propsa.route.params.email, receiver_name: propsa.route.params.email,
otp: value, otp: encryptRSAString(value),
type: 'CUSTOMER_VERIFY', type: 'CUSTOMER_VERIFY',
}); });
...@@ -68,18 +74,18 @@ const ConfirmOTP = (propsa) => { ...@@ -68,18 +74,18 @@ const ConfirmOTP = (propsa) => {
if (sponsor_id) { if (sponsor_id) {
res = await registorApi({ res = await registorApi({
email, email,
password, password: encryptRSAString(password),
platform: Platform.OS, platform: Platform.OS,
password_confirmation, password_confirmation: encryptRSAString(password_confirmation),
sponsor_id, sponsor_id,
phone, phone,
}); });
} else { } else {
res = await registorApi({ res = await registorApi({
email, email,
password, password: encryptRSAString(password),
platform: Platform.OS, platform: Platform.OS,
password_confirmation, password_confirmation: encryptRSAString(password_confirmation),
phone, phone,
}); });
} }
......
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
CONFIRMCREATEOTP, CONFIRMCREATEOTP,
} from '../../../routers/ScreenNames'; } from '../../../routers/ScreenNames';
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import {encryptRSAString} from '../../../Config/Functions';
const ConfirmChangeSmartOTP = (props) => { const ConfirmChangeSmartOTP = (props) => {
const [firstNumber, setFirstNumber] = useState(null); const [firstNumber, setFirstNumber] = useState(null);
...@@ -47,9 +48,9 @@ const ConfirmChangeSmartOTP = (props) => { ...@@ -47,9 +48,9 @@ const ConfirmChangeSmartOTP = (props) => {
props.showLoading(); props.showLoading();
const res = await updateOTPApiSmart({ const res = await updateOTPApiSmart({
platform: Platform.OS, platform: Platform.OS,
password: props.route.params.pre_otp, password: encryptRSAString(props.route.params.pre_otp),
password_confirmation: pinCode, password_confirmation: encryptRSAString(pinCode),
old_password: props.route.params.old_password, old_password: encryptRSAString(props.route.params.old_password),
}); });
props.hideLoading(); props.hideLoading();
if (res.data.code == 200) { if (res.data.code == 200) {
......
...@@ -16,7 +16,12 @@ import { ...@@ -16,7 +16,12 @@ import {
useBlurOnFulfill, useBlurOnFulfill,
useClearByFocusCell, useClearByFocusCell,
} from 'react-native-confirmation-code-field'; } from 'react-native-confirmation-code-field';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../../Config/Functions'; import {
getFontXD,
HEIGHTXD,
WIDTHXD,
encryptRSAString,
} from '../../../Config/Functions';
import R from '../../../assets/R'; import R from '../../../assets/R';
import {NEWPASSWORD, TABNAVIGATOR} from '../../../routers/ScreenNames'; import {NEWPASSWORD, TABNAVIGATOR} from '../../../routers/ScreenNames';
import { import {
...@@ -75,8 +80,10 @@ const ConfirmOTP = (propsa) => { ...@@ -75,8 +80,10 @@ const ConfirmOTP = (propsa) => {
propsa.showLoading(); propsa.showLoading();
const res = await verifyStoreOTPApiSmart({ const res = await verifyStoreOTPApiSmart({
platform: Platform.OS, platform: Platform.OS,
password: propsa.route.params.password, password: encryptRSAString(propsa.route.params.password),
password_confirmation: propsa.route.params.password_confirmation, password_confirmation: encryptRSAString(
propsa.route.params.password_confirmation,
),
otp: value, otp: value,
type: 'CREATE_OTP_PASSWORD', type: 'CREATE_OTP_PASSWORD',
}); });
......
...@@ -23,6 +23,7 @@ import { ...@@ -23,6 +23,7 @@ import {
verifyStoreOTPApiSmart, verifyStoreOTPApiSmart,
getOTPApiSmartOTP, getOTPApiSmartOTP,
} from '../../apis/Functions/users'; } from '../../apis/Functions/users';
import {encryptRSAString} from '../../Config/Functions';
const CELL_COUNT = 4; const CELL_COUNT = 4;
...@@ -63,8 +64,10 @@ const ConfirmOTPSmart = (propsa) => { ...@@ -63,8 +64,10 @@ const ConfirmOTPSmart = (propsa) => {
propsa.showLoading(); propsa.showLoading();
const res = await verifyStoreOTPApiSmart({ const res = await verifyStoreOTPApiSmart({
platform: Platform.OS, platform: Platform.OS,
password: propsa.route.params.password, password: encryptRSAString(propsa.route.params.password),
password_confirmation: propsa.route.params.password_confirmation, password_confirmation: encryptRSAString(
propsa.route.params.password_confirmation,
),
otp: value, otp: value,
type: 'CREATE_OTP_PASSWORD', type: 'CREATE_OTP_PASSWORD',
}); });
......
...@@ -8,6 +8,7 @@ import {hideLoading, showLoading} from '../../actions/loadingAction'; ...@@ -8,6 +8,7 @@ import {hideLoading, showLoading} from '../../actions/loadingAction';
import {OTP_TYPE} from '../../Config/constants'; import {OTP_TYPE} from '../../Config/constants';
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import {RESET_SMART_OTP, CHANGESMARTOTP} from '../../routers/ScreenNames'; import {RESET_SMART_OTP, CHANGESMARTOTP} from '../../routers/ScreenNames';
import {decryptRSAString, encryptRSAString} from '../../Config/Functions';
const EnterPasswordSmartOTP = (props) => { const EnterPasswordSmartOTP = (props) => {
const navigation = useNavigation(); const navigation = useNavigation();
...@@ -38,12 +39,12 @@ const EnterPasswordSmartOTP = (props) => { ...@@ -38,12 +39,12 @@ const EnterPasswordSmartOTP = (props) => {
if (props.route.params.type == 'CHANGE_SMART_OTP') { if (props.route.params.type == 'CHANGE_SMART_OTP') {
const res = await verifyOTPApiSmart({ const res = await verifyOTPApiSmart({
platform: Platform.OS, platform: Platform.OS,
otp_password: pinCode, otp_password: encryptRSAString(pinCode),
type: 'VERIFY_OTP_PASSWORD', type: 'VERIFY_OTP_PASSWORD',
}); });
if (res.data.code == 200) { if (res.data.code == 200) {
navigation.navigate(CHANGESMARTOTP, { navigation.navigate(CHANGESMARTOTP, {
old_password: pinCode, old_password: encryptRSAString(pinCode),
TYPE: 'CHANGE_SMART_OTP', TYPE: 'CHANGE_SMART_OTP',
}); });
clearPIN(); clearPIN();
...@@ -55,7 +56,7 @@ const EnterPasswordSmartOTP = (props) => { ...@@ -55,7 +56,7 @@ const EnterPasswordSmartOTP = (props) => {
const res = await getOTPApiSmartOTP({ const res = await getOTPApiSmartOTP({
platform: Platform.OS, platform: Platform.OS,
otp_by: props.user.email, otp_by: props.user.email,
otp_password: pinCode, otp_password: encryptRSAString(pinCode),
type: type:
props.route.params.type == 'DEPOSIT' props.route.params.type == 'DEPOSIT'
? OTP_TYPE.CUSTOMER_REQUEST_DEPOSIT ? OTP_TYPE.CUSTOMER_REQUEST_DEPOSIT
...@@ -63,7 +64,10 @@ const EnterPasswordSmartOTP = (props) => { ...@@ -63,7 +64,10 @@ const EnterPasswordSmartOTP = (props) => {
}); });
if (res.data.code == 200) { if (res.data.code == 200) {
props.route.params.onGoToSmartOTP(pinCode, res.data.data.otp); props.route.params.onGoToSmartOTP(
pinCode,
decryptRSAString(res.data.data.otp),
);
} else { } else {
showAlert(TYPE.ERROR, I18n.t('Notification'), res.data.message); showAlert(TYPE.ERROR, I18n.t('Notification'), res.data.message);
clearPIN(); clearPIN();
......
...@@ -11,104 +11,113 @@ import {connect} from 'react-redux'; ...@@ -11,104 +11,113 @@ import {connect} from 'react-redux';
import {hideLoading, showLoading} from '../../actions/loadingAction'; import {hideLoading, showLoading} from '../../actions/loadingAction';
import {OTP_TYPE} from '../../Config/constants'; import {OTP_TYPE} from '../../Config/constants';
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import {encryptRSAString, decryptRSAString} from '../../Config/Functions';
const SmartOTP = (props) => { const SmartOTP = (props) => {
const [value, setValue] = useState(props.route.params.otp); const [value, setValue] = useState(props.route.params.otp);
const [progress, setProgress] = useState(1); const [progress, setProgress] = useState(1);
const [isReset, setReset] = useState(false); const [isReset, setReset] = useState(false);
const navigate = useNavigation(); const navigate = useNavigation();
useEffect(() => { useEffect(() => {
setValue(props.route.params.otp); setValue(props.route.params.otp);
}, [props.route.params.otp]); }, [props.route.params.otp]);
const confirm = async () => { const confirm = async () => {
if (!value) { if (!value) {
showAlert(TYPE.WARN, I18n.t('Notification'), I18n.t('EnterOTPRequest')); showAlert(TYPE.WARN, I18n.t('Notification'), I18n.t('EnterOTPRequest'));
} else if (value.length != 4) { } else if (value.length != 4) {
showAlert(TYPE.WARN, I18n.t('Notification'), I18n.t('OTPInvalid')); showAlert(TYPE.WARN, I18n.t('Notification'), I18n.t('OTPInvalid'));
} else { } else {
props.showLoading(); props.showLoading();
let res1 = await verifyOTPApi({ let res1 = await verifyOTPApi({
platform: Platform.OS, platform: Platform.OS,
receiver_name: props.user.email, receiver_name: props.user.email,
otp: value, otp: encryptRSAString(value),
type: props.route.params.type == 'DEPOSIT' ? OTP_TYPE.CUSTOMER_REQUEST_DEPOSIT : OTP_TYPE.REQUEST_WITHDRAW, type:
}); props.route.params.type == 'DEPOSIT'
? OTP_TYPE.CUSTOMER_REQUEST_DEPOSIT
if (res1.data.code == 200) { : OTP_TYPE.REQUEST_WITHDRAW,
let res; });
if (props.route.params.type == 'DEPOSIT') {
const {amount, notes} = props.route.params;
res = await walletDeposit({
amount,
platform: Platform.OS,
notes,
fee: 0,
});
} else {
const {src, receiving_account, amount, notes} = props.route.params;
res = await widthDraw({
src,
receiving_account,
amount,
platform: Platform.OS,
notes,
fee: 0,
});
}
props.hideLoading(); if (res1.data.code == 200) {
if (res.data.code == 200) { let res;
setTimeout(() => { if (props.route.params.type == 'DEPOSIT') {
showAlert(TYPE.SUCCESS, I18n.t('Notification'), res.data.message); const {amount, notes} = props.route.params;
navigate.navigate(TABNAVIGATOR); res = await walletDeposit({
}, 500); amount,
} else {
showAlert(TYPE.ERROR, I18n.t('Notification'), res.data.message);
}
} else {
showAlert(TYPE.ERROR, I18n.t('Notification'), res1.data.message);
}
props.hideLoading();
}
};
const getNewOTP = async () => {
props.showLoading();
const res = await getOTPApiSmartOTP({
platform: Platform.OS, platform: Platform.OS,
otp_by: props.user.email, notes,
otp_password: props.route.params.pinCode, fee: 0,
type: props.route.params.type == 'DEPOSIT' ? OTP_TYPE.CUSTOMER_REQUEST_DEPOSIT : OTP_TYPE.REQUEST_WITHDRAW, });
});
if (res.data.code == 200) {
setValue(res.data.data.otp);
setReset(!isReset);
} else { } else {
showAlert(TYPE.ERROR, I18n.t('Notification'), res.data.message); const {src, receiving_account, amount, notes} = props.route.params;
res = await widthDraw({
src,
receiving_account,
amount,
platform: Platform.OS,
notes,
fee: 0,
});
} }
props.hideLoading(); props.hideLoading();
}; if (res.data.code == 200) {
setTimeout(() => {
showAlert(TYPE.SUCCESS, I18n.t('Notification'), res.data.message);
navigate.navigate(TABNAVIGATOR);
}, 500);
} else {
showAlert(TYPE.ERROR, I18n.t('Notification'), res.data.message);
}
} else {
showAlert(TYPE.ERROR, I18n.t('Notification'), res1.data.message);
}
props.hideLoading();
}
};
const getNewOTP = async () => {
props.showLoading();
const res = await getOTPApiSmartOTP({
platform: Platform.OS,
otp_by: props.user.email,
otp_password: encryptRSAString(props.route.params.pinCode),
type:
props.route.params.type == 'DEPOSIT'
? OTP_TYPE.CUSTOMER_REQUEST_DEPOSIT
: OTP_TYPE.REQUEST_WITHDRAW,
});
if (res.data.code == 200) {
setValue(decryptRSAString(res.data.data.otp));
setReset(!isReset);
} else {
showAlert(TYPE.ERROR, I18n.t('Notification'), res.data.message);
}
props.hideLoading();
};
const updateProgress = (count) => { const updateProgress = (count) => {
setProgress(count > 0 ? count / 300 : 0); setProgress(count > 0 ? count / 300 : 0);
}; };
return <SmartOTPView return (
value={value} <SmartOTPView
progress={progress} value={value}
confirm={confirm} progress={progress}
isReset={isReset} confirm={confirm}
getNewOTP={getNewOTP} isReset={isReset}
updateProgress={updateProgress} getNewOTP={getNewOTP}
setValue={setValue}/>; updateProgress={updateProgress}
setValue={setValue}
/>
);
}; };
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { return {
user: state.userReducer, user: state.userReducer,
}; };
}; };
export default connect(mapStateToProps, {showLoading, hideLoading})(SmartOTP); export default connect(mapStateToProps, {showLoading, hideLoading})(SmartOTP);
...@@ -16,7 +16,12 @@ import { ...@@ -16,7 +16,12 @@ import {
useBlurOnFulfill, useBlurOnFulfill,
useClearByFocusCell, useClearByFocusCell,
} from 'react-native-confirmation-code-field'; } from 'react-native-confirmation-code-field';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions'; import {
getFontXD,
HEIGHTXD,
WIDTHXD,
encryptRSAString,
} from '../../Config/Functions';
import R from '../../assets/R'; import R from '../../assets/R';
import {TABNAVIGATOR} from '../../routers/ScreenNames'; import {TABNAVIGATOR} from '../../routers/ScreenNames';
import {verifyOTPApi} from '../../apis/Functions/users'; import {verifyOTPApi} from '../../apis/Functions/users';
...@@ -68,8 +73,10 @@ const ConfirmOTPSmart = (propsa) => { ...@@ -68,8 +73,10 @@ const ConfirmOTPSmart = (propsa) => {
propsa.showLoading(); propsa.showLoading();
const res = await verifyStoreOTPApiSmart({ const res = await verifyStoreOTPApiSmart({
platform: Platform.OS, platform: Platform.OS,
password: propsa.route.params.password, password: encryptRSAString(propsa.route.params.password),
password_confirmation: propsa.route.params.password_confirmation, password_confirmation: encryptRSAString(
propsa.route.params.password_confirmation,
),
otp: value, otp: value,
type: 'FORGOT_PASSWORD', type: 'FORGOT_PASSWORD',
}); });
......
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