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
+7 -3
View File
@@ -3,7 +3,10 @@ export const shared = {
save: 'Save', save: 'Save',
errorTitle: 'Error', errorTitle: 'Error',
successTitle: 'Success', successTitle: 'Success',
warning: 'Warning' warning: 'Warning',
incorrectPassword: 'Password incorrect',
incorrectPasswordMessage: 'That password is incorrect.',
tryAgain: 'Try again'
} }
export const settings = { export const settings = {
@@ -52,8 +55,9 @@ export const settings = {
passwordSettings: { passwordSettings: {
title: 'App password', title: 'App password',
explainerDisabled: "Encrypt the app's database with a password. You have to enter the password every time the app is started.", explainerDisabled: "Encrypt the app's database with a password. You have to enter the password every time the app is started.",
explainerEnabled: "Your app's data is encrypted with your password.", explainerEnabled: "Password protection and database encryption is currently enabled",
deletePassword: "Delete password" deletePassword: "Delete password",
enterCurrent: "Please enter your current password",
} }
} }
+15 -11
View File
@@ -1,17 +1,19 @@
import React, { Component } from 'react' 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 nodejs from 'nodejs-mobile-react-native'
import { AppText } from './app-text' import { AppText } from './app-text'
import { hasEncryptionObservable } from '../local-storage' import { hasEncryptionObservable } from '../local-storage'
import styles from '../styles' import styles from '../styles'
import { passwordPrompt } from './labels' import { passwordPrompt, shared } from './labels'
import { openDbConnection, requestHash, deleteDbAndOpenNew, openDb } from '../db' import { openDbConnection, requestHash, deleteDbAndOpenNew, openDb } from '../db'
import App from './app' import App from './app'
export default class PasswordPrompt extends Component { export default class PasswordPrompt extends Component {
constructor() { constructor() {
super() super()
this.state = {} this.state = {
password: null
}
hasEncryptionObservable.once((hasEncryption) => { hasEncryptionObservable.once((hasEncryption) => {
if (hasEncryption) { if (hasEncryption) {
this.setState({showPasswordPrompt: true}) this.setState({showPasswordPrompt: true})
@@ -36,7 +38,14 @@ export default class PasswordPrompt extends Component {
await openDb({hash: msg.message, persistConnection: true }) await openDb({hash: msg.message, persistConnection: true })
this.setState({ showApp: true }) this.setState({ showApp: true })
} catch (err) { } 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 ? {this.state.showApp ?
<App password={this.state.password}/> <App password={this.state.password}/>
: :
<View> <View style={styles.passwordPrompt}>
{this.state.showPasswordPrompt && {this.state.showPasswordPrompt &&
<View> <View>
<TextInput <TextInput
onChangeText={val => this.setState({password: val})} onChangeText={val => this.setState({password: val})}
style={{ style={styles.passwordField}
borderWidth: 1,
borderColor: 'grey',
margin: 5
}}
/> />
<TouchableOpacity <TouchableOpacity
style={styles.settingsButton} style={styles.settingsButton}
@@ -71,7 +76,6 @@ export default class PasswordPrompt extends Component {
{ passwordPrompt.title } { passwordPrompt.title }
</AppText> </AppText>
</TouchableOpacity> </TouchableOpacity>
{this.state.wrongPassword && <AppText>Wrong PAssword!</AppText>}
<TouchableOpacity <TouchableOpacity
style={styles.settingsButton} style={styles.settingsButton}
onPress={async () => { onPress={async () => {
+37 -14
View File
@@ -2,7 +2,8 @@ import React, { Component } from 'react'
import { import {
View, View,
TouchableOpacity, TouchableOpacity,
TextInput TextInput,
Alert
} from 'react-native' } from 'react-native'
import nodejs from 'nodejs-mobile-react-native' import nodejs from 'nodejs-mobile-react-native'
import { AppText } from '../app-text' import { AppText } from '../app-text'
@@ -10,14 +11,16 @@ import {
hasEncryptionObservable hasEncryptionObservable
} from '../../local-storage' } from '../../local-storage'
import styles from '../../styles/index' import styles from '../../styles/index'
import { settings as labels } from '../labels' import { settings as labels, shared } from '../labels'
import { requestHash, openDb } from '../../db' import { requestHash, openDb } from '../../db'
export default class PasswordSetting extends Component { export default class PasswordSetting extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
enabled: hasEncryptionObservable.value enabled: hasEncryptionObservable.value,
currentPassword: null,
enteringCurrentPassword: false
} }
nodejs.start('main.js') nodejs.start('main.js')
@@ -38,11 +41,25 @@ export default class PasswordSetting extends Component {
try { try {
await openDb({ hash: msg.message, persistConnection: false }) await openDb({ hash: msg.message, persistConnection: false })
this.setState({ this.setState({
wrongPassword: false, enteringCurrentPassword: false
enterOldPassword: false
}) })
} catch (err) { } catch (err) {
this.setState({wrongPassword: true}) Alert.alert(
shared.incorrectPassword,
shared.incorrectPasswordMessage,
[{
text: shared.cancel,
onPress: () => {
this.setState({
enteringCurrentPassword: false,
currentPassword: null
})
}
}, {
text: shared.tryAgain,
onPress: () => this.setState({currentPassword: null})
}]
)
} }
} }
@@ -57,21 +74,27 @@ export default class PasswordSetting extends Component {
: :
<AppText>{labels.passwordSettings.explainerDisabled}</AppText> <AppText>{labels.passwordSettings.explainerDisabled}</AppText>
} }
{this.state.enterOldPassword && {this.state.enteringCurrentPassword &&
<View>
<TextInput <TextInput
style={{ style={styles.passwordField}
backgroundColor: 'white', onChangeText={val => {
this.setState({
currentPassword: val,
wrongPassword: false
})
}} }}
onChangeText={val => this.setState({ oldPassword: val })} value={this.state.currentPassword}
placeholder={labels.passwordSettings.enterCurrent}
/> />
</View>
} }
{this.state.wrongPassword && <AppText>Wrong PAssword!</AppText>}
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {
if (!this.state.enterOldPassword) { if (!this.state.enteringCurrentPassword) {
this.setState({ enterOldPassword: true }) this.setState({ enteringCurrentPassword: true })
} else { } else {
requestHash(this.state.oldPassword) requestHash(this.state.currentPassword)
} }
}} }}
style={styles.settingsButton}> style={styles.settingsButton}>
+12 -1
View File
@@ -249,6 +249,17 @@ export default StyleSheet.create({
fontSize: 20, fontSize: 20,
color: secondaryColor, color: secondaryColor,
marginTop: 1 marginTop: 1
},
passwordField: {
backgroundColor: 'white',
padding: 10,
marginTop: 10,
marginHorizontal: 10
},
passwordPrompt: {
backgroundColor: 'lightgrey',
flex: 1,
padding: 30
} }
}) })
@@ -268,6 +279,6 @@ export const iconStyles = {
color: fontOnPrimaryColor color: fontOnPrimaryColor
}, },
menuIconInactive: { menuIconInactive: {
color: 'lightgrey' color: 'lightgrey',
}, },
} }