Merge branch 'settings-editing-password-confirmation' into 'master'
Settings editing password confirmation Closes #256 See merge request bloodyhealth/drip!125
This commit is contained in:
@@ -1,59 +1,15 @@
|
|||||||
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 AppText from '../../app-text'
|
|
||||||
import styles from '../../../styles'
|
|
||||||
import { settings } from '../../../i18n/en/settings'
|
import { settings } from '../../../i18n/en/settings'
|
||||||
import { requestHash, changeEncryptionAndRestartApp } from '../../../db'
|
import EnterNewPassword from './enter-new-password'
|
||||||
import PasswordField from './password-field'
|
import SettingsButton from './settings-button'
|
||||||
import showBackUpReminder from './show-backup-reminder'
|
import showBackUpReminder from './show-backup-reminder'
|
||||||
|
|
||||||
const SettingsButton = ({ children, ...props }) => {
|
|
||||||
return (
|
|
||||||
<TouchableOpacity
|
|
||||||
style={[
|
|
||||||
styles.settingsButton,
|
|
||||||
props.disabled ? styles.settingsButtonDisabled : null
|
|
||||||
]}
|
|
||||||
{ ...props }
|
|
||||||
>
|
|
||||||
<AppText style={styles.settingsButtonText}>
|
|
||||||
{children}
|
|
||||||
</AppText>
|
|
||||||
</TouchableOpacity>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class CreatePassword extends Component {
|
export default class CreatePassword extends Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.state = {
|
this.state = {
|
||||||
isSettingPassword: false,
|
isSettingPassword: false
|
||||||
password: '',
|
|
||||||
passwordConfirmation: '',
|
|
||||||
shouldShowErrorMessage: false,
|
|
||||||
}
|
|
||||||
nodejs.channel.addListener(
|
|
||||||
'create-pw-hash',
|
|
||||||
changeEncryptionAndRestartApp,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
nodejs.channel.removeListener('create-pw-hash', changeEncryptionAndRestartApp)
|
|
||||||
}
|
|
||||||
|
|
||||||
savePassword = () => {
|
|
||||||
if (this.comparePasswords()) {
|
|
||||||
requestHash('create-pw-hash', this.state.password)
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
shouldShowErrorMessage: true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,35 +22,12 @@ export default class CreatePassword extends Component {
|
|||||||
showBackUpReminder(this.toggleSettingPassword)
|
showBackUpReminder(this.toggleSettingPassword)
|
||||||
}
|
}
|
||||||
|
|
||||||
comparePasswords = () => {
|
|
||||||
return this.state.password === this.state.passwordConfirmation
|
|
||||||
}
|
|
||||||
|
|
||||||
handlePasswordInput = (password) => {
|
|
||||||
this.setState({ password })
|
|
||||||
}
|
|
||||||
|
|
||||||
handleConfirmationInput = (passwordConfirmation) => {
|
|
||||||
const { password } = this.state
|
|
||||||
this.setState({
|
|
||||||
passwordConfirmation,
|
|
||||||
isPasswordsMatch: passwordConfirmation === password
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const {
|
const {
|
||||||
isSettingPassword,
|
isSettingPassword
|
||||||
password,
|
|
||||||
passwordConfirmation,
|
|
||||||
shouldShowErrorMessage,
|
|
||||||
} = this.state
|
} = this.state
|
||||||
const labels = settings.passwordSettings
|
const labels = settings.passwordSettings
|
||||||
|
|
||||||
const isSaveButtonDisabled =
|
|
||||||
!password.length ||
|
|
||||||
!passwordConfirmation.length
|
|
||||||
|
|
||||||
if (!isSettingPassword) {
|
if (!isSettingPassword) {
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
@@ -104,33 +37,7 @@ export default class CreatePassword extends Component {
|
|||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return <EnterNewPassword />
|
||||||
<View>
|
|
||||||
<PasswordField
|
|
||||||
placeholder={labels.enterNew}
|
|
||||||
value={password}
|
|
||||||
onChangeText={this.handlePasswordInput}
|
|
||||||
/>
|
|
||||||
<PasswordField
|
|
||||||
autoFocus={false}
|
|
||||||
placeholder={labels.confirmPassword}
|
|
||||||
value={passwordConfirmation}
|
|
||||||
onChangeText={this.handleConfirmationInput}
|
|
||||||
/>
|
|
||||||
{
|
|
||||||
shouldShowErrorMessage &&
|
|
||||||
<AppText style={styles.errorMessage}>
|
|
||||||
{labels.passwordsDontMatch}
|
|
||||||
</AppText>
|
|
||||||
}
|
|
||||||
<SettingsButton
|
|
||||||
onPress={this.savePassword}
|
|
||||||
disabled={isSaveButtonDisabled}
|
|
||||||
>
|
|
||||||
{labels.savePassword}
|
|
||||||
</SettingsButton>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
import nodejs from 'nodejs-mobile-react-native'
|
||||||
|
|
||||||
|
import { requestHash, changeEncryptionAndRestartApp } from '../../../db'
|
||||||
|
import AppText from '../../app-text'
|
||||||
|
import PasswordField from './password-field'
|
||||||
|
import SettingsButton from './settings-button'
|
||||||
|
|
||||||
|
import styles from '../../../styles'
|
||||||
|
import { settings } from '../../../i18n/en/settings'
|
||||||
|
|
||||||
|
const LISTENER_TYPE = 'create-or-change-pw'
|
||||||
|
|
||||||
|
export default class EnterNewPassword extends Component {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.state = {
|
||||||
|
password: '',
|
||||||
|
passwordConfirmation: '',
|
||||||
|
shouldShowErrorMessage: false,
|
||||||
|
}
|
||||||
|
nodejs.channel.addListener(
|
||||||
|
LISTENER_TYPE,
|
||||||
|
changeEncryptionAndRestartApp,
|
||||||
|
this
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
nodejs.channel.removeListener(LISTENER_TYPE, changeEncryptionAndRestartApp)
|
||||||
|
}
|
||||||
|
|
||||||
|
savePassword = () => {
|
||||||
|
if (this.comparePasswords()) {
|
||||||
|
requestHash(LISTENER_TYPE, this.state.password)
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
shouldShowErrorMessage: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
comparePasswords = () => {
|
||||||
|
return this.state.password === this.state.passwordConfirmation
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePasswordInput = (password) => {
|
||||||
|
this.setState({ password })
|
||||||
|
}
|
||||||
|
|
||||||
|
handleConfirmationInput = (passwordConfirmation) => {
|
||||||
|
this.setState({ passwordConfirmation })
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const {
|
||||||
|
password,
|
||||||
|
passwordConfirmation,
|
||||||
|
shouldShowErrorMessage,
|
||||||
|
} = this.state
|
||||||
|
const labels = settings.passwordSettings
|
||||||
|
|
||||||
|
const isSaveButtonDisabled =
|
||||||
|
!password.length ||
|
||||||
|
!passwordConfirmation.length
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<PasswordField
|
||||||
|
placeholder={labels.enterNew}
|
||||||
|
value={password}
|
||||||
|
onChangeText={this.handlePasswordInput}
|
||||||
|
/>
|
||||||
|
<PasswordField
|
||||||
|
autoFocus={false}
|
||||||
|
placeholder={labels.confirmPassword}
|
||||||
|
value={passwordConfirmation}
|
||||||
|
onChangeText={this.handleConfirmationInput}
|
||||||
|
/>
|
||||||
|
{
|
||||||
|
shouldShowErrorMessage &&
|
||||||
|
<AppText style={styles.errorMessage}>
|
||||||
|
{labels.passwordsDontMatch}
|
||||||
|
</AppText>
|
||||||
|
}
|
||||||
|
<SettingsButton
|
||||||
|
onPress={this.savePassword}
|
||||||
|
disabled={isSaveButtonDisabled}
|
||||||
|
>
|
||||||
|
{labels.savePassword}
|
||||||
|
</SettingsButton>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import { TouchableOpacity } from 'react-native'
|
||||||
|
import AppText from '../../app-text'
|
||||||
|
import styles from '../../../styles'
|
||||||
|
|
||||||
|
const SettingsButton = ({ children, ...props }) => {
|
||||||
|
return (
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[
|
||||||
|
styles.settingsButton,
|
||||||
|
props.disabled ? styles.settingsButtonDisabled : null
|
||||||
|
]}
|
||||||
|
{ ...props }
|
||||||
|
>
|
||||||
|
<AppText style={styles.settingsButtonText}>
|
||||||
|
{children}
|
||||||
|
</AppText>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsButton.propTypes = {
|
||||||
|
onPress: PropTypes.func.isRequired,
|
||||||
|
disabled: PropTypes.bool
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SettingsButton
|
||||||
@@ -1,26 +1,23 @@
|
|||||||
|
|
||||||
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 { requestHash } from '../../../db'
|
||||||
import { settings as labels } from '../../../i18n/en/settings'
|
import EnterNewPassword from './enter-new-password'
|
||||||
import { requestHash, changeEncryptionAndRestartApp } from '../../../db'
|
|
||||||
import PasswordField from './password-field'
|
import PasswordField from './password-field'
|
||||||
|
import SettingsButton from './settings-button'
|
||||||
import showBackUpReminder from './show-backup-reminder'
|
import showBackUpReminder from './show-backup-reminder'
|
||||||
import checkCurrentPassword from './check-current-password'
|
import checkCurrentPassword from './check-current-password'
|
||||||
|
|
||||||
|
|
||||||
export default class ChangePassword extends Component {
|
export default class ChangePassword extends Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.state = {
|
this.state = {
|
||||||
enteringCurrentPassword: false,
|
|
||||||
currentPassword: null,
|
currentPassword: null,
|
||||||
enteringNewPassword: false,
|
enteringCurrentPassword: false,
|
||||||
newPassword: null
|
enteringNewPassword: false
|
||||||
}
|
}
|
||||||
|
|
||||||
nodejs.channel.addListener(
|
nodejs.channel.addListener(
|
||||||
@@ -28,17 +25,10 @@ export default class ChangePassword extends Component {
|
|||||||
this.openNewPasswordField,
|
this.openNewPasswordField,
|
||||||
this
|
this
|
||||||
)
|
)
|
||||||
|
|
||||||
nodejs.channel.addListener(
|
|
||||||
'change-pw',
|
|
||||||
changeEncryptionAndRestartApp,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
nodejs.channel.removeListener('pre-change-pw-check', this.openNewPasswordField)
|
nodejs.channel.removeListener('pre-change-pw-check', this.openNewPasswordField)
|
||||||
nodejs.channel.removeListener('change-pw', changeEncryptionAndRestartApp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
openNewPasswordField = async hash => {
|
openNewPasswordField = async hash => {
|
||||||
@@ -53,77 +43,67 @@ 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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startChangingPassword = () => {
|
||||||
|
showBackUpReminder(() => {
|
||||||
|
this.setState({ enteringCurrentPassword: true })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleCurrentPasswordInput = (currentPassword) => {
|
||||||
|
this.setState({ currentPassword })
|
||||||
|
}
|
||||||
|
|
||||||
|
checkCurrentPassword = () => {
|
||||||
|
requestHash('pre-change-pw-check', this.state.currentPassword)
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
|
||||||
<View>
|
|
||||||
{!this.state.enteringCurrentPassword &&
|
|
||||||
!this.state.enteringNewPassword &&
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={() => showBackUpReminder(() => {
|
|
||||||
this.setState({ enteringCurrentPassword: true })
|
|
||||||
})}
|
|
||||||
disabled={this.state.currentPassword}
|
|
||||||
style={styles.settingsButton}>
|
|
||||||
<AppText style={styles.settingsButtonText}>
|
|
||||||
{labels.passwordSettings.changePassword}
|
|
||||||
</AppText>
|
|
||||||
</TouchableOpacity>
|
|
||||||
}
|
|
||||||
|
|
||||||
{this.state.enteringCurrentPassword &&
|
const {
|
||||||
<View>
|
enteringCurrentPassword,
|
||||||
<PasswordField
|
enteringNewPassword,
|
||||||
onChangeText={val => {
|
currentPassword
|
||||||
this.setState({
|
} = this.state
|
||||||
currentPassword: val,
|
|
||||||
wrongPassword: false
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
value={this.state.currentPassword}
|
|
||||||
placeholder={labels.passwordSettings.enterCurrent}
|
|
||||||
/>
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={() => requestHash('pre-change-pw-check', this.state.currentPassword)}
|
|
||||||
disabled={!this.state.currentPassword}
|
|
||||||
style={styles.settingsButton}>
|
|
||||||
<AppText style={styles.settingsButtonText}>
|
|
||||||
{shared.unlock}
|
|
||||||
</AppText>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</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
|
||||||
<TouchableOpacity
|
onPress={this.checkCurrentPassword}
|
||||||
onPress={() => requestHash('change-pw', this.state.newPassword)}
|
disabled={!currentPassword}
|
||||||
disabled={ !this.state.newPassword }
|
>
|
||||||
style={styles.settingsButton}>
|
{sharedLabels.unlock}
|
||||||
<AppText style={styles.settingsButtonText}>
|
</SettingsButton>
|
||||||
{labels.passwordSettings.changePassword}
|
|
||||||
</AppText>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
</View>
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enteringNewPassword) {
|
||||||
|
return <EnterNewPassword />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<SettingsButton
|
||||||
|
onPress={this.startChangingPassword}
|
||||||
|
disabled={currentPassword}
|
||||||
|
>
|
||||||
|
{labels.changePassword}
|
||||||
|
</SettingsButton>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
"nodejs-mobile-react-native": "^0.3.0",
|
"nodejs-mobile-react-native": "^0.3.0",
|
||||||
"object-path": "^0.11.4",
|
"object-path": "^0.11.4",
|
||||||
"obv": "0.0.1",
|
"obv": "0.0.1",
|
||||||
|
"prop-types": "^15.6.2",
|
||||||
"react": "16.4.1",
|
"react": "16.4.1",
|
||||||
"react-native": "~0.56.0",
|
"react-native": "~0.56.0",
|
||||||
"react-native-calendars": "^1.19.3",
|
"react-native-calendars": "^1.19.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user