From 19288510c5c7d843495ffbd27c7c49ac776cf8ab Mon Sep 17 00:00:00 2001 From: Julia Friesel 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 15e922a..d7f8199 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 be1b974..0b3a3fb 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 { {labels.passwordSettings.title} - {this.state.encryptionEnabled ? + {this.state.showUpdateAndDelete ? {labels.passwordSettings.explainerEnabled} : {labels.passwordSettings.explainerDisabled} } - {this.state.enteringCurrentPassword && + + {this.state.showUpdateAndDelete && - { - this.setState({ - currentPassword: val, - wrongPassword: false - }) + {this.state.changingPassword && + + { + this.setState({ + changedPassword: val + }) + }} + value={this.state.changedPassword} + placeholder={labels.passwordSettings.enterNew} + secureTextEntry={true} + /> + + } + { + 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}> + + {labels.passwordSettings.changePassword} + + + { + showBackUpReminder(() => changeEncryptionAndRestartApp()) + }} + style={styles.settingsButton}> + + {labels.passwordSettings.deletePassword} + + } - {this.state.encryptionEnabled && - { - if (!this.state.enteringCurrentPassword) { - showBackUpReminder(() => { - this.setState({ enteringCurrentPassword: true }) - }) - } else { - requestHash(this.state.currentPassword) - } - }} - style={styles.settingsButton}> - - {labels.passwordSettings.deletePassword} - - - } {this.state.enteringNewPassword && @@ -135,7 +112,7 @@ export default class PasswordSetting extends Component { /> } - {!this.state.encryptionEnabled && + {this.state.showSetPassword && { if (!this.state.enteringNewPassword) {