aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/auth
diff options
context:
space:
mode:
authorLibravatar vantezzen <properly@protonmail.com>2019-09-17 12:14:48 +0200
committerLibravatar vantezzen <properly@protonmail.com>2019-09-17 12:14:48 +0200
commitd14071f3503f768c9c0e040dee549be6a6b40e5f (patch)
treeb6c945c8b4baf31344dbabd2ac555559285ebec6 /src/containers/auth
parentAdd "npm run prepare-code" command (diff)
downloadferdium-app-d14071f3503f768c9c0e040dee549be6a6b40e5f.tar.gz
ferdium-app-d14071f3503f768c9c0e040dee549be6a6b40e5f.tar.zst
ferdium-app-d14071f3503f768c9c0e040dee549be6a6b40e5f.zip
Implement #41
Diffstat (limited to 'src/containers/auth')
-rw-r--r--src/containers/auth/LockedScreen.js72
1 files changed, 72 insertions, 0 deletions
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 @@
1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
3import { inject, observer } from 'mobx-react';
4import Locked from '../../components/auth/Locked';
5import SettingsStore from '../../stores/SettingsStore';
6import { DEFAULT_LOCK_PASSWORD } from '../../config';
7
8import { globalError as globalErrorPropType } from '../../prop-types';
9
10export default @inject('stores', 'actions') @observer class LockedScreen extends Component {
11 static propTypes = {
12 error: globalErrorPropType.isRequired,
13 };
14
15 state = {
16 error: false,
17 }
18
19 constructor(props) {
20 super(props);
21
22 this.onSubmit = this.onSubmit.bind(this);
23 }
24
25 onSubmit(values) {
26 const { password } = values;
27
28 let correctPassword = this.props.stores.settings.all.app.lockedPassword;
29 if (!correctPassword) {
30 // Lock feature was enabled but no password was set
31 // Use default lock password so user can exit
32 correctPassword = DEFAULT_LOCK_PASSWORD;
33 }
34
35 if (String(password) === String(correctPassword)) {
36 this.props.actions.settings.update({
37 type: 'app',
38 data: {
39 locked: false,
40 },
41 });
42 } else {
43 this.setState({
44 error: {
45 code: 'invalid-credentials',
46 },
47 });
48 }
49 }
50
51 render() {
52 const { stores, error } = this.props;
53 return (
54 <Locked
55 onSubmit={this.onSubmit}
56 isSubmitting={stores.user.loginRequest.isExecuting}
57 error={this.state.error || error}
58 />
59 );
60 }
61}
62
63LockedScreen.wrappedComponent.propTypes = {
64 actions: PropTypes.shape({
65 settings: PropTypes.shape({
66 update: PropTypes.func.isRequired,
67 }).isRequired,
68 }).isRequired,
69 stores: PropTypes.shape({
70 settings: PropTypes.instanceOf(SettingsStore).isRequired,
71 }).isRequired,
72};