diff --git a/components/password-prompt.js b/components/password-prompt.js new file mode 100644 index 0000000..c7d0644 --- /dev/null +++ b/components/password-prompt.js @@ -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 ( + + {this.state.showApp ? + + : + + {this.state.showPasswordPrompt && + + this.setState({password: val})} + /> + { + + }} + style={styles.settingsButton}> + + {labels.export.button} + + + {this.state.wrongPassword && Wrong PAssword!} + + } + + } + + ) + } +} \ No newline at end of file diff --git a/index.js b/index.js index 25e2616..b17ba73 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ import { AppRegistry } from 'react-native' -import App from './components/app' +import PasswordPrompt from './components/password-prompt' -AppRegistry.registerComponent('home', () => App) \ No newline at end of file +AppRegistry.registerComponent('home', () => PasswordPrompt) \ No newline at end of file diff --git a/local-storage/index.js b/local-storage/index.js index 83f50e5..5fffb42 100644 --- a/local-storage/index.js +++ b/local-storage/index.js @@ -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 @@ -34,14 +46,4 @@ async function setObvWithInitValue(key, obv, defaultValue) { value = 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) } \ No newline at end of file diff --git a/nodejs-assets/nodejs-project/main.js b/nodejs-assets/nodejs-project/main.js index 1dc6cf8..465e56c 100644 --- a/nodejs-assets/nodejs-project/main.js +++ b/nodejs-assets/nodejs-project/main.js @@ -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) + })) } }) \ No newline at end of file