diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4e7b4fe1b..efb20d796 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,11 @@ in development Changed ~~~~~~~ +* Changed how secrets are handled in the UI from type=password + to using CSS webkit-text-security. + + Contributed by @fdrab + * Updated various dependencies (security). #1009, #1020 Contributed by @enykeev diff --git a/modules/st2-auto-form/auto-form.component.js b/modules/st2-auto-form/auto-form.component.js index e3a355c26..5ce3cd2fe 100644 --- a/modules/st2-auto-form/auto-form.component.js +++ b/modules/st2-auto-form/auto-form.component.js @@ -23,7 +23,6 @@ import IntegerField from './fields/integer'; import BooleanField from './fields/boolean'; import StringField from './fields/string'; import ObjectField from './fields/object'; -import PasswordField from './fields/password'; import EnumField from './fields/enum'; import './style.css'; @@ -57,10 +56,6 @@ export default class AutoForm extends React.Component { case 'boolean': return BooleanField; case 'string': - if (field.secret) { - return PasswordField; - } - return StringField; case 'object': return ObjectField; diff --git a/modules/st2-auto-form/fields/base.js b/modules/st2-auto-form/fields/base.js index ca9051727..4cd7ddd43 100644 --- a/modules/st2-auto-form/fields/base.js +++ b/modules/st2-auto-form/fields/base.js @@ -45,6 +45,7 @@ export class BaseTextField extends React.Component { spec: PropTypes.object, value: PropTypes.any, disabled: PropTypes.bool, + visible: PropTypes.bool, onChange: PropTypes.func, 'data-test': PropTypes.string, } @@ -54,6 +55,7 @@ export class BaseTextField extends React.Component { this.state = { value: this.toStateValue(this.props.value), + visible: false, }; } @@ -105,6 +107,10 @@ export class BaseTextField extends React.Component { } } + visibilityToggle() { + this.setState({visible: !this.state.visible}) + } + emitChange() { return this.props.onChange(this.fromStateValue(this.state.value)); } @@ -113,18 +119,22 @@ export class BaseTextField extends React.Component { const { icon } = this.constructor; const { invalid } = this.state; const { spec={} } = this.props; - const wrapperProps = Object.assign({}, this.props); + const wrapperProps = Object.assign({}, this.props, { + visibilityToggle: () => this.visibilityToggle(), + visible: this.state.visible, + }); if (invalid) { wrapperProps.invalid = invalid; } const inputProps = { - className: 'st2-auto-form__field', - type: spec.secret ? 'password' : 'text', + className: spec.secret && !this.state.visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field', + type: 'text', placeholder:this.toStateValue(spec.default), disabled: this.props.disabled, value: this.state.value, + spellCheck: spec.secret && !this.state.visible ? false : true, onChange: (e) => this.handleChange(e, e.target.value), 'data-test': this.props['data-test'], }; @@ -135,7 +145,7 @@ export class BaseTextField extends React.Component { return ( - + ); } @@ -145,19 +155,23 @@ export class BaseTextareaField extends BaseTextField { render() { const { icon } = this.constructor; const { invalid } = this.state; - const { spec={} } = this.props; + const { spec = {} } = this.props; - const wrapperProps = Object.assign({}, this.props); + const wrapperProps = Object.assign({}, this.props, { + visibilityToggle: () => this.visibilityToggle(), + visible: this.state.visible, + }); if (invalid) { wrapperProps.invalid = invalid; } const inputProps = { - className: 'st2-auto-form__field', + className: spec.secret && !this.state.visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field', placeholder: this.toStateValue(spec.default), disabled: this.props.disabled, value: this.state.value, + spellCheck: spec.secret && !this.state.visible ? false : true, onChange: (e) => this.handleChange(e, e.target.value), minRows: 1, maxRows: 10, @@ -170,7 +184,7 @@ export class BaseTextareaField extends BaseTextField { return ( -