From 49b1110dd3763af0703b74cdcfdacaea39715be3 Mon Sep 17 00:00:00 2001
From: Julia Friesel <julia.friesel@gmail.com>
Date: Sat, 15 Sep 2018 10:34:02 +0200
Subject: [PATCH] Bring back check password flow

This reverts commit a029ba8766315f9197f67f5141606077520dc584.
---
 components/labels.js                    |   4 +-
 components/settings/password-setting.js | 153 ------------------------
 2 files changed, 2 insertions(+), 155 deletions(-)
 delete mode 100644 components/settings/password-setting.js

diff --git a/components/labels.js b/components/labels.js
index a3af8346..7f1657b0 100644
--- a/components/labels.js
+++ b/components/labels.js
@@ -58,8 +58,8 @@ export const settings = {
     explainerDisabled: "Encrypt the app's database with a password. You need to enter the password every time the app is started.",
     explainerEnabled: "Password protection and database encryption is currently enabled",
     setPassword: 'Set password',
-    deletePassword: 'Remove password protection',
-    changePassword: 'Change password',
+    deletePassword: "Delete password",
+    enterCurrent: "Please enter your current password",
     enterNew: "Please enter a new password",
     backupReminderTitle: 'Read this before making changes to your password',
     backupReminder: 'Just to be safe, please backup your data using the export function before making changes to your password.\n\nLonger passwords are better! Consider using a passphrase.\n\nPlease also make sure you do not lose your password. There is no way to recover your data if you do.\n\nMaking any changes to your password setting will restart the app.',
diff --git a/components/settings/password-setting.js b/components/settings/password-setting.js
deleted file mode 100644
index b9170e77..00000000
--- a/components/settings/password-setting.js
+++ /dev/null
@@ -1,153 +0,0 @@
-import React, { Component } from 'react'
-import {
-  View,
-  TouchableOpacity,
-  TextInput,
-  Alert
-} from 'react-native'
-import nodejs from 'nodejs-mobile-react-native'
-import { AppText } from '../app-text'
-import {
-  hasEncryptionObservable
-} from '../../local-storage'
-import styles from '../../styles/index'
-import { settings as labels, shared } from '../labels'
-import { requestHash, changeEncryptionAndRestartApp } from '../../db'
-
-export default class PasswordSetting extends Component {
-  constructor(props) {
-    super(props)
-    this.state = {
-      showUpdateAndDelete: hasEncryptionObservable.value,
-      showSetPassword: !hasEncryptionObservable.value,
-      settingNewPassword: false,
-      changingPassword: false
-    }
-
-    nodejs.channel.addListener(
-      'message',
-      this.passHashToDb,
-      this
-    )
-  }
-
-  componentWillUnmount() {
-    nodejs.channel.removeListener('message', this.passHashToDb)
-  }
-
-  passHashToDb = async (msg) => {
-    msg = JSON.parse(msg)
-    if (msg.type != 'sha512') return
-    await changeEncryptionAndRestartApp(msg.message)
-  }
-
-  render() {
-    return (
-      <View style={styles.settingsSegment}>
-        <AppText style={styles.settingsSegmentTitle}>
-          {labels.passwordSettings.title}
-        </AppText>
-        {this.state.showUpdateAndDelete ?
-          <AppText>{labels.passwordSettings.explainerEnabled}</AppText>
-          :
-          <AppText>{labels.passwordSettings.explainerDisabled}</AppText>
-        }
-
-        {this.state.showUpdateAndDelete &&
-          <View>
-            {this.state.changingPassword &&
-              <View>
-                <TextInput
-                  style={styles.passwordField}
-                  autoFocus={true}
-                  onChangeText={val => {
-                    this.setState({
-                      changedPassword: val
-                    })
-                  }}
-                  value={this.state.changedPassword}
-                  placeholder={labels.passwordSettings.enterNew}
-                  secureTextEntry={true}
-                />
-              </View>
-            }
-            <TouchableOpacity
-              onPress={() => {
-                if (!this.state.changingPassword) {
-                  showBackUpReminder(() => {
-                    this.setState({ changingPassword: true })
-                  })
-                } else {
-                  requestHash(this.state.changedPassword)
-                }
-              }}
-              disabled={this.state.changingPassword && !this.state.changedPassword}
-              style={styles.settingsButton}>
-              <AppText style={styles.settingsButtonText}>
-                {labels.passwordSettings.changePassword}
-              </AppText>
-            </TouchableOpacity>
-            <TouchableOpacity
-              onPress={() => {
-                showBackUpReminder(() => changeEncryptionAndRestartApp())
-              }}
-              style={styles.settingsButton}>
-              <AppText style={styles.settingsButtonText}>
-                {labels.passwordSettings.deletePassword}
-              </AppText>
-            </TouchableOpacity>
-          </View>
-        }
-
-        {this.state.enteringNewPassword &&
-          <View>
-            <TextInput
-              style={styles.passwordField}
-              autoFocus={true}
-              onChangeText={val => {
-                this.setState({
-                  newPassword: val
-                })
-              }}
-              value={this.state.newPassword}
-              placeholder={labels.passwordSettings.enterNew}
-              secureTextEntry={true}
-            />
-          </View>
-        }
-        {this.state.showSetPassword &&
-          <TouchableOpacity
-            onPress={() => {
-              if (!this.state.enteringNewPassword) {
-                showBackUpReminder(() => {
-                  this.setState({ enteringNewPassword: true })
-                })
-              } else {
-                requestHash(this.state.newPassword)
-              }
-            }}
-            disabled={this.state.enteringNewPassword && !this.state.newPassword}
-            style={styles.settingsButton}>
-            <AppText style={styles.settingsButtonText}>
-              {labels.passwordSettings.setPassword}
-            </AppText>
-          </TouchableOpacity>
-        }
-      </View>
-    )
-  }
-}
-
-function showBackUpReminder(okHandler) {
-  Alert.alert(
-    labels.passwordSettings.backupReminderTitle,
-    labels.passwordSettings.backupReminder,
-    [{
-      text: shared.cancel,
-      style: 'cancel'
-    }, {
-      text: shared.ok,
-      onPress: okHandler
-    }]
-  )
-}
\ No newline at end of file
-- 
GitLab