/
index.jsx
146 lines (128 loc) · 4.67 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* . .o8 oooo
* .o8 "888 `888
* .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo
* 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P'
* 888 888 888 888 888 888 888ooo888 `"Y88b. 888888.
* 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b.
* "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o
* ========================================================================
* Author: Chris Brame
* Updated: 5/17/22 2:20 PM
* Copyright (c) 2014-2022. All rights reserved.
*/
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { updateSetting, updateMultipleSettings } from 'actions/settings'
import Button from 'components/Button'
import SettingItem from 'components/Settings/SettingItem'
import helpers from 'lib/helpers'
import axios from 'axios'
import Log from '../../../logger'
import EnableSwitch from 'components/Settings/EnableSwitch'
import { observer } from 'mobx-react'
import { makeObservable, observable } from 'mobx'
import UIKit from 'uikit'
@observer
class AccountsSettingsContainer extends React.Component {
@observable passwordComplexityEnabled = false
@observable allowUserRegistrationEnabled = false
constructor (props) {
super(props)
makeObservable(this)
this.state = {
restarting: false
}
this.restartServer = this.restartServer.bind(this)
}
componentDidMount () {
// helpers.UI.inputs()
}
componentDidUpdate (prevProps) {
// helpers.UI.reRenderInputs()
if (prevProps.settings !== this.props.settings) {
if (this.passwordComplexityEnabled !== this.getSetting('accountsPasswordComplexity'))
this.passwordComplexityEnabled = this.getSetting('accountsPasswordComplexity')
if (this.allowUserRegistrationEnabled !== this.getSetting('allowUserRegistration'))
this.allowUserRegistrationEnabled = this.getSetting('allowUserRegistration')
}
}
restartServer () {
this.setState({ restarting: true })
const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content')
axios
.post(
'/api/v1/admin/restart',
{},
{
headers: {
'CSRF-TOKEN': token
}
}
)
.catch(error => {
helpers.hideLoader()
Log.error(error.responseText)
Log.error('Unable to restart server. Server must run under PM2 and Account must have admin rights.')
helpers.UI.showSnackbar('Unable to restart server. Are you an Administrator?', true)
})
.then(() => {
this.setState({ restarting: false })
})
}
getSetting (stateName) {
return this.props.settings.getIn(['settings', stateName, 'value'])
? this.props.settings.getIn(['settings', stateName, 'value'])
: ''
}
updateSetting (stateName, name, value) {
this.props.updateSetting({ stateName, name, value })
}
render () {
const { active } = this.props
return (
<div className={active ? 'active' : 'hide'}>
<SettingItem
title='Allow User Registration'
subtitle='Allow users to create accounts on the login screen.'
component={
<EnableSwitch
stateName='allowUserRegistration'
label='Enable'
checked={this.allowUserRegistrationEnabled}
onChange={e => {
this.updateSetting('allowUserRegistration', 'allowUserRegistration:enable', e.target.checked)
}}
/>
}
/>
<SettingItem
title={'Password Complexity'}
subtitle={'Require users passwords to meet minimum password complexity'}
tooltip={'Minimum 8 characters with uppercase and numeric.'}
component={
<EnableSwitch
stateName={'accountsPasswordComplexity'}
label={'Enable'}
checked={this.passwordComplexityEnabled}
onChange={e => {
this.updateSetting('accountsPasswordComplexity', 'accountsPasswordComplexity:enable', e.target.checked)
}}
/>
}
/>
</div>
)
}
}
AccountsSettingsContainer.propTypes = {
active: PropTypes.bool.isRequired,
updateSetting: PropTypes.func.isRequired,
updateMultipleSettings: PropTypes.func.isRequired,
settings: PropTypes.object.isRequired
}
const mapStateToProps = state => ({
settings: state.settings.settings
})
export default connect(mapStateToProps, { updateSetting, updateMultipleSettings })(AccountsSettingsContainer)