From d16e10baecec5059f4e2e089d984393f4226d158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=8F=D0=BD=20=D0=9C=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Wed, 22 May 2019 08:43:17 +0100 Subject: [PATCH] room-lock: adds ability to allow only digits for room locking --- config.js | 4 ++ lang/main.json | 1 + .../dialog/components/native/InputDialog.js | 13 +++++- .../components/info-dialog/web/InfoDialog.js | 9 +++- .../info-dialog/web/PasswordForm.js | 16 +++++++ react/features/room-lock/actions.js | 6 ++- .../components/RoomLockPrompt.native.js | 43 ++++++++++++++++++- 7 files changed, 87 insertions(+), 5 deletions(-) diff --git a/config.js b/config.js index 3589d3d23b..e7348a06e3 100644 --- a/config.js +++ b/config.js @@ -269,6 +269,10 @@ var config = { // Enable lock room for all moderators, even when userRolesBasedOnToken is enabled and participants are guests. // lockRoomGuestEnabled: false, + // When enabled the password used for locking a room is restricted to up to the number of digits specified + // roomPasswordNumberOfDigits: 10, + // default: roomPasswordNumberOfDigits: false, + // Message to show the users. Example: 'The service will be down for // maintenance at 01:00 AM GMT, // noticeMessage: '', diff --git a/lang/main.json b/lang/main.json index 767c9c4d1e..eec7a3c842 100644 --- a/lang/main.json +++ b/lang/main.json @@ -485,6 +485,7 @@ "newDeviceAction": "Use" }, "passwordSetRemotely": "set by another member", + "passwordDigitsOnly": "Up to __number__ digits", "poweredby": "powered by", "presenceStatus": { "busy": "Busy", diff --git a/react/features/base/dialog/components/native/InputDialog.js b/react/features/base/dialog/components/native/InputDialog.js index 63568569a5..c97dbd2bab 100644 --- a/react/features/base/dialog/components/native/InputDialog.js +++ b/react/features/base/dialog/components/native/InputDialog.js @@ -32,7 +32,12 @@ type Props = BaseProps & { t: Function, - textInputProps: ?Object + textInputProps: ?Object, + + /** + * Validating of the input. + */ + validateInput: ?Function } type State = { @@ -118,6 +123,12 @@ class InputDialog extends BaseDialog { * @returns {void} */ _onChangeText(fieldValue) { + + if (this.props.validateInput + && !this.props.validateInput(fieldValue)) { + return; + } + this.setState({ fieldValue }); diff --git a/react/features/invite/components/info-dialog/web/InfoDialog.js b/react/features/invite/components/info-dialog/web/InfoDialog.js index a1b5c886f6..20c8fafd9d 100644 --- a/react/features/invite/components/info-dialog/web/InfoDialog.js +++ b/react/features/invite/components/info-dialog/web/InfoDialog.js @@ -40,6 +40,11 @@ type Props = { */ _conferenceName: string, + /** + * The number of digits to be used in the password. + */ + _passwordNumberOfDigits: ?number, + /** * The current url of the conference to be copied onto the clipboard. */ @@ -245,7 +250,8 @@ class InfoDialog extends Component { editEnabled = { this.state.passwordEditEnabled } locked = { this.props._locked } onSubmit = { this._onPasswordSubmit } - password = { this.props._password } /> + password = { this.props._password } + passwordNumberOfDigits = { this.props._passwordNumberOfDigits } />
@@ -591,6 +597,7 @@ function _mapStateToProps(state) { _canEditPassword: isLocalParticipantModerator(state, state['features/base/config'].lockRoomGuestEnabled), _conference: conference, _conferenceName: room, + _passwordNumberOfDigits: state['features/base/config'].roomPasswordNumberOfDigits, _inviteURL: getInviteURL(state), _localParticipant: getLocalParticipant(state), _locationURL: state['features/base/connection'].locationURL, diff --git a/react/features/invite/components/info-dialog/web/PasswordForm.js b/react/features/invite/components/info-dialog/web/PasswordForm.js index fa03d9ded7..394d163ff7 100644 --- a/react/features/invite/components/info-dialog/web/PasswordForm.js +++ b/react/features/invite/components/info-dialog/web/PasswordForm.js @@ -32,6 +32,11 @@ type Props = { */ password: string, + /** + * The number of digits to be used in the password. + */ + passwordNumberOfDigits: boolean, + /** * Invoked to obtain translated strings. */ @@ -117,6 +122,14 @@ class PasswordForm extends Component { */ _renderPasswordField() { if (this.props.editEnabled) { + let digitPattern, placeHolderText; + + if (this.props.passwordNumberOfDigits) { + placeHolderText = this.props.t('passwordDigitsOnly', { + number: this.props.passwordNumberOfDigits }); + digitPattern = '\\d*'; + } + return (
{ diff --git a/react/features/room-lock/actions.js b/react/features/room-lock/actions.js index 4e29d304dc..83a0f6aecf 100644 --- a/react/features/room-lock/actions.js +++ b/react/features/room-lock/actions.js @@ -25,7 +25,11 @@ export function beginRoomLockRequest(conference: ?Object) { conference = getState()['features/base/conference'].conference; } if (conference) { - dispatch(openDialog(RoomLockPrompt, { conference })); + const passwordNumberOfDigits = getState()['features/base/config'].roomPasswordNumberOfDigits; + + dispatch(openDialog(RoomLockPrompt, { + conference, + passwordNumberOfDigits })); } }; } diff --git a/react/features/room-lock/components/RoomLockPrompt.native.js b/react/features/room-lock/components/RoomLockPrompt.native.js index 503a4e5357..a369c68839 100644 --- a/react/features/room-lock/components/RoomLockPrompt.native.js +++ b/react/features/room-lock/components/RoomLockPrompt.native.js @@ -28,10 +28,15 @@ type Props = { */ conference: Object, + /** + * The number of digits to be used in the password. + */ + passwordNumberOfDigits: ?number, + /** * Redux store dispatch function. */ - dispatch: Dispatch, + dispatch: Dispatch }; /** @@ -51,6 +56,7 @@ class RoomLockPrompt extends Component { // Bind event handlers so they are only bound once per instance. this._onCancel = this._onCancel.bind(this); this._onSubmit = this._onSubmit.bind(this); + this._validateInput = this._validateInput.bind(this); } /** @@ -60,12 +66,23 @@ class RoomLockPrompt extends Component { * @returns {ReactElement} */ render() { + let textInputProps = _TEXT_INPUT_PROPS; + + if (this.props.passwordNumberOfDigits) { + textInputProps = { + ...textInputProps, + keyboardType: 'number-pad', + maxLength: this.props.passwordNumberOfDigits + }; + } + return ( + textInputProps = { textInputProps } + validateInput = { this._validateInput } /> ); } @@ -100,6 +117,28 @@ class RoomLockPrompt extends Component { return false; // Do not hide. } + + _validateInput: (string) => boolean; + + /** + * Verifies input in case only digits are required. + * + * @param {string|undefined} value - The submitted value. + * @private + * @returns {boolean} False when the value is not valid and True otherwise. + */ + _validateInput(value: string) { + + // we want only digits, but both number-pad and numeric add ',' and '.' as symbols + if (this.props.passwordNumberOfDigits + && value.length > 0 + && !/^\d+$/.test(value)) { + + return false; + } + + return true; + } } export default connect()(RoomLockPrompt);