Cleanup ChangePassword component
This commit is contained in:
@@ -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 () {
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|
||||||
|
const {
|
||||||
|
enteringCurrentPassword,
|
||||||
|
enteringNewPassword,
|
||||||
|
currentPassword,
|
||||||
|
newPassword
|
||||||
|
} = this.state
|
||||||
|
|
||||||
|
const labels = settings.passwordSettings
|
||||||
|
|
||||||
|
if (enteringCurrentPassword) {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<PasswordField
|
||||||
|
placeholder={labels.enterCurrent}
|
||||||
|
value={currentPassword}
|
||||||
|
onChangeText={this.handleCurrentPasswordInput}
|
||||||
|
/>
|
||||||
|
<SettingsButton
|
||||||
|
onPress={this.checkCurrentPassword}
|
||||||
|
disabled={!currentPassword}
|
||||||
|
>
|
||||||
|
{sharedLabels.unlock}
|
||||||
|
</SettingsButton>
|
||||||
|
</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 (
|
return (
|
||||||
<View>
|
<View>
|
||||||
{!this.state.enteringCurrentPassword &&
|
|
||||||
!this.state.enteringNewPassword &&
|
|
||||||
<SettingsButton
|
<SettingsButton
|
||||||
onPress={this.startChangingPassword}
|
onPress={this.startChangingPassword}
|
||||||
disabled={this.state.currentPassword}
|
disabled={currentPassword}
|
||||||
>
|
>
|
||||||
{labels.passwordSettings.changePassword}
|
{labels.changePassword}
|
||||||
</SettingsButton>
|
</SettingsButton>
|
||||||
}
|
|
||||||
|
|
||||||
{this.state.enteringCurrentPassword &&
|
|
||||||
<View>
|
|
||||||
<PasswordField
|
|
||||||
onChangeText={val => {
|
|
||||||
this.setState({
|
|
||||||
currentPassword: val,
|
|
||||||
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 &&
|
|
||||||
<View>
|
|
||||||
<PasswordField
|
|
||||||
style={styles.passwordField}
|
|
||||||
onChangeText={val => {
|
|
||||||
this.setState({
|
|
||||||
newPassword: val
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
value={this.state.changedPassword}
|
|
||||||
placeholder={labels.passwordSettings.enterNew}
|
|
||||||
/>
|
|
||||||
<SettingsButton
|
|
||||||
onPress={() => requestHash('change-pw', this.state.newPassword)}
|
|
||||||
disabled={ !this.state.newPassword }
|
|
||||||
>
|
|
||||||
{labels.passwordSettings.changePassword}
|
|
||||||
</SettingsButton>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user