From d14071f3503f768c9c0e040dee549be6a6b40e5f Mon Sep 17 00:00:00 2001 From: vantezzen Date: Tue, 17 Sep 2019 12:14:48 +0200 Subject: Implement #41 --- src/containers/auth/LockedScreen.js | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/containers/auth/LockedScreen.js (limited to 'src/containers/auth/LockedScreen.js') diff --git a/src/containers/auth/LockedScreen.js b/src/containers/auth/LockedScreen.js new file mode 100644 index 000000000..94285fb06 --- /dev/null +++ b/src/containers/auth/LockedScreen.js @@ -0,0 +1,72 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { inject, observer } from 'mobx-react'; +import Locked from '../../components/auth/Locked'; +import SettingsStore from '../../stores/SettingsStore'; +import { DEFAULT_LOCK_PASSWORD } from '../../config'; + +import { globalError as globalErrorPropType } from '../../prop-types'; + +export default @inject('stores', 'actions') @observer class LockedScreen extends Component { + static propTypes = { + error: globalErrorPropType.isRequired, + }; + + state = { + error: false, + } + + constructor(props) { + super(props); + + this.onSubmit = this.onSubmit.bind(this); + } + + onSubmit(values) { + const { password } = values; + + let correctPassword = this.props.stores.settings.all.app.lockedPassword; + if (!correctPassword) { + // Lock feature was enabled but no password was set + // Use default lock password so user can exit + correctPassword = DEFAULT_LOCK_PASSWORD; + } + + if (String(password) === String(correctPassword)) { + this.props.actions.settings.update({ + type: 'app', + data: { + locked: false, + }, + }); + } else { + this.setState({ + error: { + code: 'invalid-credentials', + }, + }); + } + } + + render() { + const { stores, error } = this.props; + return ( + + ); + } +} + +LockedScreen.wrappedComponent.propTypes = { + actions: PropTypes.shape({ + settings: PropTypes.shape({ + update: PropTypes.func.isRequired, + }).isRequired, + }).isRequired, + stores: PropTypes.shape({ + settings: PropTypes.instanceOf(SettingsStore).isRequired, + }).isRequired, +}; -- cgit v1.2.3-54-g00ecf