Introduce password prompt page and save encryption flag
This commit is contained in:
@@ -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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AppRegistry } from 'react-native'
|
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
@@ -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()
|
export const tempReminderObservable = Observable()
|
||||||
setObvWithInitValue('tempReminder', tempReminderObservable, {
|
setObvWithInitValue('tempReminder', tempReminderObservable, {
|
||||||
enabled: false
|
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) {
|
async function setObvWithInitValue(key, obv, defaultValue) {
|
||||||
const result = await AsyncStorage.getItem(key)
|
const result = await AsyncStorage.getItem(key)
|
||||||
let value
|
let value
|
||||||
@@ -35,13 +47,3 @@ async function setObvWithInitValue(key, obv, defaultValue) {
|
|||||||
}
|
}
|
||||||
obv.set(value)
|
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)
|
|
||||||
}
|
|
||||||
@@ -5,11 +5,18 @@ const bcryptjs = require('bcryptjs')
|
|||||||
|
|
||||||
rnBridge.channel.on('message', (msg) => {
|
rnBridge.channel.on('message', (msg) => {
|
||||||
msg = JSON.parse(msg)
|
msg = JSON.parse(msg)
|
||||||
if (msg.type === 'request-hash') {
|
if (msg.type === 'request-password-hash') {
|
||||||
const hash = bcryptjs.hashSync(msg.message, 10)
|
const hash = bcryptjs.hashSync(msg.message, 10)
|
||||||
rnBridge.channel.send(JSON.stringify({
|
rnBridge.channel.send(JSON.stringify({
|
||||||
type: 'hash',
|
type: 'hash',
|
||||||
message: 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)
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user