room-lock: adds ability to allow only digits for room locking

This commit is contained in:
Дамян Минков 2019-05-22 08:43:17 +01:00 committed by Saúl Ibarra Corretgé
parent 11e5c14f83
commit d16e10baec
7 changed files with 87 additions and 5 deletions

View File

@ -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: '',

View File

@ -485,6 +485,7 @@
"newDeviceAction": "Use"
},
"passwordSetRemotely": "set by another member",
"passwordDigitsOnly": "Up to __number__ digits",
"poweredby": "powered by",
"presenceStatus": {
"busy": "Busy",

View File

@ -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<Props, State> {
* @returns {void}
*/
_onChangeText(fieldValue) {
if (this.props.validateInput
&& !this.props.validateInput(fieldValue)) {
return;
}
this.setState({
fieldValue
});

View File

@ -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<Props, State> {
editEnabled = { this.state.passwordEditEnabled }
locked = { this.props._locked }
onSubmit = { this._onPasswordSubmit }
password = { this.props._password } />
password = { this.props._password }
passwordNumberOfDigits = { this.props._passwordNumberOfDigits } />
</div>
<div className = 'info-dialog-action-links'>
<div className = 'info-dialog-action-link'>
@ -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,

View File

@ -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<Props, State> {
*/
_renderPasswordField() {
if (this.props.editEnabled) {
let digitPattern, placeHolderText;
if (this.props.passwordNumberOfDigits) {
placeHolderText = this.props.t('passwordDigitsOnly', {
number: this.props.passwordNumberOfDigits });
digitPattern = '\\d*';
}
return (
<form
className = 'info-password-form'
@ -125,7 +138,10 @@ class PasswordForm extends Component<Props, State> {
<input
autoFocus = { true }
className = 'info-password-input'
maxLength = { this.props.passwordNumberOfDigits }
onChange = { this._onEnteredPasswordChange }
pattern = { digitPattern }
placeholder = { placeHolderText }
spellCheck = { 'false' }
type = 'text'
value = { this.state.enteredPassword } />

View File

@ -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 }));
}
};
}

View File

@ -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<any>,
dispatch: Dispatch<any>
};
/**
@ -51,6 +56,7 @@ class RoomLockPrompt extends Component<Props> {
// 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<Props> {
* @returns {ReactElement}
*/
render() {
let textInputProps = _TEXT_INPUT_PROPS;
if (this.props.passwordNumberOfDigits) {
textInputProps = {
...textInputProps,
keyboardType: 'number-pad',
maxLength: this.props.passwordNumberOfDigits
};
}
return (
<InputDialog
contentKey = 'dialog.passwordLabel'
onCancel = { this._onCancel }
onSubmit = { this._onSubmit }
textInputProps = { _TEXT_INPUT_PROPS } />
textInputProps = { textInputProps }
validateInput = { this._validateInput } />
);
}
@ -100,6 +117,28 @@ class RoomLockPrompt extends Component<Props> {
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);