Commit 79ae6cb6 by Tonk

add change password success and error modal

parent fb137040
...@@ -7,7 +7,7 @@ import { Icon } from 'native-base'; ...@@ -7,7 +7,7 @@ import { Icon } from 'native-base';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
borderBottomWidth: 1, borderBottomWidth: 1,
borderBottomColor: color.lightGrey, borderBottomColor: '#d0d0d6',
}, },
icon: { icon: {
fontSize: 20, fontSize: 20,
......
...@@ -20,12 +20,12 @@ class Login extends Component { ...@@ -20,12 +20,12 @@ class Login extends Component {
<Field <Field
hideCheckmark hideCheckmark
forwardRef forwardRef
ref={c => (this.username = c)} ref={c => (this.email = c)}
refField="username" refField="email"
returnKeyType="next" returnKeyType="next"
onSubmitEditing={() => this.password.getRenderedComponent().refs.password.focus()} onSubmitEditing={() => this.password.getRenderedComponent().refs.password.focus()}
name="username" name="email"
keyboardType="default" keyboardType="email-address"
component={Input} component={Input}
validate={[required]} validate={[required]}
placeholder={'E-mail'} placeholder={'E-mail'}
......
...@@ -4,7 +4,11 @@ import IoniconsHeaderButton from '../../../components/IoniconsHeaderButton'; ...@@ -4,7 +4,11 @@ import IoniconsHeaderButton from '../../../components/IoniconsHeaderButton';
import ChangePasswordForm from '../../../components/Form/ChangePasswordForm'; import ChangePasswordForm from '../../../components/Form/ChangePasswordForm';
import app from '../../../firebase'; import app from '../../../firebase';
import firebase from 'firebase/app'; import firebase from 'firebase/app';
import { Alert } from 'react-native'; import Modal from 'react-native-modalbox';
import { Button, Text, View } from 'native-base';
import { width, height } from '../../../constants/Layout';
import { theme, color } from '../../../constants/Styles';
import { StyleSheet } from 'react-native';
export default class ChangePasswordScreen extends React.Component { export default class ChangePasswordScreen extends React.Component {
static navigationOptions = ({ navigation }) => { static navigationOptions = ({ navigation }) => {
...@@ -18,6 +22,11 @@ export default class ChangePasswordScreen extends React.Component { ...@@ -18,6 +22,11 @@ export default class ChangePasswordScreen extends React.Component {
}; };
}; };
state = {
changeSuccessModal: false,
errorModal: false,
};
reauthenticate = currentPassword => { reauthenticate = currentPassword => {
var user = app.auth().currentUser; var user = app.auth().currentUser;
var cred = firebase.auth.EmailAuthProvider.credential(user.email, currentPassword); var cred = firebase.auth.EmailAuthProvider.credential(user.email, currentPassword);
...@@ -29,20 +38,16 @@ export default class ChangePasswordScreen extends React.Component { ...@@ -29,20 +38,16 @@ export default class ChangePasswordScreen extends React.Component {
var user = app.auth().currentUser; var user = app.auth().currentUser;
try { try {
user.updatePassword(newPassword); user.updatePassword(newPassword);
Alert.alert('Password Changed', 'Go back to login', [ this.setState({
{ changeSuccessModal: true,
text: 'OK', });
onPress: async () => {
this.props.navigation.navigate('Login');
await AsyncStorage.clear();
},
},
]);
} catch (error) { } catch (error) {
this.setState({ errorModal: true });
console.log(error); console.log(error);
} }
}) })
.catch(error => { .catch(error => {
this.setState({ errorModal: true });
console.log(error); console.log(error);
}); });
}; };
...@@ -53,7 +58,62 @@ export default class ChangePasswordScreen extends React.Component { ...@@ -53,7 +58,62 @@ export default class ChangePasswordScreen extends React.Component {
console.log(error); console.log(error);
} }
}; };
logout = async () => {
this.setState({ changeSuccessModal: false });
this.props.navigation.navigate('Login');
await AsyncStorage.clear();
};
render() { render() {
return <ChangePasswordForm onSubmit={this.handleSave} />; const { changeSuccessModal, errorModal } = this.state;
return (
<>
<ChangePasswordForm onSubmit={this.handleSave} />
<Modal
isOpen={changeSuccessModal}
style={styles.modalContainer}
swipeToClose={false}
backdropPressToClose={false}
coverScreen
>
<View style={{ alignItems: 'center' }}>
<Text style={[theme.smallTitle, theme.textDark]}>Password Changed!</Text>
<Text style={[theme.normalText, theme.mt1]}>Go back to Login</Text>
</View>
<Button full style={styles.btn} onPress={this.logout}>
<Text>OK</Text>
</Button>
</Modal>
<Modal
isOpen={errorModal}
style={styles.modalContainer}
swipeToClose={false}
backdropPressToClose={false}
coverScreen
>
<View style={{ alignItems: 'center' }}>
<Text style={[theme.smallTitle, theme.textDark]}>Password Incorrect!</Text>
<Text style={[theme.normalText, theme.mt1]}>Please check your current password</Text>
</View>
<Button full style={styles.btn} onPress={() => this.setState({ errorModal: false })}>
<Text>OK</Text>
</Button>
</Modal>
</>
);
} }
} }
const styles = StyleSheet.create({
modalContainer: {
width: width * 0.9,
height: height / 4,
borderRadius: 20,
alignItems: 'center',
justifyContent: 'space-evenly',
},
btn: {
backgroundColor: color.primary,
marginHorizontal: 20,
borderRadius: 100,
},
});
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Text, Left, Right, Row, CheckBox } from 'native-base'; import { Text, CheckBox } from 'native-base';
import { theme, color } from '../../constants/Styles'; import { theme, color } from '../../constants/Styles';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
import LoginForm from '../../components/Form/LoginForm'; import LoginForm from '../../components/Form/LoginForm';
...@@ -18,9 +18,9 @@ export default class LoginScreen extends Component { ...@@ -18,9 +18,9 @@ export default class LoginScreen extends Component {
}; };
handleSignIn = async values => { handleSignIn = async values => {
const { username, password } = values; const { email, password } = values;
try { try {
await app.auth().signInWithEmailAndPassword(username, password); await app.auth().signInWithEmailAndPassword(email, password);
await this.success(); await this.success();
} catch (error) { } catch (error) {
alert(error); alert(error);
......
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