Cleanup ChangePassword component

This commit is contained in:
mashazyu
2018-12-07 23:56:33 +01:00
parent 7ddf9a7002
commit 857b8fc1f1
2 changed files with 70 additions and 62 deletions
+1 -5
View File
@@ -59,11 +59,7 @@ export default class CreatePassword extends Component {
} }
handleConfirmationInput = (passwordConfirmation) => { handleConfirmationInput = (passwordConfirmation) => {
const { password } = this.state this.setState({ passwordConfirmation })
this.setState({
passwordConfirmation,
isPasswordsMatch: passwordConfirmation === password
})
} }
render () { render () {
+69 -57
View File
@@ -1,13 +1,8 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { import { View } from 'react-native'
View,
TouchableOpacity} from 'react-native'
import nodejs from 'nodejs-mobile-react-native' import nodejs from 'nodejs-mobile-react-native'
import AppText from '../../app-text' import { shared as sharedLabels } from '../../../i18n/en/labels'
import styles from '../../../styles' import { settings } from '../../../i18n/en/settings'
import { shared } from '../../../i18n/en/labels'
import { settings as labels } from '../../../i18n/en/settings'
import { requestHash, changeEncryptionAndRestartApp } from '../../../db' import { requestHash, changeEncryptionAndRestartApp } from '../../../db'
import PasswordField from './password-field' import PasswordField from './password-field'
import SettingsButton from './settings-button' import SettingsButton from './settings-button'
@@ -19,10 +14,11 @@ export default class ChangePassword extends Component {
constructor() { constructor() {
super() super()
this.state = { this.state = {
enteringCurrentPassword: false,
currentPassword: null, currentPassword: null,
enteringNewPassword: false, newPassword: null,
newPassword: null newPasswordConfirmation: null,
enteringCurrentPassword: false,
enteringNewPassword: false
} }
nodejs.channel.addListener( nodejs.channel.addListener(
@@ -55,9 +51,9 @@ export default class ChangePassword extends Component {
if (passwordCorrect) { if (passwordCorrect) {
this.setState({ this.setState({
enteringCurrentPassword: false,
currentPassword: null, 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() { render() {
return (
<View>
{!this.state.enteringCurrentPassword &&
!this.state.enteringNewPassword &&
<SettingsButton
onPress={this.startChangingPassword}
disabled={this.state.currentPassword}
>
{labels.passwordSettings.changePassword}
</SettingsButton>
}
{this.state.enteringCurrentPassword && const {
<View> enteringCurrentPassword,
<PasswordField enteringNewPassword,
onChangeText={val => { currentPassword,
this.setState({ newPassword
currentPassword: val, } = this.state
wrongPassword: false
})
}}
value={this.state.currentPassword}
placeholder={labels.passwordSettings.enterCurrent}
/>
<SettingsButton
onPress={() => requestHash('pre-change-pw-check', this.state.currentPassword)}
disabled={!this.state.currentPassword}
>
{shared.unlock}
</SettingsButton>
</View>
}
{this.state.enteringNewPassword && const labels = settings.passwordSettings
if (enteringCurrentPassword) {
return (
<View> <View>
<PasswordField <PasswordField
style={styles.passwordField} placeholder={labels.enterCurrent}
onChangeText={val => { value={currentPassword}
this.setState({ onChangeText={this.handleCurrentPasswordInput}
newPassword: val
})
}}
value={this.state.changedPassword}
placeholder={labels.passwordSettings.enterNew}
/> />
<SettingsButton <SettingsButton
onPress={() => requestHash('change-pw', this.state.newPassword)} onPress={this.checkCurrentPassword}
disabled={ !this.state.newPassword } disabled={!currentPassword}
> >
{labels.passwordSettings.changePassword} {sharedLabels.unlock}
</SettingsButton> </SettingsButton>
</View> </View>
} )
}
if (enteringNewPassword) {
return (
<View>
<PasswordField
placeholder={labels.enterNew}
value={newPassword}
onChangeText={this.handleNewPasswordInput}
/>
<SettingsButton
onPress={this.changePassword}
disabled={!newPassword}
>
{labels.changePassword}
</SettingsButton>
</View>
)
}
return (
<View>
<SettingsButton
onPress={this.startChangingPassword}
disabled={currentPassword}
>
{labels.changePassword}
</SettingsButton>
</View> </View>
) )
} }