diff options
Diffstat (limited to 'src/containers/auth/LockedScreen.js')
-rw-r--r-- | src/containers/auth/LockedScreen.js | 72 |
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 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { inject, observer } from 'mobx-react'; | ||
4 | import Locked from '../../components/auth/Locked'; | ||
5 | import SettingsStore from '../../stores/SettingsStore'; | ||
6 | import { DEFAULT_LOCK_PASSWORD } from '../../config'; | ||
7 | |||
8 | import { globalError as globalErrorPropType } from '../../prop-types'; | ||
9 | |||
10 | export 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 | |||
63 | LockedScreen.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 | }; | ||