diff options
author | 2022-05-08 21:00:17 -0500 | |
---|---|---|
committer | 2022-05-08 22:19:29 -0400 | |
commit | db25991927e9b74eda2f3a9df5d01908abc04208 (patch) | |
tree | 28b82e6e50512ceecdae4e6d2ddec50f0c7835b5 /src/containers/auth/LockedScreen.tsx | |
parent | New Crowdin updates (#119) [skip ci] (diff) | |
download | ferdium-app-db25991927e9b74eda2f3a9df5d01908abc04208.tar.gz ferdium-app-db25991927e9b74eda2f3a9df5d01908abc04208.tar.zst ferdium-app-db25991927e9b74eda2f3a9df5d01908abc04208.zip |
Converted some javascript files to typescript
Diffstat (limited to 'src/containers/auth/LockedScreen.tsx')
-rw-r--r-- | src/containers/auth/LockedScreen.tsx | 84 |
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 @@ | |||
1 | import { Component } from 'react'; | ||
2 | import { inject, observer } from 'mobx-react'; | ||
3 | import Locked from '../../components/auth/Locked'; | ||
4 | import SettingsStore from '../../stores/SettingsStore'; | ||
5 | |||
6 | import { hash } from '../../helpers/password-helpers'; | ||
7 | import UserStore from '../../stores/UserStore'; | ||
8 | |||
9 | interface IProps { | ||
10 | actions: { | ||
11 | settings: SettingsStore, | ||
12 | }, | ||
13 | stores: { | ||
14 | settings: SettingsStore, | ||
15 | user: UserStore, | ||
16 | } | ||
17 | }; | ||
18 | |||
19 | class 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 | |||
84 | export default inject('stores', 'actions')(observer(LockedScreen)); | ||