aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/auth/LockedScreen.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/auth/LockedScreen.tsx')
-rw-r--r--src/containers/auth/LockedScreen.tsx84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/containers/auth/LockedScreen.tsx b/src/containers/auth/LockedScreen.tsx
new file mode 100644
index 000000000..e6bb5e8e4
--- /dev/null
+++ b/src/containers/auth/LockedScreen.tsx
@@ -0,0 +1,84 @@
1import { Component } from 'react';
2import { inject, observer } from 'mobx-react';
3import Locked from '../../components/auth/Locked';
4import SettingsStore from '../../stores/SettingsStore';
5
6import { hash } from '../../helpers/password-helpers';
7import UserStore from '../../stores/UserStore';
8
9interface IProps {
10 actions: {
11 settings: SettingsStore,
12 },
13 stores: {
14 settings: SettingsStore,
15 user: UserStore,
16 }
17};
18
19class LockedScreen extends Component<IProps> {
20 state = {
21 error: false,
22 };
23
24 constructor(props) {
25 super(props);
26
27 this.onSubmit = this.onSubmit.bind(this);
28 this.unlock = this.unlock.bind(this);
29 }
30
31 onSubmit(values) {
32 const { password } = values;
33
34 let correctPassword = this.props.stores.settings.all.app.lockedPassword;
35 if (!correctPassword) {
36 correctPassword = '';
37 }
38
39 if (hash(String(password)) === String(correctPassword)) {
40 this.props.actions.settings.update({
41 type: 'app',
42 data: {
43 locked: false,
44 },
45 });
46 } else {
47 this.setState({
48 error: {
49 code: 'invalid-credentials',
50 },
51 });
52 }
53 }
54
55 unlock() {
56 this.props.actions.settings.update({
57 type: 'app',
58 data: {
59 locked: false,
60 },
61 });
62 }
63
64 render() {
65 const { stores } = this.props;
66 const { useTouchIdToUnlock } = this.props.stores.settings.all.app;
67
68 return (
69 <div className="auth">
70 <div className="auth__layout">
71 <Locked
72 onSubmit={this.onSubmit}
73 unlock={this.unlock}
74 useTouchIdToUnlock={useTouchIdToUnlock}
75 isSubmitting={stores.user.loginRequest.isExecuting}
76 error={this.state.error || {}}
77 />
78 </div>
79 </div>
80 );
81 }
82}
83
84export default inject('stores', 'actions')(observer(LockedScreen));