From 19288510c5c7d843495ffbd27c7c49ac776cf8ab Mon Sep 17 00:00:00 2001 From: Julia Friesel <julia.friesel@gmail.com> Date: Fri, 14 Sep 2018 17:04:13 +0200 Subject: [PATCH] Remove current password check and add change password flow --- components/labels.js | 4 +- components/settings/password-setting.js | 119 ++++++++++-------------- 2 files changed, 50 insertions(+), 73 deletions(-) diff --git a/components/labels.js b/components/labels.js index 15e922a4..d7f81994 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: "Delete password", - enterCurrent: "Please enter your current password", + deletePassword: 'Remove password protection', + changePassword: 'Change password', enterNew: "Please enter a new password", backupReminderTitle: 'Have you made a backup of your data?', backupReminder: 'When you make changes to your password, we delete your old data and store it in a new version. To be safe, please backup your data using the export function before making changes to your password. Making any changes to your password setting will also restart the app immediately.', diff --git a/components/settings/password-setting.js b/components/settings/password-setting.js index be1b9740..0b3a3fbc 100644 --- a/components/settings/password-setting.js +++ b/components/settings/password-setting.js @@ -12,18 +12,18 @@ import { } from '../../local-storage' import styles from '../../styles/index' import { settings as labels, shared } from '../labels' -import { requestHash, openDb, changeEncryptionAndRestartApp } from '../../db' +import { requestHash, changeEncryptionAndRestartApp } from '../../db' export default class PasswordSetting extends Component { constructor(props) { super(props) this.state = { - encryptionEnabled: hasEncryptionObservable.value, - currentPassword: null, - enteringCurrentPassword: false + showUpdateAndDelete: hasEncryptionObservable.value, + showSetPassword: !hasEncryptionObservable.value, + settingNewPassword: false, + changingPassword: false } - nodejs.start('main.js') nodejs.channel.addListener( 'message', this.passHashToDb, @@ -38,41 +38,7 @@ export default class PasswordSetting extends Component { passHashToDb = async (msg) => { msg = JSON.parse(msg) if (msg.type != 'sha512') return - if (this.state.encryptionEnabled) { - await this.removeEncryption(msg.message) - } else if (!this.state.encryptionEnabled) { - await changeEncryptionAndRestartApp(msg.message) - } - } - - addEncryption = async hash => { - changeEncryptionAndRestartApp(hash) - } - - removeEncryption = async hash => { - try { - await openDb({ hash, persistConnection: false }) - } catch (err) { - console.log(err) - Alert.alert( - shared.incorrectPassword, - shared.incorrectPasswordMessage, - [{ - text: shared.cancel, - onPress: () => { - this.setState({ - enteringCurrentPassword: false, - currentPassword: null - }) - } - }, { - text: shared.tryAgain, - onPress: () => this.setState({currentPassword: null}) - }] - ) - return - } - await changeEncryptionAndRestartApp() + await changeEncryptionAndRestartApp(msg.message) } render() { @@ -81,44 +47,55 @@ export default class PasswordSetting extends Component { <AppText style={styles.settingsSegmentTitle}> {labels.passwordSettings.title} </AppText> - {this.state.encryptionEnabled ? + {this.state.showUpdateAndDelete ? <AppText>{labels.passwordSettings.explainerEnabled}</AppText> : <AppText>{labels.passwordSettings.explainerDisabled}</AppText> } - {this.state.enteringCurrentPassword && + + {this.state.showUpdateAndDelete && <View> - <TextInput - style={styles.passwordField} - onChangeText={val => { - this.setState({ - currentPassword: val, - wrongPassword: false - }) + {this.state.changingPassword && + <View> + <TextInput + style={styles.passwordField} + 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) + } }} - value={this.state.currentPassword} - placeholder={labels.passwordSettings.enterCurrent} - secureTextEntry={true} - /> + 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.encryptionEnabled && - <TouchableOpacity - onPress={() => { - if (!this.state.enteringCurrentPassword) { - showBackUpReminder(() => { - this.setState({ enteringCurrentPassword: true }) - }) - } else { - requestHash(this.state.currentPassword) - } - }} - style={styles.settingsButton}> - <AppText style={styles.settingsButtonText}> - {labels.passwordSettings.deletePassword} - </AppText> - </TouchableOpacity> - } {this.state.enteringNewPassword && <View> @@ -135,7 +112,7 @@ export default class PasswordSetting extends Component { /> </View> } - {!this.state.encryptionEnabled && + {this.state.showSetPassword && <TouchableOpacity onPress={() => { if (!this.state.enteringNewPassword) { -- GitLab