Implement wrong-password-try-again? flow

This commit is contained in:
Julia Friesel
2018-09-14 07:34:28 +02:00
parent b153f8d0ff
commit 8da8523558
4 changed files with 74 additions and 32 deletions
+15 -11
View File
@@ -1,17 +1,19 @@
import React, { Component } from 'react'
import { View, TextInput, TouchableOpacity } from 'react-native'
import { View, TextInput, TouchableOpacity, Alert } from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import { AppText } from './app-text'
import { hasEncryptionObservable } from '../local-storage'
import styles from '../styles'
import { passwordPrompt } from './labels'
import { passwordPrompt, shared } from './labels'
import { openDbConnection, requestHash, deleteDbAndOpenNew, openDb } from '../db'
import App from './app'
export default class PasswordPrompt extends Component {
constructor() {
super()
this.state = {}
this.state = {
password: null
}
hasEncryptionObservable.once((hasEncryption) => {
if (hasEncryption) {
this.setState({showPasswordPrompt: true})
@@ -36,7 +38,14 @@ export default class PasswordPrompt extends Component {
await openDb({hash: msg.message, persistConnection: true })
this.setState({ showApp: true })
} catch (err) {
this.setState({ wrongPassword: true })
Alert.alert(
shared.incorrectPassword,
shared.incorrectPasswordMessage,
[{
text: shared.tryAgain,
onPress: () => this.setState({password: null})
}]
)
}
}
@@ -50,16 +59,12 @@ export default class PasswordPrompt extends Component {
{this.state.showApp ?
<App password={this.state.password}/>
:
<View>
<View style={styles.passwordPrompt}>
{this.state.showPasswordPrompt &&
<View>
<TextInput
onChangeText={val => this.setState({password: val})}
style={{
borderWidth: 1,
borderColor: 'grey',
margin: 5
}}
style={styles.passwordField}
/>
<TouchableOpacity
style={styles.settingsButton}
@@ -71,7 +76,6 @@ export default class PasswordPrompt extends Component {
{ passwordPrompt.title }
</AppText>
</TouchableOpacity>
{this.state.wrongPassword && <AppText>Wrong PAssword!</AppText>}
<TouchableOpacity
style={styles.settingsButton}
onPress={async () => {