Commit 0dd06b5b by Giang Tran

connect api fogot password

parent 06ebeb35
...@@ -5,32 +5,51 @@ import { ...@@ -5,32 +5,51 @@ import {
TextInput, TextInput,
StyleSheet, StyleSheet,
TouchableOpacity, TouchableOpacity,
Platform,
Alert,
} from 'react-native'; } from 'react-native';
import HeaderBack from '../../components/Header/HeaderBack'; import HeaderBack from '../../components/Header/HeaderBack';
import {connect} from 'react-redux';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions'; import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions';
import R from '../../assets/R'; import R from '../../assets/R';
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import {CONFIRMOTP} from '../../routers/ScreenNames'; import {CONFIRMOTP} from '../../routers/ScreenNames';
import {getOTPApi} from '../../apis/Functions/users';
import {showLoading, hideLoading} from '../../actions/loadingAction';
const ConfirmEmail = (props) => { const ConfirmEmail = (props) => {
const [value, setValue] = useState(''); const [value, setValue] = useState('');
const navigate = useNavigation(); const navigate = useNavigation();
const getOTP = async () => {
if (value) {
props.showLoading();
const res = await getOTPApi({
platform: Platform.OS,
otp_by: value,
});
props.hideLoading();
if (res.data.code == 200) {
navigate.navigate(CONFIRMOTP, {email: value});
} else {
Alert.alert(res.data.message);
}
} else {
Alert.alert('Vui lòng nhập email!');
}
};
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<HeaderBack title={'Quên mật khẩu'} /> <HeaderBack title={'Quên mật khẩu'} />
<View style={styles.container}> <View style={styles.container}>
<View style={styles.wrap}> <View style={styles.wrap}>
<View style={styles.containerCode}> <View style={styles.containerCode}>
<Text style={styles.txtTitle}> <Text style={styles.txtTitle}>Vui lòng nhp email:</Text>
Vui lòng nhp email hoc s đin thoi
</Text>
<TextInput <TextInput
style={styles.txtInput} style={styles.txtInput}
placeholder="Nhập Email hoặc số điện thoại" placeholder="Nhập email"
value={value} value={value}
onChangeText={(val) => setValue(val)} onChangeText={(val) => setValue(val)}
/> />
...@@ -39,9 +58,7 @@ const ConfirmEmail = (props) => { ...@@ -39,9 +58,7 @@ const ConfirmEmail = (props) => {
</View> </View>
<View style={styles.footer}> <View style={styles.footer}>
<TouchableOpacity <TouchableOpacity onPress={getOTP} style={styles.btn}>
onPress={() => navigate.navigate(CONFIRMOTP)}
style={styles.btn}>
<Text style={styles.txtBtn}>Ly mã xác thc</Text> <Text style={styles.txtBtn}>Ly mã xác thc</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => navigate.goBack()}> <TouchableOpacity onPress={() => navigate.goBack()}>
...@@ -115,4 +132,10 @@ const styles = StyleSheet.create({ ...@@ -115,4 +132,10 @@ const styles = StyleSheet.create({
}, },
}); });
export default ConfirmEmail; const mapStateToProps = (state) => {
return {};
};
export default connect(mapStateToProps, {showLoading, hideLoading})(
ConfirmEmail,
);
...@@ -5,6 +5,8 @@ import { ...@@ -5,6 +5,8 @@ import {
TextInput, TextInput,
StyleSheet, StyleSheet,
TouchableOpacity, TouchableOpacity,
Platform,
Alert,
} from 'react-native'; } from 'react-native';
import HeaderBack from '../../components/Header/HeaderBack'; import HeaderBack from '../../components/Header/HeaderBack';
...@@ -17,16 +19,19 @@ import { ...@@ -17,16 +19,19 @@ import {
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions'; import {getFontXD, HEIGHTXD, WIDTHXD} 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} from '../../apis/Functions/users';
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import {showLoading, hideLoading} from '../../actions/loadingAction';
import {connect} from 'react-redux';
const CELL_COUNT = 4; const CELL_COUNT = 4;
const ConfirmOTP = (propsa) => { const ConfirmOTP = (propsa) => {
const [value, setValue] = useState(''); const [value, setValue] = useState('');
const navigate = useNavigation(); const navigate = useNavigation();
console.log('test'); console.log(propsa.route.params.email);
const ref = useBlurOnFulfill({value, cellCount: CELL_COUNT}); const ref = useBlurOnFulfill({value, cellCount: CELL_COUNT});
const [props, getCellOnLayoutHandler] = useClearByFocusCell({ const [props, getCellOnLayoutHandler] = useClearByFocusCell({
...@@ -34,9 +39,35 @@ const ConfirmOTP = (propsa) => { ...@@ -34,9 +39,35 @@ const ConfirmOTP = (propsa) => {
setValue, setValue,
}); });
const confirm = async () => {
if (!value) {
Alert.alert('Vui long nhập mã OTP');
} else if (value.length != 4) {
Alert.alert('Mã OTP không đúng định dạng');
} else {
propsa.showLoading();
const res = await verifyOTPApi({
platform: Platform.OS,
receiver_name: propsa.route.params.email,
otp: value,
});
propsa.hideLoading();
if (res.data.code == 200) {
navigate.navigate(NEWPASSWORD, {
otp: value,
email: propsa.route.params.email,
});
} else {
Alert(res.data.message);
}
}
};
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<HeaderBack title={'Quên mật khẩu'} /> <HeaderBack title={'Xác thưc OTP'} />
<View style={styles.container}> <View style={styles.container}>
<View style={{height: 20}} /> <View style={{height: 20}} />
...@@ -68,9 +99,7 @@ const ConfirmOTP = (propsa) => { ...@@ -68,9 +99,7 @@ const ConfirmOTP = (propsa) => {
</View> </View>
</View> </View>
<View style={styles.footer}> <View style={styles.footer}>
<TouchableOpacity <TouchableOpacity onPress={confirm} style={styles.btn}>
onPress={() => navigate.navigate(NEWPASSWORD)}
style={styles.btn}>
<Text style={styles.txtBtn}>Tiếp tc</Text> <Text style={styles.txtBtn}>Tiếp tc</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => console.log('Hello')}> <TouchableOpacity onPress={() => console.log('Hello')}>
...@@ -155,4 +184,8 @@ const styles = StyleSheet.create({ ...@@ -155,4 +184,8 @@ const styles = StyleSheet.create({
}, },
}); });
export default ConfirmOTP; const mapStateToProps = (state) => {
return {};
};
export default connect(mapStateToProps, {showLoading, hideLoading})(ConfirmOTP);
...@@ -29,8 +29,8 @@ import {connect} from 'react-redux'; ...@@ -29,8 +29,8 @@ import {connect} from 'react-redux';
const Login = (props) => { const Login = (props) => {
const {navigation} = props; const {navigation} = props;
const [email, setEmail] = useState('Tdgiang@dcv.vn'); const [email, setEmail] = useState('');
const [pass, setPass] = useState('123456'); const [pass, setPass] = useState('');
const navigate = useNavigation(); const navigate = useNavigation();
...@@ -61,10 +61,10 @@ const Login = (props) => { ...@@ -61,10 +61,10 @@ const Login = (props) => {
routes: [{name: TABNAVIGATOR}], routes: [{name: TABNAVIGATOR}],
}); });
} else { } else {
Alert.alert('Thông báo!', res.data.message); Alert.alert(res.data.message);
} }
} else { } else {
Alert.alert('Thông báo!', 'Vui lòng điền ' + titles[index]); Alert.alert('Vui lòng điền ' + titles[index]);
} }
}; };
......
...@@ -5,16 +5,54 @@ import { ...@@ -5,16 +5,54 @@ import {
TextInput, TextInput,
StyleSheet, StyleSheet,
TouchableOpacity, TouchableOpacity,
Alert,
Platform,
} from 'react-native'; } from 'react-native';
import HeaderBack from '../../components/Header/HeaderBack'; import HeaderBack from '../../components/Header/HeaderBack';
import {forgotPasswordApi} from '../../apis/Functions/users';
import {useNavigation} from '@react-navigation/native';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions'; import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions';
import R from '../../assets/R'; import R from '../../assets/R';
import {AUTHEN} from '../../routers/ScreenNames';
import {showLoading, hideLoading} from '../../actions/loadingAction';
import {connect} from 'react-redux';
const NewPassword = (props) => { const NewPassword = (props) => {
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [cfPassword, setcfPassword] = useState(''); const [cfPassword, setcfPassword] = useState('');
const navigate = useNavigation();
const {email, otp} = props.route.params;
const changePass = async () => {
if (!password || !cfPassword) {
Alert.alert('Vui lòng điền đầy đủ thông tin!');
} else {
props.showLoading();
const res = await forgotPasswordApi({
receiver_name: email,
otp,
password,
password_confirmation: cfPassword,
platform: Platform.OS,
});
props.hideLoading();
console.log(res.data);
if (res.data.code == 200) {
navigate.reset({
index: 1,
routes: [{name: AUTHEN}],
});
} else {
Alert.alert(res.data.message);
}
}
};
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<HeaderBack title={'Thay đổi mật khẩu mới'} /> <HeaderBack title={'Thay đổi mật khẩu mới'} />
...@@ -45,9 +83,7 @@ const NewPassword = (props) => { ...@@ -45,9 +83,7 @@ const NewPassword = (props) => {
</View> </View>
<View style={styles.footer}> <View style={styles.footer}>
<TouchableOpacity <TouchableOpacity onPress={changePass} style={styles.btn}>
onPress={() => console.log('Hello')}
style={styles.btn}>
<Text style={styles.txtBtn}>Cp nht</Text> <Text style={styles.txtBtn}>Cp nht</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
...@@ -123,4 +159,10 @@ const styles = StyleSheet.create({ ...@@ -123,4 +159,10 @@ const styles = StyleSheet.create({
}, },
}); });
export default NewPassword; const mapStateToProps = (state) => {
return {};
};
export default connect(mapStateToProps, {showLoading, hideLoading})(
NewPassword,
);
import React from 'react'; import React, {useState} from 'react';
import {View, Text} from 'react-native'; import {View, Text, Switch} from 'react-native';
import HeaderBack from '../../components/Header/HeaderBack';
const SettingView = (props) => { const SettingView = (props) => {
const [isEnabled, setIsEnabled] = useState(false);
const toggleSwitch = () => setIsEnabled((previousState) => !previousState);
return ( return (
<View> <View style={{flex: 1}}>
<Text>SettingView screen</Text> <HeaderBack title={'Cài đặt'} />
<View style={{flexDirection: 'row'}}></View>
<Switch
trackColor={{false: '#767577', true: '#1C6AF6'}}
// thumbColor={isEnabled ? '#f5dd4b' : '#f4f3f4'}
ios_backgroundColor="#767577"
onValueChange={toggleSwitch}
value={isEnabled}
/>
<Text>SettingView 1 screen</Text>
</View> </View>
); );
}; };
......
...@@ -16,3 +16,18 @@ export const logoutApi = async (body) => ...@@ -16,3 +16,18 @@ export const logoutApi = async (body) =>
PostData('http://api.dcvinvest.com/api/auth/logout', body) PostData('http://api.dcvinvest.com/api/auth/logout', body)
.then((res) => res) .then((res) => res)
.catch((err) => err); .catch((err) => err);
export const getOTPApi = async (body) =>
PostLogin(url.urlGetOTP, body)
.then((res) => res)
.catch((err) => err);
export const verifyOTPApi = async (body) =>
PostLogin(url.urlVerifyOTP, body)
.then((res) => res)
.catch((err) => err);
export const forgotPasswordApi = async (body) =>
PostLogin(url.urlForgotPassword, body)
.then((res) => res)
.catch((err) => err);
const root = 'http://api.dcvinvest.com/'; const root = 'http://api.dcvinvest.com/';
export default { export default {
urllogin: root + '/api/auth/customer-login', urllogin: root + 'api/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',
urlVerifyOTP: root + 'api/auth/customer-verify-otp',
urlForgotPassword: root + 'api/auth/customer-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