Remove current password check and add change password flow
This commit is contained in:
@@ -58,8 +58,8 @@ export const settings = {
|
|||||||
explainerDisabled: "Encrypt the app's database with a password. You need to enter the password every time the app is started.",
|
explainerDisabled: "Encrypt the app's database with a password. You need to enter the password every time the app is started.",
|
||||||
explainerEnabled: "Password protection and database encryption is currently enabled",
|
explainerEnabled: "Password protection and database encryption is currently enabled",
|
||||||
setPassword: 'Set password',
|
setPassword: 'Set password',
|
||||||
deletePassword: "Delete password",
|
deletePassword: 'Remove password protection',
|
||||||
enterCurrent: "Please enter your current password",
|
changePassword: 'Change password',
|
||||||
enterNew: "Please enter a new password",
|
enterNew: "Please enter a new password",
|
||||||
backupReminderTitle: 'Have you made a backup of your data?',
|
backupReminderTitle: 'Have you made a backup of your data?',
|
||||||
backupReminder: 'When you make changes to your password, we delete your old data and store it in a new version. To be safe, please backup your data using the export function before making changes to your password. Making any changes to your password setting will also restart the app immediately.',
|
backupReminder: 'When you make changes to your password, we delete your old data and store it in a new version. To be safe, please backup your data using the export function before making changes to your password. Making any changes to your password setting will also restart the app immediately.',
|
||||||
|
|||||||
@@ -12,18 +12,18 @@ import {
|
|||||||
} from '../../local-storage'
|
} from '../../local-storage'
|
||||||
import styles from '../../styles/index'
|
import styles from '../../styles/index'
|
||||||
import { settings as labels, shared } from '../labels'
|
import { settings as labels, shared } from '../labels'
|
||||||
import { requestHash, openDb, changeEncryptionAndRestartApp } from '../../db'
|
import { requestHash, changeEncryptionAndRestartApp } from '../../db'
|
||||||
|
|
||||||
export default class PasswordSetting extends Component {
|
export default class PasswordSetting extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
encryptionEnabled: hasEncryptionObservable.value,
|
showUpdateAndDelete: hasEncryptionObservable.value,
|
||||||
currentPassword: null,
|
showSetPassword: !hasEncryptionObservable.value,
|
||||||
enteringCurrentPassword: false
|
settingNewPassword: false,
|
||||||
|
changingPassword: false
|
||||||
}
|
}
|
||||||
|
|
||||||
nodejs.start('main.js')
|
|
||||||
nodejs.channel.addListener(
|
nodejs.channel.addListener(
|
||||||
'message',
|
'message',
|
||||||
this.passHashToDb,
|
this.passHashToDb,
|
||||||
@@ -38,41 +38,7 @@ export default class PasswordSetting extends Component {
|
|||||||
passHashToDb = async (msg) => {
|
passHashToDb = async (msg) => {
|
||||||
msg = JSON.parse(msg)
|
msg = JSON.parse(msg)
|
||||||
if (msg.type != 'sha512') return
|
if (msg.type != 'sha512') return
|
||||||
if (this.state.encryptionEnabled) {
|
await changeEncryptionAndRestartApp(msg.message)
|
||||||
await this.removeEncryption(msg.message)
|
|
||||||
} else if (!this.state.encryptionEnabled) {
|
|
||||||
await changeEncryptionAndRestartApp(msg.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
addEncryption = async hash => {
|
|
||||||
changeEncryptionAndRestartApp(hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
removeEncryption = async hash => {
|
|
||||||
try {
|
|
||||||
await openDb({ hash, persistConnection: false })
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
Alert.alert(
|
|
||||||
shared.incorrectPassword,
|
|
||||||
shared.incorrectPasswordMessage,
|
|
||||||
[{
|
|
||||||
text: shared.cancel,
|
|
||||||
onPress: () => {
|
|
||||||
this.setState({
|
|
||||||
enteringCurrentPassword: false,
|
|
||||||
currentPassword: null
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
text: shared.tryAgain,
|
|
||||||
onPress: () => this.setState({currentPassword: null})
|
|
||||||
}]
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await changeEncryptionAndRestartApp()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -81,44 +47,55 @@ export default class PasswordSetting extends Component {
|
|||||||
<AppText style={styles.settingsSegmentTitle}>
|
<AppText style={styles.settingsSegmentTitle}>
|
||||||
{labels.passwordSettings.title}
|
{labels.passwordSettings.title}
|
||||||
</AppText>
|
</AppText>
|
||||||
{this.state.encryptionEnabled ?
|
{this.state.showUpdateAndDelete ?
|
||||||
<AppText>{labels.passwordSettings.explainerEnabled}</AppText>
|
<AppText>{labels.passwordSettings.explainerEnabled}</AppText>
|
||||||
:
|
:
|
||||||
<AppText>{labels.passwordSettings.explainerDisabled}</AppText>
|
<AppText>{labels.passwordSettings.explainerDisabled}</AppText>
|
||||||
}
|
}
|
||||||
{this.state.enteringCurrentPassword &&
|
|
||||||
|
{this.state.showUpdateAndDelete &&
|
||||||
<View>
|
<View>
|
||||||
<TextInput
|
{this.state.changingPassword &&
|
||||||
style={styles.passwordField}
|
<View>
|
||||||
onChangeText={val => {
|
<TextInput
|
||||||
this.setState({
|
style={styles.passwordField}
|
||||||
currentPassword: val,
|
onChangeText={val => {
|
||||||
wrongPassword: false
|
this.setState({
|
||||||
})
|
changedPassword: val
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
value={this.state.changedPassword}
|
||||||
|
placeholder={labels.passwordSettings.enterNew}
|
||||||
|
secureTextEntry={true}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => {
|
||||||
|
if (!this.state.changingPassword) {
|
||||||
|
showBackUpReminder(() => {
|
||||||
|
this.setState({ changingPassword: true })
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
requestHash(this.state.changedPassword)
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
value={this.state.currentPassword}
|
style={styles.settingsButton}>
|
||||||
placeholder={labels.passwordSettings.enterCurrent}
|
<AppText style={styles.settingsButtonText}>
|
||||||
secureTextEntry={true}
|
{labels.passwordSettings.changePassword}
|
||||||
/>
|
</AppText>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => {
|
||||||
|
showBackUpReminder(() => changeEncryptionAndRestartApp())
|
||||||
|
}}
|
||||||
|
style={styles.settingsButton}>
|
||||||
|
<AppText style={styles.settingsButtonText}>
|
||||||
|
{labels.passwordSettings.deletePassword}
|
||||||
|
</AppText>
|
||||||
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
{this.state.encryptionEnabled &&
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={() => {
|
|
||||||
if (!this.state.enteringCurrentPassword) {
|
|
||||||
showBackUpReminder(() => {
|
|
||||||
this.setState({ enteringCurrentPassword: true })
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
requestHash(this.state.currentPassword)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
style={styles.settingsButton}>
|
|
||||||
<AppText style={styles.settingsButtonText}>
|
|
||||||
{labels.passwordSettings.deletePassword}
|
|
||||||
</AppText>
|
|
||||||
</TouchableOpacity>
|
|
||||||
}
|
|
||||||
|
|
||||||
{this.state.enteringNewPassword &&
|
{this.state.enteringNewPassword &&
|
||||||
<View>
|
<View>
|
||||||
@@ -135,7 +112,7 @@ export default class PasswordSetting extends Component {
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
{!this.state.encryptionEnabled &&
|
{this.state.showSetPassword &&
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (!this.state.enteringNewPassword) {
|
if (!this.state.enteringNewPassword) {
|
||||||
|
|||||||
Reference in New Issue
Block a user