Radarr/frontend/src/Settings/General/SecuritySettings.js

189 lines
5.1 KiB
JavaScript
Raw Normal View History

2018-11-23 07:04:42 +00:00
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import FieldSet from 'Components/FieldSet';
import FormGroup from 'Components/Form/FormGroup';
import FormInputButton from 'Components/Form/FormInputButton';
import FormInputGroup from 'Components/Form/FormInputGroup';
import FormLabel from 'Components/Form/FormLabel';
import Icon from 'Components/Icon';
import ClipboardButton from 'Components/Link/ClipboardButton';
2018-11-23 07:04:42 +00:00
import ConfirmModal from 'Components/Modal/ConfirmModal';
import { icons, inputTypes, kinds } from 'Helpers/Props';
import translate from 'Utilities/String/translate';
2018-11-23 07:04:42 +00:00
const authenticationMethodOptions = [
2020-11-23 03:34:51 +00:00
{ key: 'none', value: translate('None') },
{ key: 'basic', value: translate('AuthBasic') },
{ key: 'forms', value: translate('AuthForm') }
];
const certificateValidationOptions = [
2020-11-23 03:34:51 +00:00
{ key: 'enabled', value: translate('Enabled') },
{ key: 'disabledForLocalAddresses', value: translate('CertValidationNoLocal') },
{ key: 'disabled', value: translate('Disabled') }
];
2018-11-23 07:04:42 +00:00
class SecuritySettings extends Component {
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
isConfirmApiKeyResetModalOpen: false
};
}
//
// Listeners
onApikeyFocus = (event) => {
event.target.select();
}
onResetApiKeyPress = () => {
this.setState({ isConfirmApiKeyResetModalOpen: true });
}
onConfirmResetApiKey = () => {
this.setState({ isConfirmApiKeyResetModalOpen: false });
this.props.onConfirmResetApiKey();
}
onCloseResetApiKeyModal = () => {
this.setState({ isConfirmApiKeyResetModalOpen: false });
}
//
// Render
render() {
const {
settings,
isResettingApiKey,
onInputChange
} = this.props;
const {
authenticationMethod,
username,
password,
apiKey,
certificateValidation
2018-11-23 07:04:42 +00:00
} = settings;
const authenticationEnabled = authenticationMethod && authenticationMethod.value !== 'none';
return (
<FieldSet legend={translate('Security')}>
2018-11-23 07:04:42 +00:00
<FormGroup>
2020-08-29 03:56:13 +00:00
<FormLabel>{translate('Authentication')}</FormLabel>
2018-11-23 07:04:42 +00:00
<FormInputGroup
type={inputTypes.SELECT}
name="authenticationMethod"
values={authenticationMethodOptions}
2020-08-29 03:56:13 +00:00
helpText={translate('AuthenticationMethodHelpText')}
2018-11-23 07:04:42 +00:00
onChange={onInputChange}
{...authenticationMethod}
/>
</FormGroup>
{
authenticationEnabled &&
<FormGroup>
2020-08-29 03:56:13 +00:00
<FormLabel>{translate('Username')}</FormLabel>
<FormInputGroup
type={inputTypes.TEXT}
name="username"
onChange={onInputChange}
{...username}
/>
</FormGroup>
2018-11-23 07:04:42 +00:00
}
{
authenticationEnabled &&
<FormGroup>
2020-08-29 03:56:13 +00:00
<FormLabel>{translate('Password')}</FormLabel>
<FormInputGroup
type={inputTypes.PASSWORD}
name="password"
onChange={onInputChange}
{...password}
/>
</FormGroup>
2018-11-23 07:04:42 +00:00
}
<FormGroup>
2020-08-29 03:56:13 +00:00
<FormLabel>{translate('ApiKey')}</FormLabel>
2018-11-23 07:04:42 +00:00
<FormInputGroup
type={inputTypes.TEXT}
name="apiKey"
readOnly={true}
2020-08-29 03:56:13 +00:00
helpTextWarning={translate('RestartRequiredHelpTextWarning')}
2018-11-23 07:04:42 +00:00
buttons={[
<ClipboardButton
key="copy"
value={apiKey.value}
kind={kinds.DEFAULT}
/>,
<FormInputButton
key="reset"
kind={kinds.DANGER}
onPress={this.onResetApiKeyPress}
>
<Icon
name={icons.REFRESH}
isSpinning={isResettingApiKey}
/>
</FormInputButton>
]}
onChange={onInputChange}
onFocus={this.onApikeyFocus}
{...apiKey}
/>
</FormGroup>
<FormGroup>
2020-08-29 03:56:13 +00:00
<FormLabel>{translate('CertificateValidation')}</FormLabel>
<FormInputGroup
type={inputTypes.SELECT}
name="certificateValidation"
values={certificateValidationOptions}
2020-08-29 03:56:13 +00:00
helpText={translate('CertificateValidationHelpText')}
onChange={onInputChange}
{...certificateValidation}
/>
</FormGroup>
2018-11-23 07:04:42 +00:00
<ConfirmModal
isOpen={this.state.isConfirmApiKeyResetModalOpen}
kind={kinds.DANGER}
2020-08-29 03:56:13 +00:00
title={translate('ResetAPIKey')}
message={translate('AreYouSureYouWantToResetYourAPIKey')}
confirmLabel={translate('Reset')}
2018-11-23 07:04:42 +00:00
onConfirm={this.onConfirmResetApiKey}
onCancel={this.onCloseResetApiKeyModal}
/>
</FieldSet>
);
}
}
SecuritySettings.propTypes = {
settings: PropTypes.object.isRequired,
isResettingApiKey: PropTypes.bool.isRequired,
onInputChange: PropTypes.func.isRequired,
onConfirmResetApiKey: PropTypes.func.isRequired
};
export default SecuritySettings;