Added forgot pin feature

This commit is contained in:
Mustafa Buyukcelebi 2019-03-12 16:18:55 +03:00
parent b0377bb332
commit 6c4b14ca68
4 changed files with 84 additions and 22 deletions

View File

@ -144,6 +144,7 @@
"invalid_pincode": "Invalid PIN code, please check and try again.",
"remove_alert": "Are you sure you want to remove?",
"clear_alert": "Are you sure you want to clear?",
"clear_user_alert": "Are you sure you want to clear all user data?",
"clear": "Clear",
"cancel": "Cancel",
"delete": "Delete",

View File

@ -176,8 +176,7 @@ export const updateUserData = userData => new Promise((resolve, reject) => {
export const removeUserData = username => new Promise((resolve, reject) => {
try {
const account = realm.objects(USER_SCHEMA).filtered('username = $0', username);
const account = realm.objects(USER_SCHEMA).filtered('username = $0', username)
if (Array.from(account).length > 0) {
realm.write(() => {
realm.delete(account);
@ -191,6 +190,21 @@ export const removeUserData = username => new Promise((resolve, reject) => {
}
});
export const removeAllUserData = () => new Promise((resolve, reject) => {
try {
const accounts = realm.objects(USER_SCHEMA);
const scAccount = realm.objects(SC_ACCOUNTS);
realm.write(() => {
realm.delete(accounts);
realm.delete(scAccount);
resolve();
});
} catch (error) {
reject(error);
}
});
// // TODO: This method deleting ALL users. This should delete just a user.
// export const removeUserData = () => new Promise((resolve, reject) => {
// setAuthStatus({ isLoggedIn: false }).then(() => {

View File

@ -10,11 +10,19 @@ import {
verifyPinCode,
updatePinCode,
} from '../../../providers/steem/auth';
import { closePinCodeModal } from '../../../redux/actions/applicationActions';
import { getExistUser, setExistUser, getUserDataWithUsername } from '../../../realm/realm';
import { closePinCodeModal, login, logoutDone } from '../../../redux/actions/applicationActions';
import {
getExistUser,
setExistUser,
getUserDataWithUsername,
removeAllUserData,
removePinCode,
setAuthStatus,
} from '../../../realm/realm';
import {
updateCurrentAccount,
setPinCode as savePinCode,
removeOtherAccount,
} from '../../../redux/actions/accountAction';
import { getUser } from '../../../providers/steem/dsteem';
@ -112,11 +120,14 @@ class PinCodeContainer extends Component {
resolve();
})
.catch((err) => {
Alert.alert(intl.formatMessage({
id: 'alert.warning',
}), intl.formatMessage({
id: err.message,
}));
Alert.alert(
intl.formatMessage({
id: 'alert.warning',
}),
intl.formatMessage({
id: err.message,
}),
);
reject(err);
});
}
@ -154,12 +165,7 @@ class PinCodeContainer extends Component {
_verifyPinCode = pin => new Promise((resolve, reject) => {
const {
currentAccount,
dispatch,
accessToken,
navigateTo,
navigation,
intl,
currentAccount, dispatch, accessToken, navigateTo, navigation, intl,
} = this.props;
// If the user is exist, we are just checking to pin and navigating to home screen
@ -183,11 +189,14 @@ class PinCodeContainer extends Component {
}
})
.catch((err) => {
Alert.alert(intl.formatMessage({
id: 'alert.warning',
}), intl.formatMessage({
id: err.message,
}));
Alert.alert(
intl.formatMessage({
id: 'alert.warning',
}),
intl.formatMessage({
id: err.message,
}),
);
reject(err);
});
});
@ -264,6 +273,42 @@ class PinCodeContainer extends Component {
}, 1000);
};
_handleForgotButton = () => {
const { intl } = this.props;
Alert.alert(
intl.formatMessage({
id: 'alert.warning',
}),
intl.formatMessage({
id: 'alert.clear_user_alert',
}),
[
{ text: intl.formatMessage({ id: 'alert.clear' }), onPress: () => this._forgotPinCode() },
{ text: intl.formatMessage({ id: 'alert.cancel' }), style: 'destructive' },
]
);
};
_forgotPinCode = async () => {
const { otherAccounts, dispatch } = this.props;
await removeAllUserData()
.then(async () => {
dispatch(updateCurrentAccount({}));
dispatch(login(false));
removePinCode();
setAuthStatus({ isLoggedIn: false });
setExistUser(false);
if (otherAccounts.length > 0) {
otherAccounts.map(item => dispatch(removeOtherAccount(item.username)));
}
dispatch(logoutDone());
dispatch(closePinCodeModal());
})
.catch(() => {});
};
render() {
const { currentAccount, intl, isReset } = this.props;
const { informationText, isExistUser } = this.state;
@ -274,6 +319,7 @@ class PinCodeContainer extends Component {
showForgotButton={isExistUser}
username={currentAccount.name}
intl={intl}
handleForgotButton={() => this._handleForgotButton()}
{...this.props}
/>
);
@ -283,6 +329,7 @@ class PinCodeContainer extends Component {
const mapStateToProps = state => ({
currentAccount: state.account.currentAccount,
applicationPinCode: state.account.pin,
otherAccounts: state.account.otherAccounts,
});
export default injectIntl(connect(mapStateToProps)(PinCodeContainer));

View File

@ -51,7 +51,7 @@ class PinCodeScreen extends PureComponent {
render() {
const {
informationText, showForgotButton, username, intl,
informationText, showForgotButton, username, intl, handleForgotButton,
} = this.props;
const { pin, loading } = this.state;
@ -73,7 +73,7 @@ class PinCodeScreen extends PureComponent {
<NumericKeyboard onPress={this._handleKeyboardOnPress} />
</View>
{showForgotButton ? (
<TouchableOpacity style={styles.forgotButtonView}>
<TouchableOpacity onPress={() => handleForgotButton()} style={styles.forgotButtonView}>
<Text style={styles.forgotButtonText}>
{intl.formatMessage({
id: 'pincode.forgot_text',