Take user password and try to open db
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import React, { Component } from 'react'
|
||||
import { View, BackHandler } from 'react-native'
|
||||
import nodejs from 'nodejs-mobile-react-native'
|
||||
import Header from './header'
|
||||
import Menu from './menu'
|
||||
import Home from './home'
|
||||
@@ -12,7 +11,6 @@ import Settings from './settings'
|
||||
import Stats from './stats'
|
||||
import {headerTitles as titles} from './labels'
|
||||
import setupNotifications from '../lib/notifications'
|
||||
import { encrypt } from '../db'
|
||||
|
||||
const isSymptomView = name => Object.keys(symptomViews).indexOf(name) > -1
|
||||
|
||||
@@ -24,15 +22,6 @@ export default class App extends Component {
|
||||
}
|
||||
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonPress)
|
||||
setupNotifications(this.navigate)
|
||||
nodejs.start('main.js')
|
||||
nodejs.channel.addListener(
|
||||
'message',
|
||||
msg => {
|
||||
msg = JSON.parse(msg)
|
||||
encrypt(msg.message)
|
||||
},
|
||||
this
|
||||
)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
@@ -90,4 +90,8 @@ export const bleedingPrediction = {
|
||||
predictionStarted1DayLeft: 'Your period is likely to start today or tomorrow.',
|
||||
predictionStartedNoDaysLeft: 'Your period is likely to start today.',
|
||||
predictionInPast: (startDate, endDate) => `Based on your documented data, your period was likely to start between ${startDate} and ${endDate}.`
|
||||
}
|
||||
|
||||
export const passwordPrompt = {
|
||||
title: 'Log in'
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
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 { AppText } from './app-text'
|
||||
import { hasEncryptionObservable } from '../local-storage'
|
||||
import styles from '../styles'
|
||||
import labels from './labels'
|
||||
import { openDbConnection } from '../db'
|
||||
import { passwordPrompt } from './labels'
|
||||
import { openDbConnection, requestHash } from '../db'
|
||||
import App from './app'
|
||||
|
||||
export default class PasswordPrompt extends Component {
|
||||
@@ -16,18 +16,24 @@ export default class PasswordPrompt extends Component {
|
||||
if (hasEncryption) {
|
||||
this.setState({showPasswordPrompt: true})
|
||||
} else {
|
||||
openDbConnection()
|
||||
openDbConnection('something-wrong')
|
||||
this.setState({showApp: true})
|
||||
}
|
||||
})
|
||||
nodejs.start('main.js')
|
||||
nodejs.channel.addListener(
|
||||
'message',
|
||||
msg => {
|
||||
async msg => {
|
||||
msg = JSON.parse(msg)
|
||||
if (msg.type === 'password-check-result') {
|
||||
if (msg.message) {
|
||||
this.setState({showApp: true})
|
||||
} else {
|
||||
if (msg.type === 'sha512') {
|
||||
const key = new Int8Array(64)
|
||||
for (let i = 0; i < msg.message.length; i++) {
|
||||
key[i] = msg.message.charCodeAt(i)
|
||||
}
|
||||
try {
|
||||
await openDbConnection(key)
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
this.setState({wrongPassword: true})
|
||||
}
|
||||
}
|
||||
@@ -47,14 +53,20 @@ export default class PasswordPrompt extends Component {
|
||||
<View>
|
||||
<TextInput
|
||||
onChangeText={val => this.setState({password: val})}
|
||||
style={{
|
||||
borderWidth: 1,
|
||||
borderColor: 'grey',
|
||||
margin: 5
|
||||
}}
|
||||
/>
|
||||
<TouchableOpacity
|
||||
style={styles.settingsButton}
|
||||
onPress={async () => {
|
||||
|
||||
requestHash(this.state.password)
|
||||
}}
|
||||
style={styles.settingsButton}>
|
||||
>
|
||||
<AppText style={styles.settingsButtonText}>
|
||||
{labels.export.button}
|
||||
{ passwordPrompt.title }
|
||||
</AppText>
|
||||
</TouchableOpacity>
|
||||
{this.state.wrongPassword && <AppText>Wrong PAssword!</AppText>}
|
||||
|
||||
Reference in New Issue
Block a user