diff --git a/components/settings/password/create.js b/components/settings/password/create.js index e2e8517..e9603be 100644 --- a/components/settings/password/create.js +++ b/components/settings/password/create.js @@ -59,11 +59,7 @@ export default class CreatePassword extends Component { } handleConfirmationInput = (passwordConfirmation) => { - const { password } = this.state - this.setState({ - passwordConfirmation, - isPasswordsMatch: passwordConfirmation === password - }) + this.setState({ passwordConfirmation }) } render () { diff --git a/components/settings/password/update.js b/components/settings/password/update.js index a470e57..141957b 100644 --- a/components/settings/password/update.js +++ b/components/settings/password/update.js @@ -1,13 +1,8 @@ - import React, { Component } from 'react' -import { - View, - TouchableOpacity} from 'react-native' +import { View } from 'react-native' import nodejs from 'nodejs-mobile-react-native' -import AppText from '../../app-text' -import styles from '../../../styles' -import { shared } from '../../../i18n/en/labels' -import { settings as labels } from '../../../i18n/en/settings' +import { shared as sharedLabels } from '../../../i18n/en/labels' +import { settings } from '../../../i18n/en/settings' import { requestHash, changeEncryptionAndRestartApp } from '../../../db' import PasswordField from './password-field' import SettingsButton from './settings-button' @@ -19,10 +14,11 @@ export default class ChangePassword extends Component { constructor() { super() this.state = { - enteringCurrentPassword: false, currentPassword: null, - enteringNewPassword: false, - newPassword: null + newPassword: null, + newPasswordConfirmation: null, + enteringCurrentPassword: false, + enteringNewPassword: false } nodejs.channel.addListener( @@ -55,9 +51,9 @@ export default class ChangePassword extends Component { if (passwordCorrect) { this.setState({ - enteringCurrentPassword: false, currentPassword: null, - enteringNewPassword: true + enteringNewPassword: true, + enteringCurrentPassword: false }) } } @@ -68,61 +64,77 @@ export default class ChangePassword extends Component { }) } + handleCurrentPasswordInput = (currentPassword) => { + this.setState({ currentPassword }) + } + + checkCurrentPassword = () => { + requestHash('pre-change-pw-check', this.state.currentPassword) + } + + handleNewPasswordInput = (newPassword) => { + this.setState({ newPassword }) + } + + changePassword = () => { + requestHash('change-pw', this.state.newPassword) + } + render() { - return ( - - {!this.state.enteringCurrentPassword && - !this.state.enteringNewPassword && - - {labels.passwordSettings.changePassword} - - } - {this.state.enteringCurrentPassword && - - { - this.setState({ - currentPassword: val, - wrongPassword: false - }) - }} - value={this.state.currentPassword} - placeholder={labels.passwordSettings.enterCurrent} - /> - requestHash('pre-change-pw-check', this.state.currentPassword)} - disabled={!this.state.currentPassword} - > - {shared.unlock} - - - } + const { + enteringCurrentPassword, + enteringNewPassword, + currentPassword, + newPassword + } = this.state - {this.state.enteringNewPassword && + const labels = settings.passwordSettings + + if (enteringCurrentPassword) { + return ( { - this.setState({ - newPassword: val - }) - }} - value={this.state.changedPassword} - placeholder={labels.passwordSettings.enterNew} + placeholder={labels.enterCurrent} + value={currentPassword} + onChangeText={this.handleCurrentPasswordInput} /> requestHash('change-pw', this.state.newPassword)} - disabled={ !this.state.newPassword } + onPress={this.checkCurrentPassword} + disabled={!currentPassword} > - {labels.passwordSettings.changePassword} + {sharedLabels.unlock} - } + ) + } + if (enteringNewPassword) { + return ( + + + + {labels.changePassword} + + + ) + } + + return ( + + + {labels.changePassword} + ) }