fix(security-dialog) fix form event propagation after migrating to React 17
In addition, replace the from with a div because they shouldn't be nested. Since we are no longer in a form, manually validate the password. This was necessary regardless, because it was possible to bypass the digits rule by pressing "add".
This commit is contained in:
parent
676d7f2b93
commit
fb3a39e743
|
@ -85,9 +85,7 @@ class PasswordForm extends Component<Props, State> {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
// Bind event handlers so they are only bound once per instance.
|
// Bind event handlers so they are only bound once per instance.
|
||||||
this._onEnteredPasswordChange
|
this._onEnteredPasswordChange = this._onEnteredPasswordChange.bind(this);
|
||||||
= this._onEnteredPasswordChange.bind(this);
|
|
||||||
this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
|
|
||||||
this._onKeyPress = this._onKeyPress.bind(this);
|
this._onKeyPress = this._onKeyPress.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,31 +120,28 @@ class PasswordForm extends Component<Props, State> {
|
||||||
*/
|
*/
|
||||||
_renderPasswordField() {
|
_renderPasswordField() {
|
||||||
if (this.props.editEnabled) {
|
if (this.props.editEnabled) {
|
||||||
let digitPattern, placeHolderText;
|
let placeHolderText;
|
||||||
|
|
||||||
if (this.props.passwordNumberOfDigits) {
|
if (this.props.passwordNumberOfDigits) {
|
||||||
placeHolderText = this.props.t('passwordDigitsOnly', {
|
placeHolderText = this.props.t('passwordDigitsOnly', {
|
||||||
number: this.props.passwordNumberOfDigits });
|
number: this.props.passwordNumberOfDigits });
|
||||||
digitPattern = '\\d*';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<div
|
||||||
className = 'info-password-form'
|
className = 'info-password-form'>
|
||||||
onKeyPress = { this._onKeyPress }
|
|
||||||
onSubmit = { this._onPasswordSubmit }>
|
|
||||||
<input
|
<input
|
||||||
aria-label = { this.props.t('info.addPassword') }
|
aria-label = { this.props.t('info.addPassword') }
|
||||||
autoFocus = { true }
|
autoFocus = { true }
|
||||||
className = 'info-password-input'
|
className = 'info-password-input'
|
||||||
maxLength = { this.props.passwordNumberOfDigits }
|
maxLength = { this.props.passwordNumberOfDigits }
|
||||||
onChange = { this._onEnteredPasswordChange }
|
onChange = { this._onEnteredPasswordChange }
|
||||||
pattern = { digitPattern }
|
onKeyPress = { this._onKeyPress }
|
||||||
placeholder = { placeHolderText }
|
placeholder = { placeHolderText }
|
||||||
spellCheck = { 'false' }
|
spellCheck = { 'false' }
|
||||||
type = 'text'
|
type = 'text'
|
||||||
value = { this.state.enteredPassword } />
|
value = { this.state.enteredPassword } />
|
||||||
</form>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (this.props.locked === LOCKED_LOCALLY) {
|
} else if (this.props.locked === LOCKED_LOCALLY) {
|
||||||
return (
|
return (
|
||||||
|
@ -182,23 +177,6 @@ class PasswordForm extends Component<Props, State> {
|
||||||
this.setState({ enteredPassword: event.target.value });
|
this.setState({ enteredPassword: event.target.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
_onPasswordSubmit: (Object) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invokes the passed in onSubmit callback to notify the parent that a
|
|
||||||
* password submission has been attempted.
|
|
||||||
*
|
|
||||||
* @param {Object} event - DOM Event for form submission.
|
|
||||||
* @private
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
_onPasswordSubmit(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
this.props.onSubmit(this.state.enteredPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
_onKeyPress: (Object) => void;
|
_onKeyPress: (Object) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,7 +189,10 @@ class PasswordForm extends Component<Props, State> {
|
||||||
*/
|
*/
|
||||||
_onKeyPress(event) {
|
_onKeyPress(event) {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
|
this.props.onSubmit(this.state.enteredPassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { NOTIFY_CLICK_MODE } from '../../../../toolbox/constants';
|
||||||
|
|
||||||
import PasswordForm from './PasswordForm';
|
import PasswordForm from './PasswordForm';
|
||||||
|
|
||||||
|
const DIGITS_ONLY = /^\d+$/;
|
||||||
const KEY = 'add-passcode';
|
const KEY = 'add-passcode';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -97,6 +98,10 @@ function PasswordSection({
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function onPasswordSubmit(enteredPassword) {
|
function onPasswordSubmit(enteredPassword) {
|
||||||
|
if (enteredPassword && passwordNumberOfDigits && !DIGITS_ONLY.test(enteredPassword)) {
|
||||||
|
// Don't set the password.
|
||||||
|
return;
|
||||||
|
}
|
||||||
setPassword(conference, conference.lock, enteredPassword);
|
setPassword(conference, conference.lock, enteredPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +147,7 @@ function PasswordSection({
|
||||||
*/
|
*/
|
||||||
function onPasswordSave() {
|
function onPasswordSave() {
|
||||||
if (formRef.current) {
|
if (formRef.current) {
|
||||||
const { value } = formRef.current.querySelector('form > input');
|
const { value } = formRef.current.querySelector('div > input');
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
onPasswordSubmit(value);
|
onPasswordSubmit(value);
|
||||||
|
|
Loading…
Reference in New Issue