Add wrapper for password screen and logged-in app
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
import nodejs from 'nodejs-mobile-react-native'
|
||||||
|
import App from './app'
|
||||||
|
import PasswordPrompt from './password-prompt'
|
||||||
|
|
||||||
|
export default class AppWrapper extends Component {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.state = {}
|
||||||
|
nodejs.start('main.js')
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<View style={{ flex: 1 }}>
|
||||||
|
{this.state.showApp ?
|
||||||
|
<App/>
|
||||||
|
:
|
||||||
|
<PasswordPrompt
|
||||||
|
onCorrectPassword={() => this.setState({showApp: true})}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,25 +5,25 @@ 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, shared } from './labels'
|
import { passwordPrompt, shared } from './labels'
|
||||||
import { openDbConnection, requestHash, deleteDbAndOpenNew, openDb } from '../db'
|
import { requestHash, deleteDbAndOpenNew, openDb } from '../db'
|
||||||
import App from './app'
|
|
||||||
|
|
||||||
export default class PasswordPrompt extends Component {
|
export default class PasswordPrompt extends Component {
|
||||||
constructor() {
|
constructor(props) {
|
||||||
super()
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
password: null
|
password: null
|
||||||
}
|
}
|
||||||
hasEncryptionObservable.once((hasEncryption) => {
|
hasEncryptionObservable.once(async hasEncryption => {
|
||||||
|
hasEncryption = JSON.parse(hasEncryption)
|
||||||
if (hasEncryption) {
|
if (hasEncryption) {
|
||||||
this.setState({showPasswordPrompt: true})
|
this.setState({showPasswordPrompt: true})
|
||||||
} else {
|
} else {
|
||||||
openDbConnection('something-wrong')
|
await openDb({persistConnection: true})
|
||||||
this.setState({showApp: true})
|
console.log(this.props)
|
||||||
|
this.props.onCorrectPassword()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
nodejs.start('main.js')
|
|
||||||
nodejs.channel.addListener(
|
nodejs.channel.addListener(
|
||||||
'message',
|
'message',
|
||||||
this.passHashToDb,
|
this.passHashToDb,
|
||||||
@@ -35,8 +35,8 @@ export default class PasswordPrompt extends Component {
|
|||||||
msg = JSON.parse(msg)
|
msg = JSON.parse(msg)
|
||||||
if (msg.type != 'sha512') return
|
if (msg.type != 'sha512') return
|
||||||
try {
|
try {
|
||||||
|
console.log('password prompt opening db')
|
||||||
await openDb({hash: msg.message, persistConnection: true })
|
await openDb({hash: msg.message, persistConnection: true })
|
||||||
this.setState({ showApp: true })
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
shared.incorrectPassword,
|
shared.incorrectPassword,
|
||||||
@@ -46,7 +46,9 @@ export default class PasswordPrompt extends Component {
|
|||||||
onPress: () => this.setState({password: null})
|
onPress: () => this.setState({password: null})
|
||||||
}]
|
}]
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
this.setState({ showApp: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@@ -55,40 +57,34 @@ export default class PasswordPrompt extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<View style={styles.passwordPrompt}>
|
||||||
{this.state.showApp ?
|
{this.state.showPasswordPrompt &&
|
||||||
<App password={this.state.password}/>
|
<View>
|
||||||
:
|
<TextInput
|
||||||
<View style={styles.passwordPrompt}>
|
onChangeText={val => this.setState({ password: val })}
|
||||||
{this.state.showPasswordPrompt &&
|
style={styles.passwordField}
|
||||||
<View>
|
/>
|
||||||
<TextInput
|
<TouchableOpacity
|
||||||
onChangeText={val => this.setState({password: val})}
|
style={styles.settingsButton}
|
||||||
style={styles.passwordField}
|
onPress={() => {
|
||||||
/>
|
requestHash(this.state.password)
|
||||||
<TouchableOpacity
|
}}
|
||||||
style={styles.settingsButton}
|
>
|
||||||
onPress={() => {
|
<AppText style={styles.settingsButtonText}>
|
||||||
requestHash(this.state.password)
|
{passwordPrompt.title}
|
||||||
}}
|
</AppText>
|
||||||
>
|
</TouchableOpacity>
|
||||||
<AppText style={styles.settingsButtonText}>
|
<TouchableOpacity
|
||||||
{ passwordPrompt.title }
|
style={styles.settingsButton}
|
||||||
</AppText>
|
onPress={async () => {
|
||||||
</TouchableOpacity>
|
await deleteDbAndOpenNew()
|
||||||
<TouchableOpacity
|
this.setState({ showApp: true })
|
||||||
style={styles.settingsButton}
|
}}
|
||||||
onPress={async () => {
|
>
|
||||||
await deleteDbAndOpenNew()
|
<AppText style={styles.settingsButtonText}>
|
||||||
this.setState({showApp: true})
|
{'Delete old db and make unencrypted new'}
|
||||||
}}
|
</AppText>
|
||||||
>
|
</TouchableOpacity>
|
||||||
<AppText style={styles.settingsButtonText}>
|
|
||||||
{'Delete old db and make unencrypted new'}
|
|
||||||
</AppText>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AppRegistry } from 'react-native'
|
import { AppRegistry } from 'react-native'
|
||||||
import PasswordPrompt from './components/password-prompt'
|
import AppWrapper from './components/app-wrapper'
|
||||||
|
|
||||||
AppRegistry.registerComponent('home', () => PasswordPrompt)
|
AppRegistry.registerComponent('home', () => AppWrapper)
|
||||||
Reference in New Issue
Block a user