diff options
author | 2019-09-17 12:14:48 +0200 | |
---|---|---|
committer | 2019-09-17 12:14:48 +0200 | |
commit | d14071f3503f768c9c0e040dee549be6a6b40e5f (patch) | |
tree | b6c945c8b4baf31344dbabd2ac555559285ebec6 /src/containers | |
parent | Add "npm run prepare-code" command (diff) | |
download | ferdium-app-d14071f3503f768c9c0e040dee549be6a6b40e5f.tar.gz ferdium-app-d14071f3503f768c9c0e040dee549be6a6b40e5f.tar.zst ferdium-app-d14071f3503f768c9c0e040dee549be6a6b40e5f.zip |
Implement #41
Diffstat (limited to 'src/containers')
-rw-r--r-- | src/containers/auth/LockedScreen.js | 72 | ||||
-rw-r--r-- | src/containers/settings/EditSettingsScreen.js | 25 |
2 files changed, 96 insertions, 1 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 | }; | ||
diff --git a/src/containers/settings/EditSettingsScreen.js b/src/containers/settings/EditSettingsScreen.js index 778b70ad9..1b134622a 100644 --- a/src/containers/settings/EditSettingsScreen.js +++ b/src/containers/settings/EditSettingsScreen.js | |||
@@ -9,7 +9,7 @@ import UserStore from '../../stores/UserStore'; | |||
9 | import TodosStore from '../../features/todos/store'; | 9 | import TodosStore from '../../features/todos/store'; |
10 | import Form from '../../lib/Form'; | 10 | import Form from '../../lib/Form'; |
11 | import { APP_LOCALES, SPELLCHECKER_LOCALES } from '../../i18n/languages'; | 11 | import { APP_LOCALES, SPELLCHECKER_LOCALES } from '../../i18n/languages'; |
12 | import { DEFAULT_APP_SETTINGS } from '../../config'; | 12 | import { DEFAULT_APP_SETTINGS, DEFAULT_LOCK_PASSWORD } from '../../config'; |
13 | import { config as spellcheckerConfig } from '../../features/spellchecker'; | 13 | import { config as spellcheckerConfig } from '../../features/spellchecker'; |
14 | 14 | ||
15 | import { getSelectOptions } from '../../helpers/i18n-helpers'; | 15 | import { getSelectOptions } from '../../helpers/i18n-helpers'; |
@@ -57,6 +57,14 @@ const messages = defineMessages({ | |||
57 | id: 'settings.app.form.todoServer', | 57 | id: 'settings.app.form.todoServer', |
58 | defaultMessage: '!!!Todo Server', | 58 | defaultMessage: '!!!Todo Server', |
59 | }, | 59 | }, |
60 | enableLock: { | ||
61 | id: 'settings.app.form.enableLock', | ||
62 | defaultMessage: '!!!Enable Ferdi password lock', | ||
63 | }, | ||
64 | lockPassword: { | ||
65 | id: 'settings.app.form.lockPassword', | ||
66 | defaultMessage: '!!!Ferdi Lock password', | ||
67 | }, | ||
60 | language: { | 68 | language: { |
61 | id: 'settings.app.form.language', | 69 | id: 'settings.app.form.language', |
62 | defaultMessage: '!!!Language', | 70 | defaultMessage: '!!!Language', |
@@ -124,6 +132,8 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e | |||
124 | privateNotifications: settingsData.privateNotifications, | 132 | privateNotifications: settingsData.privateNotifications, |
125 | server: settingsData.server, | 133 | server: settingsData.server, |
126 | todoServer: settingsData.todoServer, | 134 | todoServer: settingsData.todoServer, |
135 | lockingFeatureEnabled: settingsData.lockingFeatureEnabled, | ||
136 | lockedPassword: settingsData.lockedPassword, | ||
127 | enableGPUAcceleration: settingsData.enableGPUAcceleration, | 137 | enableGPUAcceleration: settingsData.enableGPUAcceleration, |
128 | showDisabledServices: settingsData.showDisabledServices, | 138 | showDisabledServices: settingsData.showDisabledServices, |
129 | darkMode: settingsData.darkMode, | 139 | darkMode: settingsData.darkMode, |
@@ -214,6 +224,17 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e | |||
214 | value: settings.all.app.todoServer || TODOS_FRONTEND, | 224 | value: settings.all.app.todoServer || TODOS_FRONTEND, |
215 | default: TODOS_FRONTEND, | 225 | default: TODOS_FRONTEND, |
216 | }, | 226 | }, |
227 | lockingFeatureEnabled: { | ||
228 | label: intl.formatMessage(messages.enableLock), | ||
229 | value: settings.all.app.lockingFeatureEnabled || false, | ||
230 | default: false, | ||
231 | }, | ||
232 | lockedPassword: { | ||
233 | label: intl.formatMessage(messages.lockPassword), | ||
234 | value: settings.all.app.lockedPassword || DEFAULT_LOCK_PASSWORD, | ||
235 | default: DEFAULT_LOCK_PASSWORD, | ||
236 | type: 'password', | ||
237 | }, | ||
217 | showDisabledServices: { | 238 | showDisabledServices: { |
218 | label: intl.formatMessage(messages.showDisabledServices), | 239 | label: intl.formatMessage(messages.showDisabledServices), |
219 | value: settings.all.app.showDisabledServices, | 240 | value: settings.all.app.showDisabledServices, |
@@ -290,6 +311,7 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e | |||
290 | updateStatusTypes, | 311 | updateStatusTypes, |
291 | isClearingAllCache, | 312 | isClearingAllCache, |
292 | server, | 313 | server, |
314 | lockingFeatureEnabled, | ||
293 | } = app; | 315 | } = app; |
294 | const { | 316 | const { |
295 | checkForUpdates, | 317 | checkForUpdates, |
@@ -316,6 +338,7 @@ export default @inject('stores', 'actions') @observer class EditSettingsScreen e | |||
316 | isTodosEnabled={todos.isFeatureActive} | 338 | isTodosEnabled={todos.isFeatureActive} |
317 | isWorkspaceEnabled={workspaces.isFeatureActive} | 339 | isWorkspaceEnabled={workspaces.isFeatureActive} |
318 | server={server || 'https://api.franzinfra.com'} | 340 | server={server || 'https://api.franzinfra.com'} |
341 | lockingFeatureEnabled={lockingFeatureEnabled} | ||
319 | /> | 342 | /> |
320 | </ErrorBoundary> | 343 | </ErrorBoundary> |
321 | ); | 344 | ); |