Skip to content
Snippets Groups Projects
Commit 857b8fc1 authored by mashazyu's avatar mashazyu
Browse files

Cleanup ChangePassword component

parent 7ddf9a70
No related branches found
No related tags found
No related merge requests found
...@@ -59,11 +59,7 @@ export default class CreatePassword extends Component { ...@@ -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 () {
......
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 { ...@@ -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 { ...@@ -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 { ...@@ -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> const {
{!this.state.enteringCurrentPassword && enteringCurrentPassword,
!this.state.enteringNewPassword && enteringNewPassword,
<SettingsButton currentPassword,
onPress={this.startChangingPassword} newPassword
disabled={this.state.currentPassword} } = this.state
>
{labels.passwordSettings.changePassword} const labels = settings.passwordSettings
</SettingsButton>
} if (enteringCurrentPassword) {
return (
{this.state.enteringCurrentPassword && <View>
<View> <PasswordField
<PasswordField placeholder={labels.enterCurrent}
onChangeText={val => { value={currentPassword}
this.setState({ onChangeText={this.handleCurrentPasswordInput}
currentPassword: val, />
wrongPassword: false <SettingsButton
}) onPress={this.checkCurrentPassword}
}} disabled={!currentPassword}
value={this.state.currentPassword} >
placeholder={labels.passwordSettings.enterCurrent} {sharedLabels.unlock}
/> </SettingsButton>
<SettingsButton </View>
onPress={() => requestHash('pre-change-pw-check', this.state.currentPassword)} )
disabled={!this.state.currentPassword} }
>
{shared.unlock} if (enteringNewPassword) {
</SettingsButton> return (
</View>
}
{this.state.enteringNewPassword &&
<View> <View>
<PasswordField <PasswordField
style={styles.passwordField} placeholder={labels.enterNew}
onChangeText={val => { value={newPassword}
this.setState({ onChangeText={this.handleNewPasswordInput}
newPassword: val
})
}}
value={this.state.changedPassword}
placeholder={labels.passwordSettings.enterNew}
/> />
<SettingsButton <SettingsButton
onPress={() => requestHash('change-pw', this.state.newPassword)} onPress={this.changePassword}
disabled={ !this.state.newPassword } disabled={!newPassword}
> >
{labels.passwordSettings.changePassword} {labels.changePassword}
</SettingsButton> </SettingsButton>
</View> </View>
} )
}
return (
<View>
<SettingsButton
onPress={this.startChangingPassword}
disabled={currentPassword}
>
{labels.changePassword}
</SettingsButton>
</View> </View>
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment