Introduce password prompt page and save encryption flag

This commit is contained in:
Julia Friesel
2018-09-11 18:06:54 +02:00
parent 3e3cef8769
commit 3d61459f30
4 changed files with 90 additions and 13 deletions
+68
View File
@@ -0,0 +1,68 @@
import React, { Component } from 'react'
import { View, TextInput, TouchableOpacity } 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 labels from './labels'
import { openDbConnection } from '../db'
import App from './app'
export default class PasswordPrompt extends Component {
constructor() {
super()
this.state = {}
hasEncryptionObservable.once((hasEncryption) => {
if (hasEncryption) {
this.setState({showPasswordPrompt: true})
} else {
openDbConnection()
this.setState({showApp: true})
}
})
nodejs.channel.addListener(
'message',
msg => {
msg = JSON.parse(msg)
if (msg.type === 'password-check-result') {
if (msg.message) {
this.setState({showApp: true})
} else {
this.setState({wrongPassword: true})
}
}
},
this
)
}
render() {
return (
<View style={{ flex: 1 }}>
{this.state.showApp ?
<App password={this.state.password}/>
:
<View>
{this.state.showPasswordPrompt &&
<View>
<TextInput
onChangeText={val => this.setState({password: val})}
/>
<TouchableOpacity
onPress={async () => {
}}
style={styles.settingsButton}>
<AppText style={styles.settingsButtonText}>
{labels.export.button}
</AppText>
</TouchableOpacity>
{this.state.wrongPassword && <AppText>Wrong PAssword!</AppText>}
</View>
}
</View>
}
</View>
)
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
import { AppRegistry } from 'react-native'
import App from './components/app'
import PasswordPrompt from './components/password-prompt'
AppRegistry.registerComponent('home', () => App)
AppRegistry.registerComponent('home', () => PasswordPrompt)
+12 -10
View File
@@ -19,12 +19,24 @@ scaleObservable((scale) => {
}
})
export async function saveTempScale(scale) {
await AsyncStorage.setItem('tempScale', JSON.stringify(scale))
scaleObservable.set(scale)
}
export const tempReminderObservable = Observable()
setObvWithInitValue('tempReminder', tempReminderObservable, {
enabled: false
})
export async function saveTempReminder(reminder) {
await AsyncStorage.setItem('tempReminder', JSON.stringify(reminder))
tempReminderObservable.set(reminder)
}
export const hasEncryptionObservable = Observable()
setObvWithInitValue('hasEncryption', hasEncryptionObservable, false)
async function setObvWithInitValue(key, obv, defaultValue) {
const result = await AsyncStorage.getItem(key)
let value
@@ -35,13 +47,3 @@ async function setObvWithInitValue(key, obv, defaultValue) {
}
obv.set(value)
}
export async function saveTempScale(scale) {
await AsyncStorage.setItem('tempScale', JSON.stringify(scale))
scaleObservable.set(scale)
}
export async function saveTempReminder(reminder) {
await AsyncStorage.setItem('tempReminder', JSON.stringify(reminder))
tempReminderObservable.set(reminder)
}
+8 -1
View File
@@ -5,11 +5,18 @@ const bcryptjs = require('bcryptjs')
rnBridge.channel.on('message', (msg) => {
msg = JSON.parse(msg)
if (msg.type === 'request-hash') {
if (msg.type === 'request-password-hash') {
const hash = bcryptjs.hashSync(msg.message, 10)
rnBridge.channel.send(JSON.stringify({
type: 'hash',
message: hash
}))
} else if (msg.type === 'request-SHA512') {
// do the thing
} else if (msg.type === 'check-password') {
rnBridge.channel.send(JSON.stringify({
type: 'password-check-result',
message: bcryptjs.compareSync(msg.message.password, msg.message.hash)
}))
}
})